diff --git a/client/index.js b/client/index.js index 73b241041f..a438cd3167 100644 --- a/client/index.js +++ b/client/index.js @@ -27,7 +27,7 @@ app$({ history, location: appLocation }) .flatMap( ({ AppCat }) => { // instantiate the cat with service - const appCat = AppCat(null, services, history); + const appCat = AppCat(null, services); // hydrate the stores return hydrate(appCat, catState) .map(() => appCat); @@ -36,6 +36,20 @@ app$({ history, location: appLocation }) // redirects in the future ({ nextLocation, props }, appCat) => ({ nextLocation, props, appCat }) ) + .doOnNext(({ appCat }) => { + const appStore = appCat.getStore('appStore'); + const appActions = appCat.getActions('appActions'); + + appStore + .distinctUntilChanged() + .subscribe(function({ route = appLocation.pathname }) { + history.pushState(null, route); + }); + + appActions.goBack.subscribe(function() { + history.goBack(); + }); + }) .flatMap(({ props, appCat }) => { props.history = history; return Render( diff --git a/common/app/Cat.js b/common/app/Cat.js index 6027fa9f2d..31dae9d294 100644 --- a/common/app/Cat.js +++ b/common/app/Cat.js @@ -5,8 +5,8 @@ import { HikesActions, HikesStore } from './routes/Hikes/flux'; import { JobActions, JobsStore} from './routes/Jobs/flux'; export default Cat() - .init(({ instance: cat, args: [services, history] }) => { - cat.register(AppActions, null, services, history); + .init(({ instance: cat, args: [services] }) => { + cat.register(AppActions, null, services); cat.register(AppStore, null, cat); cat.register(HikesActions, null, services); diff --git a/common/app/flux/Actions.js b/common/app/flux/Actions.js index 2c4545afaf..1de396d835 100644 --- a/common/app/flux/Actions.js +++ b/common/app/flux/Actions.js @@ -17,19 +17,13 @@ export default Actions({ }, getUser: null, - goTo: null, + goTo(route) { + return { route }; + }, goBack: null }) .refs({ displayName: 'AppActions' }) - .init(({ instance: appActions, args: [services, history] }) => { - appActions.goTo.subscribe((url) => { - history.pushState(null, url); - }); - - appActions.goBack.subscribe(() => { - history.goBack(); - }); - + .init(({ instance: appActions, args: [services] }) => { appActions.getUser.subscribe(({ isPrimed }) => { if (isPrimed) { debug('isPrimed'); diff --git a/common/app/flux/Store.js b/common/app/flux/Store.js index 30ee4e7ff3..5891c17b8f 100644 --- a/common/app/flux/Store.js +++ b/common/app/flux/Store.js @@ -14,10 +14,10 @@ export default Store({ value: initValue }, init({ instance: appStore, args: [cat] }) { - const { setUser, setTitle } = cat.getActions('appActions'); + const { goTo, setUser, setTitle } = cat.getActions('appActions'); const register = createRegistrar(appStore); - register(setter(fromMany(setUser, setTitle))); + register(setter(fromMany(setUser, setTitle, goTo))); return appStore; } diff --git a/common/app/routes/Jobs/components/GoToPayPal.jsx b/common/app/routes/Jobs/components/GoToPayPal.jsx index 3345e16d08..59b33cc32b 100644 --- a/common/app/routes/Jobs/components/GoToPayPal.jsx +++ b/common/app/routes/Jobs/components/GoToPayPal.jsx @@ -12,7 +12,10 @@ const paypalIds = { export default contain( { store: 'JobsStore', - actions: 'jobActions', + actions: [ + 'jobActions', + 'appActions' + ], map({ job: { id, isHighlighted } = {}, buttonId = isHighlighted ? @@ -40,6 +43,7 @@ export default contain( displayName: 'GoToPayPal', propTypes: { + appActions: PropTypes.object, id: PropTypes.string, isHighlighted: PropTypes.bool, buttonId: PropTypes.string, @@ -51,6 +55,11 @@ export default contain( jobActions: PropTypes.object }, + goToJobBoard() { + const { appActions } = this.props; + appActions.goTo('/jobs'); + }, + renderDiscount(discountAmount) { if (!discountAmount) { return null; @@ -217,7 +226,8 @@ export default contain(