Changeset View
Changeset View
Standalone View
Standalone View
native/redux/redux-setup.js
// @flow | // @flow | ||||
import { AppState as NativeAppState, Platform, Alert } from 'react-native'; | import { AppState as NativeAppState, Platform, Alert } from 'react-native'; | ||||
import ExitApp from 'react-native-exit-app'; | import ExitApp from 'react-native-exit-app'; | ||||
import Orientation from 'react-native-orientation-locker'; | import Orientation from 'react-native-orientation-locker'; | ||||
import { createStore, applyMiddleware, type Store, compose } from 'redux'; | import { createStore, applyMiddleware, type Store, compose } from 'redux'; | ||||
import { persistStore, persistReducer } from 'redux-persist'; | import { persistStore, persistReducer } from 'redux-persist'; | ||||
import thunk from 'redux-thunk'; | import thunk from 'redux-thunk'; | ||||
import { setClientDBStoreActionType } from 'lib/actions/client-db-store-actions'; | |||||
import { setDeviceTokenActionTypes } from 'lib/actions/device-actions'; | import { setDeviceTokenActionTypes } from 'lib/actions/device-actions'; | ||||
import { | import { | ||||
logOutActionTypes, | logOutActionTypes, | ||||
deleteAccountActionTypes, | deleteAccountActionTypes, | ||||
logInActionTypes, | logInActionTypes, | ||||
} from 'lib/actions/user-actions'; | } from 'lib/actions/user-actions'; | ||||
import baseReducer from 'lib/reducers/master-reducer'; | import baseReducer from 'lib/reducers/master-reducer'; | ||||
import { processThreadStoreOperations } from 'lib/reducers/thread-reducer'; | import { processThreadStoreOperations } from 'lib/reducers/thread-reducer'; | ||||
▲ Show 20 Lines • Show All 329 Lines • ▼ Show 20 Lines | if (action.type === setNewSessionActionType) { | ||||
} | } | ||||
} | } | ||||
if (action.type === setStoreLoadedActionType) { | if (action.type === setStoreLoadedActionType) { | ||||
return { | return { | ||||
...state, | ...state, | ||||
storeLoaded: true, | storeLoaded: true, | ||||
}; | }; | ||||
} | } | ||||
if (action.type === setClientDBStoreActionType) { | |||||
state = { | |||||
...state, | |||||
storeLoaded: true, | |||||
}; | |||||
const currentLoggedInUserID = state.currentUserInfo?.anonymous | |||||
? undefined | |||||
: state.currentUserInfo?.id; | |||||
const actionCurrentLoggedInUserID = action.payload.currentUserID; | |||||
if ( | |||||
!currentLoggedInUserID || | |||||
!actionCurrentLoggedInUserID || | |||||
actionCurrentLoggedInUserID !== currentLoggedInUserID | |||||
) { | |||||
// If user is logged out now, was logged out at the time action was | |||||
// dispatched or their ID changed between action dispatch and a | |||||
// call to reducer we ignore the SQLite data since it is not valid | |||||
return state; | |||||
} | |||||
} | |||||
const baseReducerResult = baseReducer(state, (action: BaseAction)); | const baseReducerResult = baseReducer(state, (action: BaseAction)); | ||||
state = baseReducerResult.state; | state = baseReducerResult.state; | ||||
const { storeOperations } = baseReducerResult; | const { storeOperations } = baseReducerResult; | ||||
const { | const { | ||||
draftStoreOperations, | draftStoreOperations, | ||||
threadStoreOperations, | threadStoreOperations, | ||||
▲ Show 20 Lines • Show All 185 Lines • Show Last 20 Lines |