add reset button for db

This commit is contained in:
austinried 2021-06-28 20:50:13 +09:00
parent ef69e9d517
commit f9f016b932
2 changed files with 31 additions and 2 deletions

View File

@ -5,11 +5,23 @@ import React from 'react';
import { Button, Text, View } from 'react-native'; import { Button, Text, View } from 'react-native';
import { v4 as uuidv4 } from 'uuid'; import { v4 as uuidv4 } from 'uuid';
import { appSettingsAtom } from '../state/settings'; import { appSettingsAtom } from '../state/settings';
import { getAllKeys, multiRemove } from '../storage/asyncstorage';
import text from '../styles/text';
const TestControls = () => { const TestControls = () => {
const navigation = useNavigation(); const navigation = useNavigation();
const removeAllKeys = async () => {
const allKeys = await getAllKeys();
await multiRemove(allKeys);
}
return ( return (
<View> <View>
<Button
title='Remove all keys'
onPress={removeAllKeys}
/>
<Button <Button
title='Now Playing' title='Now Playing'
onPress={() => navigation.navigate('Now Playing')} onPress={() => navigation.navigate('Now Playing')}
@ -52,8 +64,8 @@ const ServerSettingsView = () => {
/> />
{appSettings.servers.map(s => ( {appSettings.servers.map(s => (
<View key={s.id}> <View key={s.id}>
<Text>{s.address}</Text> <Text style={text.paragraph}>{s.address}</Text>
<Text>{s.username}</Text> <Text style={text.paragraph}>{s.username}</Text>
</View> </View>
))} ))}
</View> </View>

View File

@ -35,3 +35,20 @@ export async function multiSet(items: string[][]): Promise<void> {
console.error(`multiSet error`, e); console.error(`multiSet error`, e);
} }
} }
export async function getAllKeys(): Promise<string[]> {
try {
return await AsyncStorage.getAllKeys();
} catch (e) {
console.error(`getAllKeys error`, e);
return [];
}
}
export async function multiRemove(keys: string[]): Promise<void> {
try {
await AsyncStorage.multiRemove(keys);
} catch (e) {
console.error(`multiRemove error`, e);
}
}