Skip to content

Commit

Permalink
Code cleanup & map open by default (#1053)
Browse files Browse the repository at this point in the history
* Code cleanup & map open by default

* Fix lint

* Improve types
  • Loading branch information
thecalcc authored and petrjasek committed Sep 3, 2024
1 parent 1a4d6d2 commit 65c826e
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 34 deletions.
15 changes: 10 additions & 5 deletions assets/agenda/components/AgendaPreviewImage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,18 @@ import {shouldRenderLocation, getLocations} from 'maps/utils';
import StaticMap from 'maps/components/static';
import BannerDrop from 'components/BannerDrop';
import {gettext} from '../../utils';
import {get} from 'lodash';
import {IAgendaItem} from 'interfaces';

interface IProps {
onClick: (item: IAgendaItem) => void;
item: IAgendaItem;
}
/**
* Display map image for item location
* @param {Object} item
* @param {function} onClick
*/
export default function AgendaPreviewImage({item, onClick}: any) {
export default function AgendaPreviewImage({item, onClick}: IProps) {
if (!shouldRenderLocation(item)) {
return null;
}
Expand All @@ -20,10 +24,11 @@ export default function AgendaPreviewImage({item, onClick}: any) {

return (
<BannerDrop
id={get(item, '_id')}
id={item._id}
labelCollapsed={gettext('Show Map')}
labelOpened={gettext('Hide Map')}
isOpen={get(item, 'coverages.length', 0) === 0} >
isOpenDefault={true}
>
<div className="wire-column__preview__image" onClick={() => onClick(item)}>
<StaticMap locations={locations} />
</div>
Expand All @@ -34,4 +39,4 @@ export default function AgendaPreviewImage({item, onClick}: any) {
AgendaPreviewImage.propTypes = {
item: PropTypes.object.isRequired,
onClick: PropTypes.func.isRequired,
};
};
38 changes: 20 additions & 18 deletions assets/components/BannerDrop.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,31 @@
import React from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';

class BannerDrop extends React.Component<any, any> {
static propTypes: any;
constructor(props: any) {
interface IProps {
isOpenDefault: boolean;
id?: string;
children?: React.ReactNode;
labelCollapsed: string;
labelOpened: string;
}

interface IState {
open: boolean;
}

export default class BannerDrop extends React.Component<IProps, IState> {
constructor(props: IProps) {
super(props);
this.state = {open: this.props.isOpen};
this.state = {
open: this.props.isOpenDefault
};
this.toggleOpen = this.toggleOpen.bind(this);
}

componentWillReceiveProps(nextProps: any) {
componentWillReceiveProps(nextProps: IProps) {
if (this.props.id !== nextProps.id &&
this.state.open !== nextProps.isOpen) {
this.setState({open: nextProps.isOpen});
this.state.open !== nextProps.isOpenDefault) {
this.setState({open: nextProps.isOpenDefault});
}
}

Expand All @@ -40,13 +52,3 @@ class BannerDrop extends React.Component<any, any> {
</div>);
}
}

BannerDrop.propTypes = {
id: PropTypes.string,
children: PropTypes.node,
isOpen: PropTypes.bool,
labelCollapsed: PropTypes.string,
labelOpened: PropTypes.string,
};

export default BannerDrop;
21 changes: 10 additions & 11 deletions assets/maps/components/static.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
import React from 'react';
import PropTypes from 'prop-types';
import {getMapSource} from '../utils';
import {gettext} from '../../utils';

interface IProps {
scale?: number;
locations?: Array<any>;
}

interface IState {
mapLoaded: boolean;
}

class StaticMap extends React.Component<any, any> {
static propTypes: any;
constructor(props: any) {
export default class StaticMap extends React.Component<IProps, IState> {
constructor(props: IProps) {
super(props);
this.state = {
mapLoaded: false
Expand Down Expand Up @@ -39,10 +45,3 @@ class StaticMap extends React.Component<any, any> {
);
}
}

StaticMap.propTypes = {
scale: PropTypes.number,
locations: PropTypes.arrayOf(PropTypes.object),
};

export default StaticMap;

0 comments on commit 65c826e

Please sign in to comment.