diff --git a/js/actions/user_actions.js b/js/actions/user_actions.js index 661890e9..3780a802 100644 --- a/js/actions/user_actions.js +++ b/js/actions/user_actions.js @@ -13,7 +13,7 @@ class UserActions { } fetchCurrentUser() { - return UserFetcher.fetchOne() + UserFetcher.fetchOne() .then((res) => { this.actions.updateCurrentUser(res.users[0]); }) @@ -24,7 +24,7 @@ class UserActions { } logoutCurrentUser() { - return UserFetcher.logout() + UserFetcher.logout() .then(() => { this.actions.deleteCurrentUser(); }) diff --git a/js/app.js b/js/app.js index bd1b839a..c9451e47 100644 --- a/js/app.js +++ b/js/app.js @@ -3,7 +3,8 @@ require('babel/polyfill'); import React from 'react'; -import Router from 'react-router'; +import { Router, Redirect } from 'react-router'; +import history from './history'; /* eslint-disable */ import fetch from 'isomorphic-fetch'; @@ -46,7 +47,6 @@ requests.defaults({ } }); - class AppGateway { start() { let settings; @@ -68,22 +68,36 @@ class AppGateway { load(settings) { let type = 'default'; let subdomain = 'www'; + let redirectRoute = (); if (settings) { type = settings.type; subdomain = settings.subdomain; } + // www and cc do not have a landing page + if(subdomain && subdomain !== 'cc') { + redirectRoute = null; + } + + // Adds a client specific class to the body for whitelabel styling window.document.body.classList.add('client--' + subdomain); + // Send the applicationWillBoot event to the third-party stores EventActions.applicationWillBoot(settings); - window.appRouter = Router.run(getRoutes(type, subdomain), Router.HistoryLocation, (App) => { - React.render( - , - document.getElementById('main') - ); - EventActions.routeDidChange(); - }); + + // `history.listen` is called on every route change, which is perfect for + // us in that case. + history.listen(EventActions.routeDidChange); + + React.render(( + + {redirectRoute} + {getRoutes(type, subdomain)} + + ), document.getElementById('main')); + + // Send the applicationDidBoot event to the third-party stores EventActions.applicationDidBoot(settings); } } diff --git a/js/components/ascribe_accordion_list/accordion_list_item.js b/js/components/ascribe_accordion_list/accordion_list_item.js index 6204f57d..ce24c083 100644 --- a/js/components/ascribe_accordion_list/accordion_list_item.js +++ b/js/components/ascribe_accordion_list/accordion_list_item.js @@ -1,7 +1,7 @@ 'use strict'; import React from 'react'; -import Router from 'react-router'; + let AccordionListItem = React.createClass({ propTypes: { @@ -18,10 +18,7 @@ let AccordionListItem = React.createClass({ ]) }, - mixins: [Router.Navigation], - render() { - return (
diff --git a/js/components/ascribe_accordion_list/accordion_list_item_piece.js b/js/components/ascribe_accordion_list/accordion_list_item_piece.js index d0b16c9f..a7f09e85 100644 --- a/js/components/ascribe_accordion_list/accordion_list_item_piece.js +++ b/js/components/ascribe_accordion_list/accordion_list_item_piece.js @@ -1,14 +1,12 @@ 'use strict'; import React from 'react'; -import Router from 'react-router'; +import { Link } from 'react-router'; import AccordionListItem from './accordion_list_item'; import { getLangText } from '../../utils/lang_utils'; -let Link = Router.Link; - let AccordionListItemPiece = React.createClass({ propTypes: { @@ -24,26 +22,15 @@ let AccordionListItemPiece = React.createClass({ badge: React.PropTypes.object }, - mixins: [Router.Navigation], - getLinkData() { + let { piece } = this.props; + + if(piece && piece.first_edition) { + return `/editions/${piece.first_edition.bitcoin_id}`; - if(this.props.piece && this.props.piece.first_edition) { - return { - to: 'edition', - params: { - editionId: this.props.piece.first_edition.bitcoin_id - } - }; } else { - return { - to: 'piece', - params: { - pieceId: this.props.piece.id - } - }; + return `/pieces/${piece.id}`; } - }, render() { @@ -51,11 +38,11 @@ let AccordionListItemPiece = React.createClass({ + } heading={ - +

{this.props.piece.title}

} subheading={ diff --git a/js/components/ascribe_accordion_list/accordion_list_item_table_editions.js b/js/components/ascribe_accordion_list/accordion_list_item_table_editions.js index 350d61a8..7e258267 100644 --- a/js/components/ascribe_accordion_list/accordion_list_item_table_editions.js +++ b/js/components/ascribe_accordion_list/accordion_list_item_table_editions.js @@ -110,7 +110,7 @@ let AccordionListItemTableEditions = React.createClass({ showExpandOption = true; } - let transition = new TransitionModel('edition', 'editionId', 'bitcoin_id', (e) => e.stopPropagation() ); + let transition = new TransitionModel('editions', 'editionId', 'bitcoin_id', (e) => e.stopPropagation() ); let columnList = [ new ColumnModel( diff --git a/js/components/ascribe_app.js b/js/components/ascribe_app.js index 789399b0..0c9cd703 100644 --- a/js/components/ascribe_app.js +++ b/js/components/ascribe_app.js @@ -1,22 +1,29 @@ 'use strict'; import React from 'react'; -import Router from 'react-router'; + import Header from '../components/header'; import Footer from '../components/footer'; import GlobalNotification from './global_notification'; -import getRoutes from '../routes'; - - -let RouteHandler = Router.RouteHandler; let AscribeApp = React.createClass({ + propTypes: { + children: React.PropTypes.oneOfType([ + React.PropTypes.arrayOf(React.PropTypes.element), + React.PropTypes.element + ]), + routes: React.PropTypes.arrayOf(React.PropTypes.object) + }, + render() { + let { children, routes } = this.props; + return (
-
- +
+ {/* Routes are injected here */} + {children}