diff --git a/app/appListeners.js b/app/appListeners.js index 8c5094d..7ab5851 100644 --- a/app/appListeners.js +++ b/app/appListeners.js @@ -3,7 +3,6 @@ export const appListeners = (app, state, emitter) => { document.title = app.siteConfig.siteName; // Emitter listeners emitter.on('render', callback => { - app.setSessionState(); // This is a dirty hack to get the callback to call *after* re-rendering. if (callback && typeof callback === "function") { setTimeout(() => { diff --git a/app/appRoutes.js b/app/appRoutes.js index 2c6c6b8..571673a 100644 --- a/app/appRoutes.js +++ b/app/appRoutes.js @@ -1,4 +1,3 @@ -import { I18n } from './i18n'; import { globalView } from './views/global'; import { homeView } from './views/home'; import { loginView } from './views/login'; @@ -6,13 +5,11 @@ import { searchView } from './views/search'; import { errorView } from './views/404'; export const appRoutes = (app) => { - const i18n = new I18n(app.state); // Global I18n class passed to all views + app.route('/', (state, emit) => globalView(state, emit, homeView)); - app.route('/', (state, emit) => globalView(state, emit, i18n, homeView)); + app.route('/login', (state, emit) => globalView(state, emit, loginView)); - app.route('/login', (state, emit) => globalView(state, emit, i18n, loginView)); + app.route('/search', (state, emit) => globalView(state, emit, searchView)); - app.route('/search', (state, emit) => globalView(state, emit, i18n, searchView)); - - app.route('/404', (state, emit) => globalView(state, emit, i18n, errorView)); + app.route('/404', (state, emit) => globalView(state, emit, errorView)); } diff --git a/app/appState.js b/app/appState.js index 9dfcfee..49f1b46 100644 --- a/app/appState.js +++ b/app/appState.js @@ -1,15 +1,8 @@ +import { I18n } from "./i18n"; + export const appState = (app, state, emitter) => { - const sessionState = app.getSessionState(); - if (sessionState) { - Object.keys(sessionState).forEach(key => { - if (typeof state[key] === 'undefined') { - state[key] = sessionState[key]; - } - }); - } else { - // Default state variables - state.language = app.getSettingsItem('lang') ? app.getSettingsItem('lang') : (navigator.language || navigator.userLanguage).split('-')[0]; - state.viewStates = {}; - state.isLoggedIn = false; - } + state.language = app.getSettingsItem('lang') ? app.getSettingsItem('lang') : (navigator.language || navigator.userLanguage).split('-')[0]; + state.viewStates = {}; + state.isLoggedIn = false; + state.i18n = new I18n(state); // Global I18n class passed to all views } \ No newline at end of file diff --git a/app/appUtilities.js b/app/appUtilities.js index c134332..0739369 100644 --- a/app/appUtilities.js +++ b/app/appUtilities.js @@ -19,14 +19,4 @@ export const appUtilities = (app) => { savedSettings[settingsKey] = value; return window.localStorage.setItem('settings', JSON.stringify(savedSettings)); } - app.getSessionState = () => { - let sessionState = window.sessionStorage.getItem('sessionState'); - if (sessionState) { - return JSON.parse(sessionState); - } - return null; - } - app.setSessionState = () => { - return window.sessionStorage.setItem('sessionState', JSON.stringify(app.state)); - } } \ No newline at end of file diff --git a/app/views/global.js b/app/views/global.js index 4ea9e2c..6ba6a4e 100644 --- a/app/views/global.js +++ b/app/views/global.js @@ -2,7 +2,8 @@ import html from 'choo/html'; import headerImage from '../../dev/images/header.png'; -export const globalView = (state, emit, i18n, view) => { +export const globalView = (state, emit, view) => { + const { i18n } = state; // Create a wrapper for view content that includes global header/footer return html`