From 67d90d4e02725a9e1ff7294a10ae1adc744e43f0 Mon Sep 17 00:00:00 2001 From: Brandon Presley Date: Fri, 2 Dec 2022 14:48:10 +1300 Subject: [PATCH] Get settings on TimerPage on focus Previously it was on mount. Fixes #122. --- TimerPage.tsx | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/TimerPage.tsx b/TimerPage.tsx index 466b56e..4b551e7 100644 --- a/TimerPage.tsx +++ b/TimerPage.tsx @@ -1,4 +1,5 @@ -import React, {useEffect, useMemo, useState} from 'react' +import {useFocusEffect} from '@react-navigation/native' +import React, {useCallback, useMemo, useState} from 'react' import {Dimensions, NativeModules, View} from 'react-native' import {Button, Text, useTheme} from 'react-native-paper' import {ProgressCircle} from 'react-native-svg-charts' @@ -19,15 +20,18 @@ export default function TimerPage() { const [settings, setSettings] = useState() const {colors} = useTheme() - useEffect(() => { - settingsRepo.findOne({where: {}}).then(setSettings) - }, []) + useFocusEffect( + useCallback(() => { + settingsRepo.findOne({where: {}}).then(setSettings) + }, []), + ) const stop = () => { NativeModules.AlarmModule.stop() } const add = async () => { + console.log(`${TimerPage.name}.add:`, settings) const params = [settings.vibrate, settings.sound, settings.noSound] NativeModules.AlarmModule.add(...params) }