diff --git a/src/common/reducers/auth/index.js b/src/common/reducers/auth/index.js index cbca1161..8ccc0207 100644 --- a/src/common/reducers/auth/index.js +++ b/src/common/reducers/auth/index.js @@ -7,7 +7,7 @@ import { LOGOUT_AUTH_SUCCESS } from 'actions/auth' import {APPLICATION_INIT} from 'actions/common' -// + import type { LOGIN_AUTH_FAIL_TYPE, LOGIN_AUTH_PENDING_TYPE, @@ -17,8 +17,6 @@ import type { import type {APPLICATION_INIT_TYPE} from 'actions/common' export type State = { - isLoading: boolean, - isLoaded: boolean, isLoggedIn: boolean, errors: Object } @@ -31,8 +29,6 @@ type Action = | LOGOUT_AUTH_SUCCESS_TYPE export const initialState: State = { - isLoading: false, - isLoaded: false, isLoggedIn: hasLocalToken(), errors: {} } @@ -44,8 +40,6 @@ export function auth (state: State = initialState, action: Action): State { case LOGOUT_AUTH_SUCCESS: { return { ...state, - isLoading: false, - isLoaded: true, isLoggedIn: false, errors: {} } @@ -54,8 +48,6 @@ export function auth (state: State = initialState, action: Action): State { const {errors} = action.payload return { ...state, - isLoading: false, - isLoaded: true, isLoggedIn: false, errors } @@ -63,16 +55,12 @@ export function auth (state: State = initialState, action: Action): State { case LOGIN_AUTH_SUCCESS: { return { ...state, - isLoading: false, - isLoaded: true, isLoggedIn: true } } case LOGIN_AUTH_PENDING: { return { - ...state, - isLoading: true, - isLoaded: false + ...state } } default: diff --git a/src/common/reducers/index.js b/src/common/reducers/index.js index 83898eb2..8175fe4b 100644 --- a/src/common/reducers/index.js +++ b/src/common/reducers/index.js @@ -1,31 +1,27 @@ // @flow import {combineReducers} from 'redux' import {routerReducer} from 'react-router-redux' -import {getMetaRoutes} from 'routing' +import {reducer as reduxFormReducer} from 'redux-form' import type {State as AuthState} from 'reducers/auth' import type {State as LayoutState} from 'reducers/layout' import type {State as EntitiesLinksState} from 'reducers/links' import {layout} from './layout' -import {metaRouting} from './metarouter' import {links} from './links' import {auth} from './auth' // Root reducer export default combineReducers({ layout, - me: combineReducers({auth}), + auth, entities: combineReducers({ links }), routing: routerReducer, - // NOTE: metaRouting is an addon for react-router-redux - // metaRouting allows you storing meta info (e.g. `meta` field) about the current route - // metaRouting is avaliable as package: `react-router-redux-meta` - metaRouting: metaRouting(getMetaRoutes()) + form: reduxFormReducer }) -export type GlobalState = {layout: LayoutState} & {me: {auth: AuthState}} & { +export type GlobalState = {layout: LayoutState} & {auth: AuthState} & { entities: {links: EntitiesLinksState} } diff --git a/src/common/reducers/layout/index.js b/src/common/reducers/layout/index.js index 683641b9..c0419956 100644 --- a/src/common/reducers/layout/index.js +++ b/src/common/reducers/layout/index.js @@ -1,61 +1,44 @@ // @flow import { - UI_OPEN_SIDEBAR, - UI_CLOSE_SIDEBAR, + UI_TOGGLE_SIDEBAR, UI_WINDOW_RESIZE } from 'actions/layout' import {LOCATION_CHANGE} from 'actions/common' -// import type {LOCATION_CHANGE_TYPE} from 'actions/common' import type { - UI_OPEN_SIDEBAR_TYPE, - UI_CLOSE_SIDEBAR_TYPE, + UI_TOGGLE_SIDEBAR_TYPE, UI_WINDOW_RESIZE_TYPE } from 'actions/layout' export type State = { sidebarOpened: boolean, - isMobile: boolean, - isMobileXS: boolean, - isMobileSM: boolean + innerWidth?: number } type Action = - | UI_OPEN_SIDEBAR_TYPE - | UI_CLOSE_SIDEBAR_TYPE + | UI_TOGGLE_SIDEBAR_TYPE | UI_WINDOW_RESIZE_TYPE | LOCATION_CHANGE_TYPE export const initialState: State = { - sidebarOpened: false, - isMobile: false, - isMobileXS: false, - isMobileSM: false + sidebarOpened: false } export function layout (state: State = initialState, action: Action): State { - const computeMobileStatuses = (innerWidth: number) => { - const isMobile: boolean = innerWidth < 1025 // 1024px - is the main breakpoint in ui - const isMobileXS: boolean = innerWidth < 481 - const isMobileSM: boolean = innerWidth > 480 && innerWidth < 767 - return {isMobileSM, isMobileXS, isMobile} - } switch (action.type) { case UI_WINDOW_RESIZE: { const {innerWidth} = action.payload - const mobileStates = computeMobileStatuses(innerWidth) return { ...state, - ...mobileStates + innerWidth } } - case UI_OPEN_SIDEBAR: + case UI_TOGGLE_SIDEBAR: return { ...state, - sidebarOpened: true + sidebarOpened: !state.sidebarOpened } case LOCATION_CHANGE: - case UI_CLOSE_SIDEBAR: return { ...state, sidebarOpened: false diff --git a/src/common/reducers/links/index.js b/src/common/reducers/links/index.js index e242f165..e389e388 100644 --- a/src/common/reducers/links/index.js +++ b/src/common/reducers/links/index.js @@ -10,8 +10,7 @@ import type {GET_LINKS_SUCCESS_TYPE, GET_LINKS_FAIL_TYPE, GET_LINKS_PENDING_TYPE export type State = { entities: Array, errors: Object, - isLoading: boolean, - isLoaded: boolean + fetchStatus: 'none' | 'loaded' | 'loading' } type Action = @@ -22,41 +21,35 @@ type Action = export const initialState: State = { entities: [], errors: {}, - isLoading: false, - isLoaded: false, - count: 0 + fetchStatus: 'none' } export function links (state: State = initialState, action: Action): State { switch (action.type) { case GET_LINKS_PENDING: { + console.log(action) return { ...state, errors: {}, - isLoaded: false, - isLoading: true + fetchStatus: 'loading' } } case GET_LINKS_SUCCESS: { + console.log(action) const entities = action.payload - const count = entities.length return { ...state, - isLoaded: true, - isLoading: false, entities, - count + fetchStatus: 'loaded' } } case GET_LINKS_FAIL: { - const {errors} = action.payload + console.log(action) + const errors = action.payload return { ...state, errors, - isLoaded: true, - isLoading: false, - entities: [], - count: 0 + fetchStatus: 'loaded' } } default: diff --git a/src/common/reducers/metarouter/index.js b/src/common/reducers/metarouter/index.js deleted file mode 100644 index b5ebba33..00000000 --- a/src/common/reducers/metarouter/index.js +++ /dev/null @@ -1,29 +0,0 @@ -/** @flow - @file Check `src/common/reducers/index.js` for more info about metaRouting -*/ -import {matchPath} from 'react-router' -import {LOCATION_CHANGE} from 'react-router-redux' -import type {RouteItem} from 'types' - -type State = { - currentRoute: RouteItem | Object -} - -export const initialState = { - currentRoute: {} -} - -export const metaRouting = (allRoutes: RouteItem[]) => (state: State = initialState, action) => { - switch (action.type) { - case LOCATION_CHANGE: { - const {pathname} = action.payload - const currentRoute = - allRoutes.filter(a => matchPath(pathname, a))[0] || {} - return { - currentRoute - } - } - default: - return state - } -}