Bluesky app fork with some witchin' additions 💫 witchsky.app
bluesky fork client

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

* Add dev-only button to clear storage

* Add legacy storage clearing too

* Use try/catch

authored by

Eric Bailey and committed by
GitHub
71b59021 3a21c02b

+54
+12
src/state/persisted/legacy.ts
··· 130 130 const newData = transform(legacyData) 131 131 await write(newData) 132 132 logger.debug('persisted state: migrated legacy storage') 133 + } else { 134 + logger.debug('persisted state: no migration needed') 133 135 } 134 136 } catch (e) { 135 137 logger.error('persisted state: error migrating legacy storage', { ··· 137 139 }) 138 140 } 139 141 } 142 + 143 + export async function clearLegacyStorage() { 144 + try { 145 + await AsyncStorage.removeItem(DEPRECATED_ROOT_STATE_STORAGE_KEY) 146 + } catch (e: any) { 147 + logger.error(`persisted legacy store: failed to clear`, { 148 + error: e.toString(), 149 + }) 150 + } 151 + }
+9
src/state/persisted/store.ts
··· 1 1 import AsyncStorage from '@react-native-async-storage/async-storage' 2 2 3 3 import {Schema, schema} from '#/state/persisted/schema' 4 + import {logger} from '#/logger' 4 5 5 6 const BSKY_STORAGE = 'BSKY_STORAGE' 6 7 ··· 16 17 return objData 17 18 } 18 19 } 20 + 21 + export async function clear() { 22 + try { 23 + await AsyncStorage.removeItem(BSKY_STORAGE) 24 + } catch (e: any) { 25 + logger.error(`persisted store: failed to clear`, {error: e.toString()}) 26 + } 27 + }
+33
src/view/screens/Settings.tsx
··· 64 64 import {useProfileQuery} from '#/state/queries/profile' 65 65 import {useClearPreferencesMutation} from '#/state/queries/preferences' 66 66 import {useInviteCodesQuery} from '#/state/queries/invites' 67 + import {clear as clearStorage} from '#/state/persisted/store' 68 + import {clearLegacyStorage} from '#/state/persisted/legacy' 67 69 68 70 // TEMPORARY (APP-700) 69 71 // remove after backend testing finishes ··· 264 266 265 267 const onPressStatusPage = React.useCallback(() => { 266 268 Linking.openURL(STATUS_PAGE_URL) 269 + }, []) 270 + 271 + const clearAllStorage = React.useCallback(async () => { 272 + await clearStorage() 273 + Toast.show(`Storage cleared, you need to restart the app now.`) 274 + }, []) 275 + const clearAllLegacyStorage = React.useCallback(async () => { 276 + await clearLegacyStorage() 277 + Toast.show(`Legacy storage cleared, you need to restart the app now.`) 267 278 }, []) 268 279 269 280 return ( ··· 669 680 accessibilityLabel={_(msg`Resets the onboarding state`)}> 670 681 <Text type="lg" style={pal.text}> 671 682 <Trans>Reset onboarding state</Trans> 683 + </Text> 684 + </TouchableOpacity> 685 + <TouchableOpacity 686 + style={[pal.view, styles.linkCardNoIcon]} 687 + onPress={clearAllLegacyStorage} 688 + accessibilityRole="button" 689 + accessibilityHint="Clear all legacy storage data" 690 + accessibilityLabel={_(msg`Clear all legacy storage data`)}> 691 + <Text type="lg" style={pal.text}> 692 + <Trans> 693 + Clear all legacy storage data (restart after this) 694 + </Trans> 695 + </Text> 696 + </TouchableOpacity> 697 + <TouchableOpacity 698 + style={[pal.view, styles.linkCardNoIcon]} 699 + onPress={clearAllStorage} 700 + accessibilityRole="button" 701 + accessibilityHint="Clear all storage data" 702 + accessibilityLabel={_(msg`Clear all storage data`)}> 703 + <Text type="lg" style={pal.text}> 704 + <Trans>Clear all storage data (restart after this)</Trans> 672 705 </Text> 673 706 </TouchableOpacity> 674 707 </>