Add legacy storage clearing too

This commit is contained in:
Eric Bailey
2023-11-20 16:06:14 -06:00
parent bd061f983e
commit cf73b8fe4d
2 changed files with 29 additions and 4 deletions
+8
View File
@@ -128,6 +128,8 @@ export async function migrate() {
const newData = transform(legacyData)
await write(newData)
logger.debug('persisted state: migrated legacy storage')
} else {
logger.debug('persisted state: no migration needed')
}
} catch (e) {
logger.error('persisted state: error migrating legacy storage', {
@@ -135,3 +137,9 @@ export async function migrate() {
})
}
}
export async function clearLegacyStorage() {
await AsyncStorage.removeItem(DEPRECATED_ROOT_STATE_STORAGE_KEY, e => {
if (e) console.error(e)
})
}
+21 -4
View File
@@ -64,7 +64,8 @@ import {
import {useProfileQuery} from '#/state/queries/profile'
import {useClearPreferencesMutation} from '#/state/queries/preferences'
import {useInviteCodesQuery} from '#/state/queries/invites'
import {clear as clearPersistentData} from '#/state/persisted/store'
import {clear as clearStorage} from '#/state/persisted/store'
import {clearLegacyStorage} from '#/state/persisted/legacy'
// TEMPORARY (APP-700)
// remove after backend testing finishes
@@ -267,10 +268,14 @@ export const SettingsScreen = withAuthRequired(function Settings({}: Props) {
Linking.openURL(STATUS_PAGE_URL)
}, [])
const clearAllPersistedData = React.useCallback(async () => {
await clearPersistentData()
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">
@@ -679,7 +684,19 @@ export const SettingsScreen = withAuthRequired(function Settings({}: Props) {
</TouchableOpacity>
<TouchableOpacity
style={[pal.view, styles.linkCardNoIcon]}
onPress={clearAllPersistedData}
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`)}>