From 6b8780c62e867dc9ecc4564b641daf9afe8e20d3 Mon Sep 17 00:00:00 2001 From: Brandon Presley Date: Mon, 11 Jul 2022 11:26:45 +1200 Subject: [PATCH] Add confirm dialog to deleting all data --- BatteryDialog.tsx | 36 ------------------------------------ ConfirmDialog.tsx | 32 ++++++++++++++++++++++++++++++++ HomePage.tsx | 4 ++-- SetsPage.tsx => SetList.tsx | 6 +++--- SettingsPage.tsx | 26 +++++++++++++++++++++++--- 5 files changed, 60 insertions(+), 44 deletions(-) delete mode 100644 BatteryDialog.tsx create mode 100644 ConfirmDialog.tsx rename SetsPage.tsx => SetList.tsx (95%) diff --git a/BatteryDialog.tsx b/BatteryDialog.tsx deleted file mode 100644 index 3972446..0000000 --- a/BatteryDialog.tsx +++ /dev/null @@ -1,36 +0,0 @@ -import React from 'react'; -import {NativeModules, Text} from 'react-native'; -import {Button, Dialog, Portal} from 'react-native-paper'; - -export default function BatteryDialog({ - show, - setShow, -}: { - show: boolean; - setShow: (show: boolean) => void; -}) { - const ok = () => { - NativeModules.AlarmModule.openBatteryOptimizations(); - setShow(false); - }; - - return ( - - setShow(false)}> - Battery optimizations - - - Disable battery optimizations for Massive to use rest timers. - - - Settings {'>'} Battery {'>'} Unrestricted - - - - - - - - - ); -} diff --git a/ConfirmDialog.tsx b/ConfirmDialog.tsx new file mode 100644 index 0000000..a8ccb59 --- /dev/null +++ b/ConfirmDialog.tsx @@ -0,0 +1,32 @@ +import React from 'react'; +import {Text} from 'react-native'; +import {Button, Dialog, Portal} from 'react-native-paper'; + +export default function ConfirmDialog({ + title, + children, + onOk, + show, + setShow, +}: { + title: string; + children: string; + onOk: () => void; + show: boolean; + setShow: (show: boolean) => void; +}) { + return ( + + setShow(false)}> + {title} + + {children} + + + + + + + + ); +} diff --git a/HomePage.tsx b/HomePage.tsx index d738037..4abadbb 100644 --- a/HomePage.tsx +++ b/HomePage.tsx @@ -6,7 +6,7 @@ import {IconButton} from 'react-native-paper'; import {DrawerParamList} from './App'; import EditSet from './EditSet'; import Set from './set'; -import SetsPage from './SetsPage'; +import SetList from './SetList'; const Stack = createStackNavigator(); export type StackParams = { @@ -22,7 +22,7 @@ export default function HomePage() { return ( - + (); const [offset, setOffset] = useState(0); const [search, setSearch] = useState(''); @@ -33,7 +33,7 @@ export default function SetsPage() { const refresh = useCallback(async () => { const [result] = await db.executeSql(selectSets, [`%${search}%`, limit, 0]); if (!result) return setSets([]); - console.log(`${SetsPage.name}.refresh:`, {search, limit}); + console.log(`${SetList.name}.refresh:`, {search, limit}); setSets(result.rows.raw()); setOffset(0); setEnd(false); @@ -66,7 +66,7 @@ export default function SetsPage() { if (end) return; setRefreshing(true); const newOffset = offset + limit; - console.log(`${SetsPage.name}.next:`, { + console.log(`${SetList.name}.next:`, { offset, limit, newOffset, diff --git a/SettingsPage.tsx b/SettingsPage.tsx index a5dfd4f..963854c 100644 --- a/SettingsPage.tsx +++ b/SettingsPage.tsx @@ -13,6 +13,7 @@ import {DatabaseContext} from './App'; import BatteryDialog from './BatteryDialog'; import Set from './set'; import DocumentPicker from 'react-native-document-picker'; +import ConfirmDialog from './ConfirmDialog'; const {getItem, setItem} = AsyncStorage; @@ -24,6 +25,7 @@ export default function SettingsPage() { const [predictiveSets, setPredictiveSets] = useState(false); const [snackbar, setSnackbar] = useState(''); const [showBattery, setShowBattery] = useState(false); + const [showDelete, setShowDelete] = useState(false); const [ignoring, setIgnoring] = useState(false); const [timeoutId, setTimeoutId] = useState(0); const db = useContext(DatabaseContext); @@ -51,6 +53,7 @@ export default function SettingsPage() { ); const clear = useCallback(async () => { + setShowDelete(false); await db.executeSql(`DELETE FROM sets`); toast('All data has been deleted!'); }, [db, toast]); @@ -165,6 +168,17 @@ export default function SettingsPage() { onValueChange={changeAlarmEnabled} /> + { + NativeModules.AlarmModule.openBatteryOptimizations(); + setShowBattery(false); + }}> + Disable battery optimizations for Massive to use rest timers. + + Predictive sets - + + This irreversibly deletes all data from the app. Are you sure? +