Changeset View
Changeset View
Standalone View
Standalone View
web/database/sqlite-data-handler-web.js
- This file was added.
// @flow | |||||||||||||
import * as React from 'react'; | |||||||||||||
import { isLoggedIn } from 'lib/selectors/user-selectors.js'; | |||||||||||||
import { databaseModule } from './database-module-provider.js'; | |||||||||||||
import { useSelector } from '../redux/redux-utils.js'; | |||||||||||||
import { workerRequestMessageTypes } from '../types/worker-types.js'; | |||||||||||||
function SQLiteDataHandlerWeb(): React.Node { | |||||||||||||
ashoat: Don't think we need the "Web" part here or in the filename | |||||||||||||
const rehydrateConcluded = useSelector( | |||||||||||||
state => !!(state._persist && state._persist.rehydrated), | |||||||||||||
); | |||||||||||||
const currentLoggedInUserID = useSelector(state => | |||||||||||||
state.currentUserInfo?.anonymous ? undefined : state.currentUserInfo?.id, | |||||||||||||
); | |||||||||||||
const loggedIn = useSelector(isLoggedIn); | |||||||||||||
const handleSensitiveData = React.useCallback(async () => { | |||||||||||||
try { | |||||||||||||
const currentUserData = await databaseModule.schedule({ | |||||||||||||
type: workerRequestMessageTypes.GET_CURRENT_USER_ID, | |||||||||||||
}); | |||||||||||||
if ( | |||||||||||||
currentUserData?.userID && | |||||||||||||
currentUserData.userID !== currentLoggedInUserID | |||||||||||||
) { | |||||||||||||
await databaseModule.clearSensitiveData(); | |||||||||||||
} | |||||||||||||
if (currentLoggedInUserID) { | |||||||||||||
await databaseModule.schedule({ | |||||||||||||
type: workerRequestMessageTypes.SET_CURRENT_USER_ID, | |||||||||||||
userID: currentLoggedInUserID, | |||||||||||||
}); | |||||||||||||
} | |||||||||||||
} catch (error) { | |||||||||||||
console.error(error); | |||||||||||||
} | |||||||||||||
}, [currentLoggedInUserID]); | |||||||||||||
React.useEffect(() => { | |||||||||||||
if (!rehydrateConcluded) { | |||||||||||||
return; | |||||||||||||
} | |||||||||||||
if (!loggedIn) { | |||||||||||||
return; | |||||||||||||
} | |||||||||||||
(async () => { | |||||||||||||
await handleSensitiveData(); | |||||||||||||
})(); | |||||||||||||
tomekUnsubmitted Not Done Inline Actions
This is equivalent to just handleSensitiveData() tomek: This is equivalent to just `handleSensitiveData()` | |||||||||||||
}, [handleSensitiveData, loggedIn, rehydrateConcluded]); | |||||||||||||
return null; | |||||||||||||
} | |||||||||||||
export { SQLiteDataHandlerWeb }; |
Don't think we need the "Web" part here or in the filename