Add dev-only button to clear storage (#1965)

* Add dev-only button to clear storage

* Add legacy storage clearing too

* Use try/catch
This commit is contained in:
Eric Bailey 2023-11-21 10:16:22 -06:00 committed by GitHub
parent 3a21c02b8a
commit 71b59021b9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 54 additions and 0 deletions

View file

@ -64,6 +64,8 @@ import {
import {useProfileQuery} from '#/state/queries/profile'
import {useClearPreferencesMutation} from '#/state/queries/preferences'
import {useInviteCodesQuery} from '#/state/queries/invites'
import {clear as clearStorage} from '#/state/persisted/store'
import {clearLegacyStorage} from '#/state/persisted/legacy'
// TEMPORARY (APP-700)
// remove after backend testing finishes
@ -266,6 +268,15 @@ export const SettingsScreen = withAuthRequired(function Settings({}: Props) {
Linking.openURL(STATUS_PAGE_URL)
}, [])
const clearAllStorage = React.useCallback(async () => {
await clearStorage()
Toast.show(`Storage cleared, you need to restart the app now.`)
}, [])
const clearAllLegacyStorage = React.useCallback(async () => {
await clearLegacyStorage()
Toast.show(`Legacy storage cleared, you need to restart the app now.`)
}, [])
return (
<View style={[s.hContentRegion]} testID="settingsScreen">
<ViewHeader title={_(msg`Settings`)} />
@ -671,6 +682,28 @@ export const SettingsScreen = withAuthRequired(function Settings({}: Props) {
<Trans>Reset onboarding state</Trans>
</Text>
</TouchableOpacity>
<TouchableOpacity
style={[pal.view, styles.linkCardNoIcon]}
onPress={clearAllLegacyStorage}
accessibilityRole="button"
accessibilityHint="Clear all legacy storage data"
accessibilityLabel={_(msg`Clear all legacy storage data`)}>
<Text type="lg" style={pal.text}>
<Trans>
Clear all legacy storage data (restart after this)
</Trans>
</Text>
</TouchableOpacity>
<TouchableOpacity
style={[pal.view, styles.linkCardNoIcon]}
onPress={clearAllStorage}
accessibilityRole="button"
accessibilityHint="Clear all storage data"
accessibilityLabel={_(msg`Clear all storage data`)}>
<Text type="lg" style={pal.text}>
<Trans>Clear all storage data (restart after this)</Trans>
</Text>
</TouchableOpacity>
</>
) : null}
<View style={[styles.footer]}>