2017-09-19 10:16:14 -04:00
|
|
|
import React, { Component } from 'react'
|
2017-09-09 09:38:18 -07:00
|
|
|
import PropTypes from 'prop-types'
|
2017-03-16 17:58:56 -04:00
|
|
|
|
2017-10-14 12:31:20 -04:00
|
|
|
import ContextMenu from '../../components/ContextMenu'
|
2017-10-25 16:38:23 -04:00
|
|
|
import MapVis from '../../components/MapVis'
|
2017-10-14 12:31:20 -04:00
|
|
|
import UpperOptions from '../../components/UpperOptions'
|
|
|
|
import InfoAndHelp from '../../components/InfoAndHelp'
|
2017-03-16 17:58:56 -04:00
|
|
|
import Instructions from './Instructions'
|
2017-10-14 12:31:20 -04:00
|
|
|
import VisualizationControls from '../../components/VisualizationControls'
|
2017-03-16 17:58:56 -04:00
|
|
|
import MapChat from './MapChat'
|
2017-10-14 12:31:20 -04:00
|
|
|
import TopicCard from '../../components/TopicCard'
|
2017-03-16 17:58:56 -04:00
|
|
|
|
|
|
|
export default class MapView extends Component {
|
|
|
|
|
|
|
|
static propTypes = {
|
2017-09-18 23:30:33 -04:00
|
|
|
contextMenu: PropTypes.bool,
|
2017-03-16 17:58:56 -04:00
|
|
|
mobile: PropTypes.bool,
|
|
|
|
mapId: PropTypes.string,
|
|
|
|
map: PropTypes.object,
|
|
|
|
mapIsStarred: PropTypes.bool,
|
|
|
|
onMapStar: PropTypes.func,
|
|
|
|
onMapUnstar: PropTypes.func,
|
|
|
|
filterData: PropTypes.object,
|
|
|
|
allForFiltering: PropTypes.object,
|
|
|
|
visibleForFiltering: PropTypes.object,
|
|
|
|
toggleMetacode: PropTypes.func,
|
|
|
|
toggleMapper: PropTypes.func,
|
|
|
|
toggleSynapse: PropTypes.func,
|
|
|
|
filterAllMetacodes: PropTypes.func,
|
|
|
|
filterAllMappers: PropTypes.func,
|
|
|
|
filterAllSynapses: PropTypes.func,
|
|
|
|
toggleMapInfoBox: PropTypes.func,
|
|
|
|
infoBoxHtml: PropTypes.string,
|
|
|
|
currentUser: PropTypes.object,
|
|
|
|
endActiveMap: PropTypes.func,
|
|
|
|
launchNewMap: PropTypes.func,
|
|
|
|
openImportLightbox: PropTypes.func,
|
|
|
|
forkMap: PropTypes.func,
|
|
|
|
openHelpLightbox: PropTypes.func,
|
|
|
|
onZoomExtents: PropTypes.func,
|
|
|
|
onZoomIn: PropTypes.func,
|
|
|
|
onZoomOut: PropTypes.func,
|
|
|
|
hasLearnedTopicCreation: PropTypes.bool
|
|
|
|
}
|
|
|
|
|
|
|
|
constructor(props) {
|
|
|
|
super(props)
|
|
|
|
this.state = {
|
|
|
|
chatOpen: false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
componentWillUnmount() {
|
|
|
|
this.endMap()
|
|
|
|
}
|
|
|
|
|
|
|
|
endMap() {
|
|
|
|
this.setState({
|
|
|
|
chatOpen: false
|
|
|
|
})
|
|
|
|
this.mapChat.reset()
|
|
|
|
this.upperOptions.reset()
|
|
|
|
this.props.endActiveMap()
|
|
|
|
}
|
|
|
|
|
|
|
|
componentDidUpdate(prevProps) {
|
|
|
|
const oldMapId = prevProps.mapId
|
|
|
|
const { mapId, launchNewMap } = this.props
|
|
|
|
if (!oldMapId && mapId) launchNewMap(mapId)
|
|
|
|
else if (oldMapId && mapId && oldMapId !== mapId) {
|
|
|
|
this.endMap()
|
|
|
|
launchNewMap(mapId)
|
|
|
|
}
|
|
|
|
else if (oldMapId && !mapId) this.endMap()
|
|
|
|
}
|
|
|
|
|
|
|
|
render = () => {
|
|
|
|
const { mobile, map, currentUser, onOpen, onClose,
|
|
|
|
toggleMapInfoBox, infoBoxHtml, allForFiltering, visibleForFiltering,
|
|
|
|
toggleMetacode, toggleMapper, toggleSynapse, filterAllMetacodes,
|
|
|
|
filterAllMappers, filterAllSynapses, filterData,
|
|
|
|
openImportLightbox, forkMap, openHelpLightbox,
|
2017-03-22 16:09:47 +00:00
|
|
|
mapIsStarred, onMapStar, onMapUnstar, openTopic,
|
2017-09-18 23:30:33 -04:00
|
|
|
onZoomExtents, onZoomIn, onZoomOut, hasLearnedTopicCreation,
|
2017-10-25 16:38:23 -04:00
|
|
|
contextMenu, DataModel } = this.props
|
2017-03-16 17:58:56 -04:00
|
|
|
const { chatOpen } = this.state
|
|
|
|
const onChatOpen = () => {
|
|
|
|
this.setState({chatOpen: true})
|
|
|
|
onOpen()
|
|
|
|
}
|
|
|
|
const onChatClose = () => {
|
|
|
|
this.setState({chatOpen: false})
|
|
|
|
onClose()
|
|
|
|
}
|
|
|
|
const canEditMap = map && map.authorizeToEdit(currentUser)
|
|
|
|
// TODO: stop using {...this.props} and make explicit
|
|
|
|
return <div className="mapWrapper">
|
|
|
|
<UpperOptions ref={x => this.upperOptions = x}
|
|
|
|
map={map}
|
|
|
|
currentUser={currentUser}
|
|
|
|
onImportClick={openImportLightbox}
|
|
|
|
onForkClick={forkMap}
|
|
|
|
canEditMap={canEditMap}
|
|
|
|
filterData={filterData}
|
|
|
|
allForFiltering={allForFiltering}
|
|
|
|
visibleForFiltering={visibleForFiltering}
|
|
|
|
toggleMetacode={toggleMetacode}
|
|
|
|
toggleMapper={toggleMapper}
|
|
|
|
toggleSynapse={toggleSynapse}
|
|
|
|
filterAllMetacodes={filterAllMetacodes}
|
|
|
|
filterAllMappers={filterAllMappers}
|
|
|
|
filterAllSynapses={filterAllSynapses} />
|
2017-10-25 16:38:23 -04:00
|
|
|
<MapVis map={map} DataModel={DataModel} />
|
2017-03-22 16:09:47 +00:00
|
|
|
{openTopic && <TopicCard {...this.props} />}
|
2017-09-18 23:30:33 -04:00
|
|
|
{contextMenu && <ContextMenu {...this.props} />}
|
2017-03-16 17:58:56 -04:00
|
|
|
{currentUser && <Instructions mobile={mobile} hasLearnedTopicCreation={hasLearnedTopicCreation} />}
|
|
|
|
{currentUser && <MapChat {...this.props} onOpen={onChatOpen} onClose={onChatClose} chatOpen={chatOpen} ref={x => this.mapChat = x} />}
|
|
|
|
<VisualizationControls map={map}
|
|
|
|
onClickZoomExtents={onZoomExtents}
|
|
|
|
onClickZoomIn={onZoomIn}
|
|
|
|
onClickZoomOut={onZoomOut} />
|
|
|
|
<InfoAndHelp mapIsStarred={mapIsStarred}
|
|
|
|
currentUser={currentUser}
|
|
|
|
map={map}
|
|
|
|
onInfoClick={toggleMapInfoBox}
|
|
|
|
onMapStar={onMapStar}
|
|
|
|
onMapUnstar={onMapUnstar}
|
|
|
|
onHelpClick={openHelpLightbox}
|
|
|
|
infoBoxHtml={infoBoxHtml} />
|
|
|
|
</div>
|
|
|
|
}
|
|
|
|
}
|