Changeset View
Changeset View
Standalone View
Standalone View
web/database/sqlite-data-handler.js
// @flow | // @flow | ||||
import * as React from 'react'; | import * as React from 'react'; | ||||
import { useDispatch } from 'react-redux'; | import { useDispatch } from 'react-redux'; | ||||
import { setClientDBStoreActionType } from 'lib/actions/client-db-store-actions.js'; | import { setClientDBStoreActionType } from 'lib/actions/client-db-store-actions.js'; | ||||
import { convertClientDBReportToClientReportCreationRequest } from 'lib/ops/report-store-ops.js'; | |||||
import { databaseModule } from './database-module-provider.js'; | import { databaseModule } from './database-module-provider.js'; | ||||
import { useSelector } from '../redux/redux-utils.js'; | import { useSelector } from '../redux/redux-utils.js'; | ||||
import { workerRequestMessageTypes } from '../types/worker-types.js'; | import { workerRequestMessageTypes } from '../types/worker-types.js'; | ||||
function SQLiteDataHandler(): React.Node { | function SQLiteDataHandler(): React.Node { | ||||
const dispatch = useDispatch(); | const dispatch = useDispatch(); | ||||
const rehydrateConcluded = useSelector( | const rehydrateConcluded = useSelector( | ||||
▲ Show 20 Lines • Show All 45 Lines • ▼ Show 20 Lines | (async () => { | ||||
await handleSensitiveData(); | await handleSensitiveData(); | ||||
if (!currentLoggedInUserID) { | if (!currentLoggedInUserID) { | ||||
return; | return; | ||||
} | } | ||||
const data = await databaseModule.schedule({ | const data = await databaseModule.schedule({ | ||||
type: workerRequestMessageTypes.GET_CLIENT_STORE, | type: workerRequestMessageTypes.GET_CLIENT_STORE, | ||||
}); | }); | ||||
if (!data?.store?.drafts) { | if (!data?.store?.drafts && !data?.store?.reports) { | ||||
return; | return; | ||||
} | } | ||||
const reports = convertClientDBReportToClientReportCreationRequest( | |||||
data.store.reports, | |||||
); | |||||
dispatch({ | dispatch({ | ||||
type: setClientDBStoreActionType, | type: setClientDBStoreActionType, | ||||
payload: { | payload: { | ||||
drafts: data.store.drafts, | drafts: data.store.drafts, | ||||
reports, | |||||
}, | }, | ||||
}); | }); | ||||
})(); | })(); | ||||
}, [ | }, [ | ||||
currentLoggedInUserID, | currentLoggedInUserID, | ||||
dispatch, | dispatch, | ||||
handleSensitiveData, | handleSensitiveData, | ||||
rehydrateConcluded, | rehydrateConcluded, | ||||
]); | ]); | ||||
return null; | return null; | ||||
} | } | ||||
export { SQLiteDataHandler }; | export { SQLiteDataHandler }; |