Get settings on TimerPage on focus

Previously it was on mount.
Fixes #122.
This commit is contained in:
Brandon Presley 2022-12-02 14:48:10 +13:00
parent c2994da041
commit 67d90d4e02
1 changed files with 8 additions and 4 deletions

View File

@ -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 {Dimensions, NativeModules, View} from 'react-native'
import {Button, Text, useTheme} from 'react-native-paper' import {Button, Text, useTheme} from 'react-native-paper'
import {ProgressCircle} from 'react-native-svg-charts' import {ProgressCircle} from 'react-native-svg-charts'
@ -19,15 +20,18 @@ export default function TimerPage() {
const [settings, setSettings] = useState<Settings>() const [settings, setSettings] = useState<Settings>()
const {colors} = useTheme() const {colors} = useTheme()
useEffect(() => { useFocusEffect(
settingsRepo.findOne({where: {}}).then(setSettings) useCallback(() => {
}, []) settingsRepo.findOne({where: {}}).then(setSettings)
}, []),
)
const stop = () => { const stop = () => {
NativeModules.AlarmModule.stop() NativeModules.AlarmModule.stop()
} }
const add = async () => { const add = async () => {
console.log(`${TimerPage.name}.add:`, settings)
const params = [settings.vibrate, settings.sound, settings.noSound] const params = [settings.vibrate, settings.sound, settings.noSound]
NativeModules.AlarmModule.add(...params) NativeModules.AlarmModule.add(...params)
} }