Add dev-only button to clear storage (#1965)
* Add dev-only button to clear storage * Add legacy storage clearing too * Use try/catchzio/stable
parent
3a21c02b8a
commit
71b59021b9
|
@ -130,6 +130,8 @@ export async function migrate() {
|
||||||
const newData = transform(legacyData)
|
const newData = transform(legacyData)
|
||||||
await write(newData)
|
await write(newData)
|
||||||
logger.debug('persisted state: migrated legacy storage')
|
logger.debug('persisted state: migrated legacy storage')
|
||||||
|
} else {
|
||||||
|
logger.debug('persisted state: no migration needed')
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
logger.error('persisted state: error migrating legacy storage', {
|
logger.error('persisted state: error migrating legacy storage', {
|
||||||
|
@ -137,3 +139,13 @@ export async function migrate() {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function clearLegacyStorage() {
|
||||||
|
try {
|
||||||
|
await AsyncStorage.removeItem(DEPRECATED_ROOT_STATE_STORAGE_KEY)
|
||||||
|
} catch (e: any) {
|
||||||
|
logger.error(`persisted legacy store: failed to clear`, {
|
||||||
|
error: e.toString(),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import AsyncStorage from '@react-native-async-storage/async-storage'
|
import AsyncStorage from '@react-native-async-storage/async-storage'
|
||||||
|
|
||||||
import {Schema, schema} from '#/state/persisted/schema'
|
import {Schema, schema} from '#/state/persisted/schema'
|
||||||
|
import {logger} from '#/logger'
|
||||||
|
|
||||||
const BSKY_STORAGE = 'BSKY_STORAGE'
|
const BSKY_STORAGE = 'BSKY_STORAGE'
|
||||||
|
|
||||||
|
@ -16,3 +17,11 @@ export async function read(): Promise<Schema | undefined> {
|
||||||
return objData
|
return objData
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function clear() {
|
||||||
|
try {
|
||||||
|
await AsyncStorage.removeItem(BSKY_STORAGE)
|
||||||
|
} catch (e: any) {
|
||||||
|
logger.error(`persisted store: failed to clear`, {error: e.toString()})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -64,6 +64,8 @@ import {
|
||||||
import {useProfileQuery} from '#/state/queries/profile'
|
import {useProfileQuery} from '#/state/queries/profile'
|
||||||
import {useClearPreferencesMutation} from '#/state/queries/preferences'
|
import {useClearPreferencesMutation} from '#/state/queries/preferences'
|
||||||
import {useInviteCodesQuery} from '#/state/queries/invites'
|
import {useInviteCodesQuery} from '#/state/queries/invites'
|
||||||
|
import {clear as clearStorage} from '#/state/persisted/store'
|
||||||
|
import {clearLegacyStorage} from '#/state/persisted/legacy'
|
||||||
|
|
||||||
// TEMPORARY (APP-700)
|
// TEMPORARY (APP-700)
|
||||||
// remove after backend testing finishes
|
// remove after backend testing finishes
|
||||||
|
@ -266,6 +268,15 @@ export const SettingsScreen = withAuthRequired(function Settings({}: Props) {
|
||||||
Linking.openURL(STATUS_PAGE_URL)
|
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 (
|
return (
|
||||||
<View style={[s.hContentRegion]} testID="settingsScreen">
|
<View style={[s.hContentRegion]} testID="settingsScreen">
|
||||||
<ViewHeader title={_(msg`Settings`)} />
|
<ViewHeader title={_(msg`Settings`)} />
|
||||||
|
@ -671,6 +682,28 @@ export const SettingsScreen = withAuthRequired(function Settings({}: Props) {
|
||||||
<Trans>Reset onboarding state</Trans>
|
<Trans>Reset onboarding state</Trans>
|
||||||
</Text>
|
</Text>
|
||||||
</TouchableOpacity>
|
</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}
|
) : null}
|
||||||
<View style={[styles.footer]}>
|
<View style={[styles.footer]}>
|
||||||
|
|
Loading…
Reference in New Issue