make other routes work

This commit is contained in:
Connor Turland 2017-03-12 12:26:49 -04:00
parent 96c202c7bf
commit 0741743660
8 changed files with 45 additions and 28 deletions

View file

@ -1,15 +1,6 @@
<%= render :partial => 'layouts/lightboxes' %> <%= render :partial => 'layouts/lightboxes' %>
<%= render :partial => 'layouts/templates' %> <%= render :partial => 'layouts/templates' %>
<%= render :partial => 'shared/metacodeBgColors' %> <%= render :partial => 'shared/metacodeBgColors' %>
<script type="text/javascript" charset="utf-8">
<% if current_user %>
Metamaps.ServerData.ActiveMapper = <%= current_user.to_json({follows: true, email: true, follow_settings: true}).html_safe %>
<% else %>
Metamaps.ServerData.ActiveMapper = null
<% end %>
Metamaps.Loading.setup()
</script>
<%= render :partial => 'layouts/googleanalytics' if ENV["GA_TRACKING_CODE"].present? %> <%= render :partial => 'layouts/googleanalytics' if ENV["GA_TRACKING_CODE"].present? %>
</body> </body>
</html> </html>

View file

@ -7,9 +7,8 @@
<%= render :partial => 'layouts/head' %> <%= render :partial => 'layouts/head' %>
<body class="<%= authenticated? ? "authenticated" : "unauthenticated" %> controller-<%= controller_name %> action-<%= action_name %>"> <body class="<%= authenticated? ? "authenticated" : "unauthenticated" %> controller-<%= controller_name %> action-<%= action_name %>">
<%= content_tag :div, class: "main", id: "react-app" do %> <div class="main" id="react-app"></div>
<%= yield %> <%= yield %>
<% end %>
<% if devise_error_messages? %> <% if devise_error_messages? %>
<%= devise_error_messages! %> <%= devise_error_messages! %>
<% end %> <% end %>
@ -29,14 +28,14 @@
<%= render :partial => 'maps/newsynapse' %> <%= render :partial => 'maps/newsynapse' %>
<% # for populating the change metacode list on the topic card %> <% # for populating the change metacode list on the topic card %>
<%= render :partial => 'shared/metacodeoptions' %> <%= render :partial => 'shared/metacodeoptions' %>
<script type="text/javascript">
Metamaps.ServerData.unreadNotificationsCount = <%= user_unread_notification_count %>
Metamaps.ServerData.mapIsStarred = <%= @map && current_user.starred_map?(@map) ? true : false %>
</script>
<% end %> <% end %>
<script type="text/javascript">
Metamaps.ServerData.mobileTitle = "<%= yield(:mobile_title) %>"
</script>
<div class="hidden"><%= render :partial => 'shared/filterBox' %></div> <div class="hidden"><%= render :partial => 'shared/filterBox' %></div>
<div id="loading"></div> <div id="loading"></div>
<script type="text/javascript">
Metamaps.ServerData.unreadNotificationsCount = <%= current_user ? user_unread_notification_count : 0 %>
Metamaps.ServerData.mapIsStarred = <%= current_user && @map && current_user.starred_map?(@map) ? true : false %>
Metamaps.ServerData.mobileTitle = "<%= yield(:mobile_title) %>"
Metamaps.ServerData.ActiveMapper = <%= current_user ? current_user.to_json({follows: true, email: true, follow_settings: true}).html_safe : nil %>
Metamaps.Loading.setup()
</script>
<%= render :partial => 'layouts/foot' %> <%= render :partial => 'layouts/foot' %>

View file

@ -37,7 +37,7 @@ const ReactApp = {
self.unreadNotificationsCount = serverData.unreadNotificationsCount self.unreadNotificationsCount = serverData.unreadNotificationsCount
self.mobileTitle = serverData.mobileTitle self.mobileTitle = serverData.mobileTitle
self.openLightbox = openLightbox self.openLightbox = openLightbox
routes = makeRoutes() routes = makeRoutes(serverData.ActiveMapper)
self.resize() self.resize()
window && window.addEventListener('resize', self.resize) window && window.addEventListener('resize', self.resize)
}, },
@ -47,14 +47,17 @@ const ReactApp = {
switch (this.state.location.pathname.split('/')[1]) { switch (this.state.location.pathname.split('/')[1]) {
case '': case '':
case 'explore': case 'explore':
$('#yield').hide()
ExploreMaps.updateFromPath(this.state.location.pathname) ExploreMaps.updateFromPath(this.state.location.pathname)
self.mapId = null self.mapId = null
Active.Map = null Active.Map = null
Active.Topic = null Active.Topic = null
break break
case 'topics': case 'topics':
$('#yield').hide()
break break
case 'maps': case 'maps':
$('#yield').hide()
self.mapId = this.state.location.pathname.split('/')[2] self.mapId = this.state.location.pathname.split('/')[2]
break break
} }

View file

@ -16,6 +16,7 @@ const Search = {
self.userIconUrl = serverData['user.png'] self.userIconUrl = serverData['user.png']
// this is similar to Metamaps.Loading, but it's for the search element // this is similar to Metamaps.Loading, but it's for the search element
if (!document.getElementById('searchLoading')) return
var loader = new CanvasLoader('searchLoading') var loader = new CanvasLoader('searchLoading')
loader.setColor('#4fb5c0') // default is '#000000' loader.setColor('#4fb5c0') // default is '#000000'
loader.setDiameter(24) // default is 40 loader.setDiameter(24) // default is 40

View file

@ -19,12 +19,13 @@ const GlobalUI = {
const self = GlobalUI const self = GlobalUI
self.ReactApp.init(serverData, self.openLightbox) self.ReactApp.init(serverData, self.openLightbox)
self.Search.init(serverData)
self.CreateMap.init(serverData) self.CreateMap.init(serverData)
self.Account.init(serverData) self.Account.init(serverData)
self.ImportDialog.init(serverData, self.openLightbox, self.closeLightbox) self.ImportDialog.init(serverData, self.openLightbox, self.closeLightbox)
self.Search.init(serverData)
if ($('#toast').html().trim()) self.notifyUser($('#toast').html()) const toastHtml = $('#toast').html()
if (toastHtml && toastHtml.trim()) self.notifyUser(toastHtml)
// bind lightbox clicks // bind lightbox clicks
$('.openLightbox').click(function(event) { $('.openLightbox').click(function(event) {

View file

@ -15,6 +15,7 @@ const Loading = {
Loading.loader.setDensity(41) // default is 40 Loading.loader.setDensity(41) // default is 40
Loading.loader.setRange(0.9) // default is 1.3 Loading.loader.setRange(0.9) // default is 1.3
Loading.loader.show() // Hidden by default Loading.loader.show() // Hidden by default
$('#loading').hide()
} }
} }

View file

@ -30,17 +30,20 @@ class App extends Component {
render () { render () {
const { children, toast, currentUser, unreadNotificationsCount, openInviteLightbox, const { children, toast, currentUser, unreadNotificationsCount, openInviteLightbox,
mobile, mobileTitle, mobileTitleWidth, mobileTitleClick } = this.props mobile, mobileTitle, mobileTitleWidth, mobileTitleClick, location } = this.props
const { pathname } = location || {}
const unauthedHome = pathname === '/' && !currentUser
return <div className="wrapper" id="wrapper"> return <div className="wrapper" id="wrapper">
{mobile && <MobileHeader currentUser={currentUser} {mobile && <MobileHeader currentUser={currentUser}
unreadNotificationsCount={unreadNotificationsCount} unreadNotificationsCount={unreadNotificationsCount}
mobileTitle={mobileTitle} mobileTitle={mobileTitle}
mobileTitleWidth={mobileTitleWidth} mobileTitleWidth={mobileTitleWidth}
onTitleClick={mobileTitleClick} />} onTitleClick={mobileTitleClick} />}
<UpperLeftUI currentUser={currentUser} /> {!unauthedHome && <UpperLeftUI currentUser={currentUser} />}
{!mobile && <UpperRightUI currentUser={currentUser} {!mobile && <UpperRightUI currentUser={currentUser}
unreadNotificationsCount={unreadNotificationsCount} unreadNotificationsCount={unreadNotificationsCount}
openInviteLightbox={openInviteLightbox} />} openInviteLightbox={openInviteLightbox}
signInPage={pathname === '/login'} />}
<Toast message={toast} /> <Toast message={toast} />
{!mobile && currentUser && <a className='feedback-icon' target='_blank' href='https://hylo.com/c/metamaps'></a>} {!mobile && currentUser && <a className='feedback-icon' target='_blank' href='https://hylo.com/c/metamaps'></a>}
{children} {children}

View file

@ -4,9 +4,14 @@ import App from './App'
import Maps from './Maps' import Maps from './Maps'
import MapView from './MapView' import MapView from './MapView'
export default function makeRoutes () { function nullComponent(props) {
return null
}
export default function makeRoutes (currentUser) {
const homeComponent = currentUser ? Maps : nullComponent
return <Route path="/" component={App} > return <Route path="/" component={App} >
<IndexRoute component={Maps} /> <IndexRoute component={homeComponent} />
<Route path="explore"> <Route path="explore">
<Route path="active" component={Maps} /> <Route path="active" component={Maps} />
<Route path="featured" component={Maps} /> <Route path="featured" component={Maps} />
@ -15,6 +20,19 @@ export default function makeRoutes () {
<Route path="starred" component={Maps} /> <Route path="starred" component={Maps} />
<Route path="mapper/:id" component={Maps} /> <Route path="mapper/:id" component={Maps} />
</Route> </Route>
<Route path="maps/:id" component={MapView} /> <Route path="maps/:id">
<IndexRoute component={MapView} />
<Route path="conversation" component={MapView} />
</Route>
<Route path="/login" component={nullComponent} />
<Route path="/join" component={nullComponent} />
<Route path="/request" component={nullComponent} />
<Route path="/notifications" component={nullComponent} />
<Route path="/notifications/:id" component={nullComponent} />
<Route path="/users/:id/edit" component={nullComponent} />
<Route path="/metacodes" component={nullComponent} />
<Route path="/metacodes/new" component={nullComponent} />
<Route path="/metacode_sets" component={nullComponent} />
<Route path="/metacode_sets/new" component={nullComponent} />
</Route> </Route>
} }