From f9f016b9326bcdd49b6e7e6ae597ef6cf720f9d2 Mon Sep 17 00:00:00 2001
From: austinried <4966622+austinried@users.noreply.github.com>
Date: Mon, 28 Jun 2021 20:50:13 +0900
Subject: [PATCH] add reset button for db
---
src/components/Settings.tsx | 16 ++++++++++++++--
src/storage/asyncstorage.ts | 17 +++++++++++++++++
2 files changed, 31 insertions(+), 2 deletions(-)
diff --git a/src/components/Settings.tsx b/src/components/Settings.tsx
index 6d4248b..cb39dc7 100644
--- a/src/components/Settings.tsx
+++ b/src/components/Settings.tsx
@@ -5,11 +5,23 @@ import React from 'react';
import { Button, Text, View } from 'react-native';
import { v4 as uuidv4 } from 'uuid';
import { appSettingsAtom } from '../state/settings';
+import { getAllKeys, multiRemove } from '../storage/asyncstorage';
+import text from '../styles/text';
const TestControls = () => {
const navigation = useNavigation();
+
+ const removeAllKeys = async () => {
+ const allKeys = await getAllKeys();
+ await multiRemove(allKeys);
+ }
+
return (
+
diff --git a/src/storage/asyncstorage.ts b/src/storage/asyncstorage.ts
index d138f02..eb98c66 100644
--- a/src/storage/asyncstorage.ts
+++ b/src/storage/asyncstorage.ts
@@ -35,3 +35,20 @@ export async function multiSet(items: string[][]): Promise {
console.error(`multiSet error`, e);
}
}
+
+export async function getAllKeys(): Promise {
+ try {
+ return await AsyncStorage.getAllKeys();
+ } catch (e) {
+ console.error(`getAllKeys error`, e);
+ return [];
+ }
+}
+
+export async function multiRemove(keys: string[]): Promise {
+ try {
+ await AsyncStorage.multiRemove(keys);
+ } catch (e) {
+ console.error(`multiRemove error`, e);
+ }
+}