From a8ed7410a433a06ce545ed5bef909914f296be5f Mon Sep 17 00:00:00 2001 From: Paul Kaplan Date: Wed, 23 Jun 2021 20:57:30 -0400 Subject: [PATCH] Separate studio reducers and initial state into a helper --- src/views/studio/studio-redux.js | 37 ++++++++++++++++++++++++++++++++ src/views/studio/studio.jsx | 36 ++++--------------------------- 2 files changed, 41 insertions(+), 32 deletions(-) create mode 100644 src/views/studio/studio-redux.js diff --git a/src/views/studio/studio-redux.js b/src/views/studio/studio-redux.js new file mode 100644 index 000000000..9cfaf6ee0 --- /dev/null +++ b/src/views/studio/studio-redux.js @@ -0,0 +1,37 @@ +import { + projects, + curators, + managers, + activity, + userProjects +} from './lib/redux-modules'; + +const {getInitialState, studioReducer} = require('../../redux/studio'); +const {studioReportReducer} = require('../../redux/studio-report'); +const {commentsReducer} = require('../../redux/comments'); +const {studioMutationsReducer} = require('../../redux/studio-mutations'); + + +const reducers = { + [projects.key]: projects.reducer, + [curators.key]: curators.reducer, + [managers.key]: managers.reducer, + [activity.key]: activity.reducer, + [userProjects.key]: userProjects.reducer, + comments: commentsReducer, + studio: studioReducer, + studioMutations: studioMutationsReducer, + studioReport: studioReportReducer +}; + +const initialState = { + studio: { + ...getInitialState(), + // Include the studio id in the initial state to allow us + // to stop passing around the studio id in components + // when it is only needed for data fetching, not for rendering. + id: window.location.pathname.split('/')[2] + } +}; + +export {reducers, initialState}; diff --git a/src/views/studio/studio.jsx b/src/views/studio/studio.jsx index a88871e8c..51054bbc5 100644 --- a/src/views/studio/studio.jsx +++ b/src/views/studio/studio.jsx @@ -27,18 +27,8 @@ import StudioMeta from './studio-meta.jsx'; import StudioAdminPanel from './studio-admin-panel.jsx'; import StudioDeleted from './studio-deleted.jsx'; -import { - projects, - curators, - managers, - activity, - userProjects -} from './lib/redux-modules'; - -const {getInitialState, studioReducer, selectStudioLoadFailed, getInfo} = require('../../redux/studio'); -const {studioReportReducer} = require('../../redux/studio-report'); -const {commentsReducer} = require('../../redux/comments'); -const {studioMutationsReducer} = require('../../redux/studio-mutations'); +import {reducers, initialState} from './studio-redux.js'; +import {selectStudioLoadFailed, getInfo} from '../../redux/studio'; import './studio.scss'; import {selectIsAdmin, selectMuteStatus} from '../../redux/session.js'; @@ -140,24 +130,6 @@ render( , document.getElementById('app'), - { - [projects.key]: projects.reducer, - [curators.key]: curators.reducer, - [managers.key]: managers.reducer, - [activity.key]: activity.reducer, - [userProjects.key]: userProjects.reducer, - comments: commentsReducer, - studio: studioReducer, - studioMutations: studioMutationsReducer, - studioReport: studioReportReducer - }, - { - studio: { - ...getInitialState(), - // Include the studio id in the initial state to allow us - // to stop passing around the studio id in components - // when it is only needed for data fetching, not for rendering. - id: window.location.pathname.split('/')[2] - } - } + reducers, + initialState );