mirror of
https://bitbucket.org/wisemapping/wisemapping-frontend.git
synced 2024-11-22 06:37:56 +01:00
Complete dispatcher
This commit is contained in:
parent
be7c307425
commit
9c353a0dd1
52
src/index.js
52
src/index.js
@ -13,19 +13,63 @@ function loadLocaleData(language) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const Apps = Object.freeze({
|
||||||
|
LOGIN: {
|
||||||
|
id: 'login',
|
||||||
|
path: '/c/login'
|
||||||
|
},
|
||||||
|
REGISTRATION: {
|
||||||
|
id: 'registration',
|
||||||
|
path: '/c/user/registration'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
function router() {
|
||||||
|
let result = null;
|
||||||
|
|
||||||
|
// Is it running ebedded ?.
|
||||||
|
const location = window.location;
|
||||||
|
if (location.pathname.indexOf('/c/') !== -1) {
|
||||||
|
const pathname = location.pathname;
|
||||||
|
result = Object.values(Apps).find(value => value.path.endsWith(pathname));
|
||||||
|
} else {
|
||||||
|
// It's loaded from the npm start
|
||||||
|
const pageId = new URLSearchParams(location.search).get('app');
|
||||||
|
result = Object.values(Apps).find(value => value.id == pageId);
|
||||||
|
}
|
||||||
|
if (result === null) {
|
||||||
|
result = Apps.LOGIN;
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log("router():" + result);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
async function bootstrapApplication() {
|
async function bootstrapApplication() {
|
||||||
|
|
||||||
|
// Boostrap i18n ...
|
||||||
const locale = (navigator.languages && navigator.languages[0])
|
const locale = (navigator.languages && navigator.languages[0])
|
||||||
|| navigator.language
|
|| navigator.language
|
||||||
|| navigator.userLanguage
|
|| navigator.userLanguage
|
||||||
|| 'en-US';
|
|| 'en-US';
|
||||||
const language = locale.split('-')[0];
|
const language = locale.split('-')[0];
|
||||||
|
|
||||||
const messages = (await loadLocaleData(language));
|
const messages = (await loadLocaleData(language));
|
||||||
|
|
||||||
console.log(messages)
|
// Todo: This is a temporal hack to rudimentary dispatch application.
|
||||||
console.log(language)
|
let rootPage;
|
||||||
|
switch (router()) {
|
||||||
|
case Apps.LOGIN:
|
||||||
|
rootPage = <LoginPage locale={locale} messages={messages} />;
|
||||||
|
break
|
||||||
|
case Apps.REGISTRATION:
|
||||||
|
rootPage = <div>Register</div>;
|
||||||
|
break
|
||||||
|
default:
|
||||||
|
rootPage = <LoginPage locale={locale} messages={messages} />;
|
||||||
|
}
|
||||||
|
|
||||||
ReactDOM.render(
|
ReactDOM.render(
|
||||||
<LoginPage locale={locale} messages={messages} />,
|
rootPage,
|
||||||
document.getElementById('root')
|
document.getElementById('root')
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user