From 4c1646fdef902c604c7d778f294d9476530232bf Mon Sep 17 00:00:00 2001 From: Connor Turland Date: Mon, 13 Mar 2017 09:21:16 -0400 Subject: [PATCH] fix up navigation to use react-router --- frontend/src/Metamaps/GlobalUI/ReactApp.js | 26 ++++++++++++++-------- frontend/src/Metamaps/GlobalUI/Search.js | 8 ++++--- frontend/src/Metamaps/Map/InfoBox.js | 3 ++- frontend/src/Metamaps/Map/index.js | 10 +++++---- 4 files changed, 30 insertions(+), 17 deletions(-) diff --git a/frontend/src/Metamaps/GlobalUI/ReactApp.js b/frontend/src/Metamaps/GlobalUI/ReactApp.js index 14c80f2b..bd479458 100644 --- a/frontend/src/Metamaps/GlobalUI/ReactApp.js +++ b/frontend/src/Metamaps/GlobalUI/ReactApp.js @@ -44,18 +44,21 @@ const ReactApp = { }, handleUpdate: function(location) { const self = ReactApp + const pathname = this.state.location.pathname // TODO: also handle page title updates - switch (this.state.location.pathname.split('/')[1]) { + switch (pathname.split('/')[1]) { case '': - if (Active.Mapper) $('#yield').hide() - ExploreMaps.updateFromPath(this.state.location.pathname) - self.mapId = null - Active.Map = null - Active.Topic = null + if (Active.Mapper) { + $('#yield').hide() + ExploreMaps.updateFromPath(pathname) + self.mapId = null + Active.Map = null + Active.Topic = null + } break case 'explore': $('#yield').hide() - ExploreMaps.updateFromPath(this.state.location.pathname) + ExploreMaps.updateFromPath(pathname) self.mapId = null Active.Map = null Active.Topic = null @@ -64,8 +67,13 @@ const ReactApp = { $('#yield').hide() break case 'maps': - $('#yield').hide() - self.mapId = this.state.location.pathname.split('/')[2] + if (!pathname.includes('request_access')) { + $('#yield').hide() + self.mapId = pathname.split('/')[2] + } + break + default: + $('#yield').show() break } self.render() diff --git a/frontend/src/Metamaps/GlobalUI/Search.js b/frontend/src/Metamaps/GlobalUI/Search.js index be4b5f3e..7e28906c 100644 --- a/frontend/src/Metamaps/GlobalUI/Search.js +++ b/frontend/src/Metamaps/GlobalUI/Search.js @@ -1,5 +1,7 @@ /* global $, Hogan, Bloodhound, CanvasLoader */ +import { browserHistory } from 'react-router' + import Active from '../Active' const Search = { @@ -189,11 +191,11 @@ const Search = { if (['topic', 'map', 'mapper'].indexOf(datum.rtype) !== -1) { if (datum.rtype === 'topic') { - // TODO: navigate to topic datum.id + browserHistory.push(`/topics/${datum.id}`) } else if (datum.rtype === 'map') { - // TODO: navigate to map datum.id + browserHistory.push(`/maps/${datum.id}`) } else if (datum.rtype === 'mapper') { - // TODO: navigate to mapper section datum.id + browserHistory.push(`/explore/mapper/${datum.id}`) } } }, diff --git a/frontend/src/Metamaps/Map/InfoBox.js b/frontend/src/Metamaps/Map/InfoBox.js index 59f66411..3f6fcd9c 100644 --- a/frontend/src/Metamaps/Map/InfoBox.js +++ b/frontend/src/Metamaps/Map/InfoBox.js @@ -1,6 +1,7 @@ /* global $, Hogan, Bloodhound, Countable */ import outdent from 'outdent' +import { browserHistory } from 'react-router' import Active from '../Active' import DataModel from '../DataModel' @@ -376,7 +377,7 @@ const InfoBox = { DataModel.Maps.Mine.remove(map) DataModel.Maps.Shared.remove(map) map.destroy() - // TODO: navigate home + browserHistory.push('/') GlobalUI.notifyUser('Map eliminated') } else if (!authorized) { window.alert("Hey now. We can't just go around willy nilly deleting other people's maps now can we? Run off and find something constructive to do, eh?") diff --git a/frontend/src/Metamaps/Map/index.js b/frontend/src/Metamaps/Map/index.js index b06131ef..0f83286b 100644 --- a/frontend/src/Metamaps/Map/index.js +++ b/frontend/src/Metamaps/Map/index.js @@ -2,6 +2,7 @@ import outdent from 'outdent' import { find as _find } from 'lodash' +import { browserHistory } from 'react-router' import Active from '../Active' import AutoLayout from '../AutoLayout' @@ -84,7 +85,6 @@ const Map = { launch: function(id) { const self = Map var start = function() { - document.title = Active.Map.get('name') + ' | Metamaps' Map.setAccessRequest() $('#filter_by_mapper h3').html('MAPPERS') // TODO: rewrite filter box in react Visualize.type = 'ForceDirected' @@ -97,7 +97,9 @@ const Map = { Filter.checkMappers() Realtime.startActiveMap() Loading.hide() - $('#header_content').html(Active.Map.get('name')) // TODO: make this use ReactApp.mobileTitle to set this + document.title = Active.Map.get('name') + ' | Metamaps' + ReactApp.mobileTitle = Active.Map.get('name') + ReactApp.render() } function isLoaded() { if (InfoBox.generateBoxHTML) start() @@ -210,7 +212,7 @@ const Map = { var map = Active.Map DataModel.Maps.Active.remove(map) DataModel.Maps.Featured.remove(map) - // TODO: navigate home + browserHistory.push('/') GlobalUI.notifyUser('Sorry! That map has been changed to Private.') }, cantEditNow: function() { @@ -223,7 +225,7 @@ const Map = { confirmString += 'Do you want to reload and enable realtime collaboration?' var c = window.confirm(confirmString) if (c) { - // TODO: reload the map somehow + window.location.reload() } }, editedByActiveMapper: function() {