Changeset View
Changeset View
Standalone View
Standalone View
web/root.js
Show All 20 Lines | |||||
import Loading from './loading.react.js'; | import Loading from './loading.react.js'; | ||||
import { createAsyncMigrate } from './redux/create-async-migrate.js'; | import { createAsyncMigrate } from './redux/create-async-migrate.js'; | ||||
import { reducer } from './redux/redux-setup.js'; | import { reducer } from './redux/redux-setup.js'; | ||||
import type { AppState, Action } from './redux/redux-setup.js'; | import type { AppState, Action } from './redux/redux-setup.js'; | ||||
import history from './router-history.js'; | import history from './router-history.js'; | ||||
import Socket from './socket.react.js'; | import Socket from './socket.react.js'; | ||||
import { workerRequestMessageTypes } from './types/worker-types.js'; | import { workerRequestMessageTypes } from './types/worker-types.js'; | ||||
const initiallyLoggedInUserID = preloadedState.currentUserInfo?.anonymous | |||||
? undefined | |||||
: preloadedState.currentUserInfo?.id; | |||||
const isDatabaseSupported = isSQLiteSupported(initiallyLoggedInUserID); | |||||
const migrations = { | const migrations = { | ||||
[1]: async state => { | [1]: async state => { | ||||
const { | const { | ||||
primaryIdentityPublicKey, | primaryIdentityPublicKey, | ||||
...stateWithoutPrimaryIdentityPublicKey | ...stateWithoutPrimaryIdentityPublicKey | ||||
} = state; | } = state; | ||||
return { | return { | ||||
...stateWithoutPrimaryIdentityPublicKey, | ...stateWithoutPrimaryIdentityPublicKey, | ||||
cryptoStore: { | cryptoStore: { | ||||
primaryAccount: null, | primaryAccount: null, | ||||
primaryIdentityKeys: null, | primaryIdentityKeys: null, | ||||
notificationAccount: null, | notificationAccount: null, | ||||
notificationIdentityKeys: null, | notificationIdentityKeys: null, | ||||
}, | }, | ||||
}; | }; | ||||
}, | }, | ||||
[2]: async state => { | [2]: async state => { | ||||
const currentLoggedInUserID = preloadedState.currentUserInfo?.anonymous | if (!isDatabaseSupported) { | ||||
? undefined | |||||
: preloadedState.currentUserInfo?.id; | |||||
const isSupported = isSQLiteSupported(currentLoggedInUserID); | |||||
if (!isSupported) { | |||||
return state; | return state; | ||||
} | } | ||||
const { drafts } = state.draftStore; | const { drafts } = state.draftStore; | ||||
const draftStoreOperations = []; | const draftStoreOperations = []; | ||||
for (const key in drafts) { | for (const key in drafts) { | ||||
const text = drafts[key]; | const text = drafts[key]; | ||||
draftStoreOperations.push({ | draftStoreOperations.push({ | ||||
type: 'update', | type: 'update', | ||||
payload: { key, text }, | payload: { key, text }, | ||||
}); | }); | ||||
} | } | ||||
await databaseModule.schedule({ | await databaseModule.schedule({ | ||||
type: workerRequestMessageTypes.PROCESS_STORE_OPERATIONS, | type: workerRequestMessageTypes.PROCESS_STORE_OPERATIONS, | ||||
storeOperations: { draftStoreOperations }, | storeOperations: { draftStoreOperations }, | ||||
}); | }); | ||||
return state; | return state; | ||||
}, | }, | ||||
}; | }; | ||||
const persistConfig = { | const persistWhitelist = [ | ||||
key: 'root', | |||||
storage, | |||||
whitelist: [ | |||||
'enabledApps', | 'enabledApps', | ||||
'deviceID', | 'deviceID', | ||||
'draftStore', | |||||
'cryptoStore', | 'cryptoStore', | ||||
'notifPermissionAlertInfo', | 'notifPermissionAlertInfo', | ||||
'commServicesAccessToken', | 'commServicesAccessToken', | ||||
], | ]; | ||||
const persistConfig = { | |||||
key: 'root', | |||||
storage, | |||||
whitelist: isDatabaseSupported | |||||
? persistWhitelist | |||||
: [...persistWhitelist, 'draftStore'], | |||||
migrate: (createAsyncMigrate(migrations, { debug: isDev }): any), | migrate: (createAsyncMigrate(migrations, { debug: isDev }): any), | ||||
version: 2, | version: 2, | ||||
}; | }; | ||||
declare var preloadedState: AppState; | declare var preloadedState: AppState; | ||||
const persistedReducer = persistReducer(persistConfig, reducer); | const persistedReducer = persistReducer(persistConfig, reducer); | ||||
const store: Store<AppState, Action> = createStore( | const store: Store<AppState, Action> = createStore( | ||||
persistedReducer, | persistedReducer, | ||||
Show All 20 Lines |