diff --git a/openbis_ng_ui/src/js/index.js b/openbis_ng_ui/src/js/index.js index 76ca3e869881ab62b84a55209e59d2da7ae152b1..e46b87c28b14d8f155fed7855c4bd657fdcf438d 100644 --- a/openbis_ng_ui/src/js/index.js +++ b/openbis_ng_ui/src/js/index.js @@ -1,6 +1,7 @@ import 'regenerator-runtime/runtime' import React from 'react' import ReactDOM from 'react-dom' +import store from './store/store.js' import { Provider } from 'react-redux' import { MuiThemeProvider, createMuiTheme } from '@material-ui/core/styles' import DragAndDropProvider from './components/common/dnd/DragAndDropProvider.jsx' @@ -26,8 +27,7 @@ const theme = createMuiTheme({ }) const render = () => { - const App = require('./components/App.jsx').default - const store = require('./store/store.js').default + let App = require('./components/App.jsx').default ReactDOM.render( <Provider store={store}> @@ -44,10 +44,6 @@ const render = () => { /* eslint-disable no-undef */ if (module.hot) { module.hot.accept('./components/App.jsx', () => setTimeout(render)) - module.hot.accept('./store/reducers/reducers.js', () => { - const nextRootReducer = require('./store/reducers/reducers.js').default - store.replaceReducer(nextRootReducer) - }) } render() diff --git a/openbis_ng_ui/src/js/store/actions/app.js b/openbis_ng_ui/src/js/store/actions/app.js index 997e5d1fc003d8281c1cf7cfce9e844d2dcac535..024a21a69d2617948e04175d8e4967d4dbdff323 100644 --- a/openbis_ng_ui/src/js/store/actions/app.js +++ b/openbis_ng_ui/src/js/store/actions/app.js @@ -1,4 +1,5 @@ export const INIT = 'INIT' +export const CLEAR = 'CLEAR' export const LOGIN = 'LOGIN' export const LOGOUT = 'LOGOUT' export const SEARCH = 'SEARCH' @@ -7,6 +8,7 @@ export const SEARCH_CHANGE = 'SEARCH_CHANGE' export const ERROR_CHANGE = 'ERROR_CHANGE' export const ROUTE_CHANGE = 'ROUTE_CHANGE' +export const SET_INITIALIZED = 'SET_INITIALIZED' export const SET_LOADING = 'SET_LOADING' export const SET_SEARCH = 'SET_SEARCH' export const SET_SESSION = 'SET_SESSION' @@ -17,6 +19,10 @@ export const init = () => ({ type: INIT }) +export const clear = () => ({ + type: CLEAR +}) + export const login = (username, password) => ({ type: LOGIN, payload: { @@ -65,6 +71,13 @@ export const routeChange = route => ({ } }) +export const setInitialized = initialized => ({ + type: SET_INITIALIZED, + payload: { + initialized + } +}) + export const setLoading = loading => ({ type: SET_LOADING, payload: { diff --git a/openbis_ng_ui/src/js/store/reducers/reducers.js b/openbis_ng_ui/src/js/store/reducers/reducers.js index a13a279f0c6384177bfe6730665ab5324b2597ac..7c0401110b507bc05437cd6dd6dac55b47f28332 100644 --- a/openbis_ng_ui/src/js/store/reducers/reducers.js +++ b/openbis_ng_ui/src/js/store/reducers/reducers.js @@ -5,12 +5,26 @@ import session from './session/session.js' import route from './route/route.js' export default function root(state = {}, action) { - if (action.type === actions.INIT) { - state = {} + if (action.type === actions.CLEAR) { + state = { + initialized: state.initialized + } } return combineReducers({ + initialized, ui, session, route })(state, action) } + +function initialized(state = false, action) { + switch (action.type) { + case actions.SET_INITIALIZED: { + return action.payload.initialized + } + default: { + return state + } + } +} diff --git a/openbis_ng_ui/src/js/store/reducers/ui/pages/common/page.js b/openbis_ng_ui/src/js/store/reducers/ui/pages/common/page.js index 3b07945d25f4938d93f8523fb743388fac3be5c6..5155ac8f4d403d24a63ba755017054fd554cb412 100644 --- a/openbis_ng_ui/src/js/store/reducers/ui/pages/common/page.js +++ b/openbis_ng_ui/src/js/store/reducers/ui/pages/common/page.js @@ -6,6 +6,7 @@ export * from './browser.js' export function isPageAction(page, action) { return ( action.type === actions.INIT || + action.type === actions.CLEAR || page === (action.payload && action.payload.page) ) } diff --git a/openbis_ng_ui/src/js/store/sagas/app.js b/openbis_ng_ui/src/js/store/sagas/app.js index 328d1306929499241049519a77c0ce5bcdab6dcf..2a9b534f0ab9746fcf4fdfca020486cc97dfa7d9 100644 --- a/openbis_ng_ui/src/js/store/sagas/app.js +++ b/openbis_ng_ui/src/js/store/sagas/app.js @@ -17,14 +17,19 @@ export default function* appSaga() { } function* init() { - try { - yield put(actions.setLoading(true)) - yield call([dto, dto.init]) - yield call([facade, facade.init]) - } catch (e) { - yield put(actions.setError(e)) - } finally { - yield put(actions.setLoading(false)) + let initialized = yield select(selectors.getInitialized) + + if (!initialized) { + try { + yield put(actions.setLoading(true)) + yield call([dto, dto.init]) + yield call([facade, facade.init]) + yield put(actions.setInitialized(true)) + } catch (e) { + yield put(actions.setError(e)) + } finally { + yield put(actions.setLoading(false)) + } } } @@ -62,7 +67,7 @@ function* logout() { try { yield put(actions.setLoading(true)) yield putAndWait(actions.apiRequest({ method: 'logout' })) - yield put(actions.init()) + yield put(actions.clear()) yield put(actions.routeChange('/')) } catch (e) { yield put(actions.setError(e)) diff --git a/openbis_ng_ui/src/js/store/selectors/app.js b/openbis_ng_ui/src/js/store/selectors/app.js index 23cdfafef467958a274b45d2ea9f75aa195d5767..14f732b76d8a105b97dcca5e0e0527a9489aa2d2 100644 --- a/openbis_ng_ui/src/js/store/selectors/app.js +++ b/openbis_ng_ui/src/js/store/selectors/app.js @@ -1,5 +1,9 @@ import routes from '../../common/consts/routes.js' +export const getInitialized = state => { + return state.initialized +} + export const getLoading = state => { return state.ui.loading } diff --git a/openbis_ng_ui/src/js/store/store.js b/openbis_ng_ui/src/js/store/store.js index 91f70997aec01d8245fb794b858bd1033d361d2e..6a452965160042e427d056b6d56b8e173db87a31 100644 --- a/openbis_ng_ui/src/js/store/store.js +++ b/openbis_ng_ui/src/js/store/store.js @@ -8,7 +8,12 @@ import history from './history.js' function createStoreWithMiddleware() { const sagaMiddleware = createSagaMiddleware() const composeEnhancers = - window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose + (window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ && + window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__({ + trace: true, + traceLimit: 25 + })) || + compose let store = createStore( rootReducer, @@ -23,5 +28,13 @@ function createStoreWithMiddleware() { let store = createStoreWithMiddleware() +/* eslint-disable no-undef */ +if (module.hot) { + module.hot.accept('./reducers/reducers.js', () => { + const nextRootReducer = require('./reducers/reducers.js').default + store.replaceReducer(nextRootReducer) + }) +} + export { createStoreWithMiddleware as createStore } export default store diff --git a/openbis_ng_ui/webpack.config.dev.js b/openbis_ng_ui/webpack.config.dev.js index 60ce6f1e15fd492cb5569b6fe9cec3cd401b06ce..a096344971edbe9ce84e5bf960a60d01e8efb180 100644 --- a/openbis_ng_ui/webpack.config.dev.js +++ b/openbis_ng_ui/webpack.config.dev.js @@ -38,9 +38,7 @@ module.exports = { { test: /\.(js|jsx)$/, exclude: /node_modules/, - use: { - loader: 'babel-loader' - } + use: ['react-hot', 'babel-loader'] }, { test: /\.(css)$/,