From d5ea4e515d8cedf0cd50ed0a26eaf98343fbcf4b Mon Sep 17 00:00:00 2001 From: vrde Date: Fri, 10 Jul 2015 16:43:35 +0200 Subject: [PATCH 1/8] Use distinct routers for different apps --- js/app.js | 40 +++++++++++++++---- js/components/routes.js | 25 ++++++++++++ js/components/whitelabel/prize/app.js | 24 +++++++++++ .../whitelabel/prize/components/landing.js | 15 +++++++ js/components/whitelabel/prize/routes.js | 26 ++++++++++++ js/routes.js | 27 ++++++++++--- 6 files changed, 144 insertions(+), 13 deletions(-) create mode 100644 js/components/routes.js create mode 100644 js/components/whitelabel/prize/app.js create mode 100644 js/components/whitelabel/prize/components/landing.js create mode 100644 js/components/whitelabel/prize/routes.js diff --git a/js/app.js b/js/app.js index a54f01d9..38fcbd40 100644 --- a/js/app.js +++ b/js/app.js @@ -8,7 +8,7 @@ import Router from 'react-router'; import fetch from 'isomorphic-fetch'; import ApiUrls from './constants/api_urls'; -import routes from './routes'; +import getRoutes from './routes'; import requests from './utils/requests'; let headers = { @@ -28,9 +28,35 @@ requests.defaults({ } }); -Router.run(routes, Router.HistoryLocation, (AscribeApp) => { - React.render( - , - document.getElementById('main') - ); -}); + +class AppGateway { + + start() { + let subdomain = window.location.host.split('.')[0]; + requests.get('whitelabel_settings', {'subdomain': subdomain}) + .then(this.loadSubdomain.bind(this)) + .catch(this.loadDefault.bind(this)); + } + + loadSubdomain(data) { + let settings = data.whitelabel; + + this.load('prize'); + } + + loadDefault() { + this.load('default'); + } + + load(type) { + Router.run(getRoutes(type), Router.HistoryLocation, (App) => { + React.render( + , + document.getElementById('main') + ); + }); + } +} + +let ag = new AppGateway(); +ag.start(); diff --git a/js/components/routes.js b/js/components/routes.js new file mode 100644 index 00000000..431d02fb --- /dev/null +++ b/js/components/routes.js @@ -0,0 +1,25 @@ +'use strict'; + +import React from 'react'; +import Router from 'react-router'; + +import App from './ascribe_app'; +import AppConstants from '../constants/application_constants'; + +let Route = Router.Route; +let Redirect = Router.Redirect; +let baseUrl = AppConstants.baseUrl; + + +function getRoutes(commonRoutes) { + return ( + + {commonRoutes} + + + + ); +} + + +export default getRoutes; diff --git a/js/components/whitelabel/prize/app.js b/js/components/whitelabel/prize/app.js new file mode 100644 index 00000000..c2ca7993 --- /dev/null +++ b/js/components/whitelabel/prize/app.js @@ -0,0 +1,24 @@ +'use strict'; + +import React from 'react'; +import Router from 'react-router'; +import Footer from '../../footer'; +import GlobalNotification from '../../global_notification'; + +let RouteHandler = Router.RouteHandler; + + +let PrizeApp = React.createClass({ + render() { + return ( +
+ +
+ + +
+ ); + } +}); + +export default PrizeApp; diff --git a/js/components/whitelabel/prize/components/landing.js b/js/components/whitelabel/prize/components/landing.js new file mode 100644 index 00000000..e4fb2df8 --- /dev/null +++ b/js/components/whitelabel/prize/components/landing.js @@ -0,0 +1,15 @@ +'use strict'; + +import React from 'react'; + +let Landing = React.createClass({ + render() { + return ( +
+ Hello from landing +
+ ); + } +}); + +export default Landing; diff --git a/js/components/whitelabel/prize/routes.js b/js/components/whitelabel/prize/routes.js new file mode 100644 index 00000000..e5abb074 --- /dev/null +++ b/js/components/whitelabel/prize/routes.js @@ -0,0 +1,26 @@ +'use strict'; + +import React from 'react'; +import Router from 'react-router'; + +import Landing from './components/landing'; + +import App from './app'; +import AppConstants from '../../../constants/application_constants'; + +let Route = Router.Route; +// let Redirect = Router.Redirect; +let baseUrl = AppConstants.baseUrl; + + +function getRoutes(commonRoutes) { + return ( + + + {commonRoutes} + + ); +} + + +export default getRoutes; diff --git a/js/routes.js b/js/routes.js index db8ed171..0da2f6de 100644 --- a/js/routes.js +++ b/js/routes.js @@ -4,6 +4,10 @@ import React from 'react'; import Router from 'react-router'; import AscribeApp from './components/ascribe_app'; + +import getPrizeRoutes from './components/whitelabel/prize/routes'; +import getDefaultRoutes from './components/routes'; + import PieceList from './components/piece_list'; import PieceContainer from './components/ascribe_detail/piece_container'; import EditionContainer from './components/ascribe_detail/edition_container'; @@ -22,8 +26,9 @@ let Route = Router.Route; let Redirect = Router.Redirect; let baseUrl = AppConstants.baseUrl; -let routes = ( - + +const COMMON_ROUTES = ( + @@ -33,10 +38,20 @@ let routes = ( - - - ); -export default routes; + +function getRoutes(type) { + let routes = null; + if (type === 'prize') { + routes = getPrizeRoutes(COMMON_ROUTES); + } else { + routes = getDefaultRoutes(COMMON_ROUTES); + } + + return routes; +} + + +export default getRoutes; From df5295dffd11a69e7e76e09dbebcbecce5e60db8 Mon Sep 17 00:00:00 2001 From: vrde Date: Fri, 10 Jul 2015 18:21:42 +0200 Subject: [PATCH 2/8] Cleanup and reorder routes --- js/app.js | 2 +- js/components/ascribe_app.js | 2 +- js/components/routes.js | 2 +- js/components/whitelabel/prize/routes.js | 1 - js/routes.js | 5 ----- 5 files changed, 3 insertions(+), 9 deletions(-) diff --git a/js/app.js b/js/app.js index 38fcbd40..7d627c82 100644 --- a/js/app.js +++ b/js/app.js @@ -1,6 +1,6 @@ 'use strict'; -require("babel/polyfill"); +require('babel/polyfill'); import React from 'react'; import Router from 'react-router'; diff --git a/js/components/ascribe_app.js b/js/components/ascribe_app.js index 9000094f..c34e3462 100644 --- a/js/components/ascribe_app.js +++ b/js/components/ascribe_app.js @@ -6,7 +6,7 @@ import Header from '../components/header'; import Footer from '../components/footer'; import GlobalNotification from './global_notification'; -let Link = Router.Link; +// let Link = Router.Link; let RouteHandler = Router.RouteHandler; diff --git a/js/components/routes.js b/js/components/routes.js index 431d02fb..8b230a5a 100644 --- a/js/components/routes.js +++ b/js/components/routes.js @@ -14,9 +14,9 @@ let baseUrl = AppConstants.baseUrl; function getRoutes(commonRoutes) { return ( - {commonRoutes} + {commonRoutes} ); } diff --git a/js/components/whitelabel/prize/routes.js b/js/components/whitelabel/prize/routes.js index e5abb074..6003a698 100644 --- a/js/components/whitelabel/prize/routes.js +++ b/js/components/whitelabel/prize/routes.js @@ -9,7 +9,6 @@ import App from './app'; import AppConstants from '../../../constants/application_constants'; let Route = Router.Route; -// let Redirect = Router.Redirect; let baseUrl = AppConstants.baseUrl; diff --git a/js/routes.js b/js/routes.js index 0da2f6de..3dbc6ca8 100644 --- a/js/routes.js +++ b/js/routes.js @@ -3,8 +3,6 @@ import React from 'react'; import Router from 'react-router'; -import AscribeApp from './components/ascribe_app'; - import getPrizeRoutes from './components/whitelabel/prize/routes'; import getDefaultRoutes from './components/routes'; @@ -19,12 +17,9 @@ import PasswordResetContainer from './components/password_reset_container'; import SettingsContainer from './components/settings_container'; import CoaVerifyContainer from './components/coa_verify_container'; -import AppConstants from './constants/application_constants'; import RegisterPiece from './components/register_piece'; let Route = Router.Route; -let Redirect = Router.Redirect; -let baseUrl = AppConstants.baseUrl; const COMMON_ROUTES = ( From 33d599b9235e574800e20cf465c19176a570fe5a Mon Sep 17 00:00:00 2001 From: vrde Date: Fri, 10 Jul 2015 18:45:26 +0200 Subject: [PATCH 3/8] Start to work on custom landing --- js/components/whitelabel/prize/app.js | 2 +- .../whitelabel/prize/components/landing.js | 13 ++++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/js/components/whitelabel/prize/app.js b/js/components/whitelabel/prize/app.js index c2ca7993..cd6928de 100644 --- a/js/components/whitelabel/prize/app.js +++ b/js/components/whitelabel/prize/app.js @@ -11,7 +11,7 @@ let RouteHandler = Router.RouteHandler; let PrizeApp = React.createClass({ render() { return ( -
+