diff --git a/web/root.js b/web/root.js --- a/web/root.js +++ b/web/root.js @@ -14,7 +14,9 @@ import { isDev } from 'lib/utils/dev-utils.js'; import App from './app.react.js'; +import { databaseModule } from './database/database-module-provider.js'; import { SQLiteDataHandler } from './database/sqlite-data-handler.js'; +import { isSQLiteSupported } from './database/utils/db-utils.js'; import ErrorBoundary from './error-boundary.react.js'; import Loading from './loading.react.js'; import { creatAsyncMigrate } from './redux/create-async-migrate.js'; @@ -22,6 +24,7 @@ import type { AppState, Action } from './redux/redux-setup.js'; import history from './router-history.js'; import Socket from './socket.react.js'; +import { workerRequestMessageTypes } from './types/worker-types.js'; const migrations = { [1]: async state => { @@ -39,6 +42,32 @@ }, }; }, + [2]: async state => { + const currentLoggedInUserID = preloadedState.currentUserInfo?.anonymous + ? undefined + : preloadedState.currentUserInfo?.id; + const isSupported = isSQLiteSupported(currentLoggedInUserID); + if (!isSupported) { + return state; + } + + const { drafts } = state.draftStore; + const draftStoreOperations = []; + for (const key in drafts) { + const text = drafts[key]; + draftStoreOperations.push({ + type: 'update', + payload: { key, text }, + }); + } + + await databaseModule.schedule({ + type: workerRequestMessageTypes.PROCESS_STORE_OPERATIONS, + storeOperations: { draftStoreOperations }, + }); + + return state; + }, }; const persistConfig = { key: 'root', @@ -52,7 +81,7 @@ 'commServicesAccessToken', ], migrate: (creatAsyncMigrate(migrations, { debug: isDev }): any), - version: 1, + version: 2, }; declare var preloadedState: AppState;