diff --git a/Alarm.tsx b/Alarm.tsx index 41b5587..fed04f5 100644 --- a/Alarm.tsx +++ b/Alarm.tsx @@ -1,6 +1,6 @@ import AsyncStorage from '@react-native-async-storage/async-storage'; import React, {useEffect, useState} from 'react'; -import {StyleSheet, Text} from 'react-native'; +import {NativeModules, StyleSheet, Text, View} from 'react-native'; import {Button, Modal, Portal} from 'react-native-paper'; export default function Alarm() { @@ -8,15 +8,16 @@ export default function Alarm() { const [seconds, setSeconds] = useState(0); const [minutes, setMinutes] = useState(0); + let intervalId: number; + useEffect(() => { if (!show) return; - let intervalId: number; (async () => { const next = await AsyncStorage.getItem('nextAlarm'); if (!next) return; - const ms = new Date(next).getTime() - new Date().getTime(); - if (ms <= 0) return; - let secondsLeft = ms / 1000; + const milliseconds = new Date(next).getTime() - new Date().getTime(); + if (milliseconds <= 0) return; + let secondsLeft = milliseconds / 1000; setSeconds(Math.floor(secondsLeft % 60)); setMinutes(Math.floor(secondsLeft / 60)); intervalId = setInterval(() => { @@ -29,6 +30,14 @@ export default function Alarm() { return () => clearInterval(intervalId); }, [show]); + const stop = async () => { + NativeModules.AlarmModule.stop(); + clearInterval(intervalId); + setSeconds(0); + setMinutes(0); + await AsyncStorage.setItem('nextAlarm', ''); + }; + return ( <> @@ -40,9 +49,14 @@ export default function Alarm() { {minutes}:{seconds} - + + + + - - - - - - - - + + setShow(false)}> + Add a set + repsRef.current?.focus()} + /> + weightRef.current?.focus()} + /> + + + + + + + + + + ); } const styles = StyleSheet.create({ modal: { - height: '100%', backgroundColor: 'black', padding: 20, }, diff --git a/Home.tsx b/Home.tsx index 6b174d8..51399ba 100644 --- a/Home.tsx +++ b/Home.tsx @@ -7,7 +7,7 @@ import { StyleSheet, View, } from 'react-native'; -import {List, Searchbar} from 'react-native-paper'; +import {AnimatedFAB, Button, Searchbar} from 'react-native-paper'; import Alarm from './Alarm'; import {getDb} from './db'; import EditSet from './EditSet'; @@ -90,13 +90,23 @@ export default function Home() { + + { + setId(undefined); + setShowEdit(true); + }} + /> ); }