diff --git a/.eslintrc.js b/.eslintrc.js index dcf0be0..6b1f939 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -13,4 +13,4 @@ module.exports = { }, }, ], -}; +} diff --git a/App.tsx b/App.tsx index 2122fd6..573238e 100644 --- a/App.tsx +++ b/App.tsx @@ -42,6 +42,7 @@ export const CombinedDarkTheme = { const App = () => { const isDark = useColorScheme() === 'dark' + const [initialized, setInitialized] = useState(false) const [settings, setSettings] = useState() const [color, setColor] = useState( isDark @@ -55,6 +56,7 @@ const App = () => { console.log(`${App.name}.useEffect:`, {gotSettings}) setSettings(gotSettings) if (gotSettings.color) setColor(gotSettings.color) + setInitialized(true) }) }, [setColor]) @@ -73,15 +75,22 @@ const App = () => { return value }, [color, isDark, settings]) + const settingsContext = useMemo( + () => ({settings, setSettings}), + [settings, setSettings], + ) + + const colorContext = useMemo(() => ({color, setColor}), [color, setColor]) + return ( - + }}> - {settings && ( - + {initialized && ( + )} diff --git a/EditWorkout.tsx b/EditWorkout.tsx index 46870b0..a435d61 100644 --- a/EditWorkout.tsx +++ b/EditWorkout.tsx @@ -3,7 +3,6 @@ import {useCallback, useRef, useState} from 'react' import {ScrollView, TextInput, View} from 'react-native' import DocumentPicker from 'react-native-document-picker' import {Button, Card, TouchableRipple} from 'react-native-paper' -import {Like} from 'typeorm' import ConfirmDialog from './ConfirmDialog' import {MARGIN, PADDING} from './constants' import {getNow, planRepo, setRepo} from './db' diff --git a/PlanItem.tsx b/PlanItem.tsx index a95b68d..aeaa826 100644 --- a/PlanItem.tsx +++ b/PlanItem.tsx @@ -6,7 +6,6 @@ import { import {useCallback, useMemo, useState} from 'react' import {GestureResponderEvent, Text} from 'react-native' import {Divider, List, Menu} from 'react-native-paper' -import {getBestSet} from './best.service' import {planRepo} from './db' import {Plan} from './plan' import {PlanPageParams} from './plan-page-params' diff --git a/Routes.tsx b/Routes.tsx index de8bb32..23b2060 100644 --- a/Routes.tsx +++ b/Routes.tsx @@ -1,4 +1,5 @@ import {createDrawerNavigator} from '@react-navigation/drawer' +import {useMemo} from 'react' import {IconButton} from 'react-native-paper' import BestPage from './BestPage' import {DrawerParamList} from './drawer-param-list' @@ -14,13 +15,16 @@ const Drawer = createDrawerNavigator() export default function Routes() { const dark = useDark() - const routes: Route[] = [ - {name: 'Home', component: HomePage, icon: 'home'}, - {name: 'Plans', component: PlanPage, icon: 'event'}, - {name: 'Best', component: BestPage, icon: 'insights'}, - {name: 'Workouts', component: WorkoutsPage, icon: 'fitness-center'}, - {name: 'Settings', component: SettingsPage, icon: 'settings'}, - ] + const routes: Route[] = useMemo( + () => [ + {name: 'Home', component: HomePage, icon: 'home'}, + {name: 'Plans', component: PlanPage, icon: 'event'}, + {name: 'Best', component: BestPage, icon: 'insights'}, + {name: 'Workouts', component: WorkoutsPage, icon: 'fitness-center'}, + {name: 'Settings', component: SettingsPage, icon: 'settings'}, + ], + [], + ) return ( [] = [ - {name: 'Rest timers', value: alarm, onChange: changeAlarmEnabled}, - {name: 'Vibrate', value: vibrate, onChange: changeVibrate}, - {name: 'Disable sound', value: noSound, onChange: changeNoSound}, - {name: 'Record notifications', value: notify, onChange: changeNotify}, - {name: 'Show images', value: images, onChange: changeImages}, - {name: 'Show unit', value: showUnit, onChange: changeUnit}, - {name: 'Show steps', value: steps, onChange: changeSteps}, - {name: 'Show date', value: showDate, onChange: changeShowDate}, - {name: 'Show sets', value: showSets, onChange: changeShowSets}, + {name: 'Rest timers', value: settings.alarm, onChange: changeAlarmEnabled}, + {name: 'Vibrate', value: settings.vibrate, onChange: changeVibrate}, + {name: 'Disable sound', value: settings.noSound, onChange: changeNoSound}, + {name: 'Notifications', value: settings.notify, onChange: changeNotify}, + {name: 'Show images', value: settings.images, onChange: changeImages}, + {name: 'Show unit', value: settings.showUnit, onChange: changeUnit}, + {name: 'Show steps', value: settings.steps, onChange: changeSteps}, + {name: 'Show date', value: settings.showDate, onChange: changeShowDate}, + {name: 'Show sets', value: settings.showSets, onChange: changeShowSets}, ] const changeTheme = useCallback( @@ -177,6 +164,27 @@ export default function SettingsPage() { [settings, setSettings], ) + const sound = useMemo(() => { + if (!settings.sound) return null + const split = settings.sound.split('/') + return split.pop() + }, [settings.sound]) + + const theme = useMemo(() => { + if (!'theme'.includes(term.toLowerCase())) return null + return ( + + + + + + ) + }, [term, color, changeTheme, settings.theme]) + return ( <> @@ -195,17 +203,7 @@ export default function SettingsPage() { {input.name} ))} - {'theme'.includes(term.toLowerCase()) && ( - - - - - - )} + {theme} {'color'.includes(term.toLowerCase()) && ( - Alarm sound - {sound - ? ': ' + sound.split('/')[sound.split('/').length - 1] - : null} + Alarm sound: {sound} )} diff --git a/StartPlan.tsx b/StartPlan.tsx index 53fac07..3aff1d9 100644 --- a/StartPlan.tsx +++ b/StartPlan.tsx @@ -86,7 +86,7 @@ export default function StartPlan() { useFocusEffect( useCallback(() => { refresh().then(newCounts => select(0, newCounts)) - }, [refresh]), + }, [refresh, select]), ) const handleSubmit = async () => { diff --git a/ViewBest.tsx b/ViewBest.tsx index 6dbdb4b..5c0d8ae 100644 --- a/ViewBest.tsx +++ b/ViewBest.tsx @@ -56,9 +56,9 @@ export default function ViewBest() { builder .addSelect('MAX(weight / (1.0278 - 0.0278 * reps))', 'weight') .getRawMany() - .then(weights => { - console.log({weights}) - setWeights(weights) + .then(newWeights => { + console.log({weights: newWeights}) + setWeights(newWeights) }) } }, [params.best.name, metric, period]) diff --git a/babel.config.js b/babel.config.js index edd6299..f67d31d 100644 --- a/babel.config.js +++ b/babel.config.js @@ -2,8 +2,8 @@ module.exports = { presets: ['module:metro-react-native-babel-preset'], plugins: [ '@babel/plugin-transform-flow-strip-types', - ['@babel/plugin-proposal-decorators', { legacy: true }], - ['@babel/plugin-proposal-class-properties', { loose: true }], + ['@babel/plugin-proposal-decorators', {legacy: true}], + ['@babel/plugin-proposal-class-properties', {loose: true}], 'react-native-reanimated/plugin', 'react-native-paper/babel', ], @@ -12,4 +12,4 @@ module.exports = { plugins: ['transform-remove-console'], }, }, -}; +} diff --git a/jest.config.js b/jest.config.js index a561637..619f6bf 100644 --- a/jest.config.js +++ b/jest.config.js @@ -11,4 +11,4 @@ module.exports = { './node_modules/react-native-gesture-handler/jestSetup', './jestSetup.ts', ], -}; +} diff --git a/metro.config.js b/metro.config.js index e91aba9..c81b3ca 100644 --- a/metro.config.js +++ b/metro.config.js @@ -14,4 +14,4 @@ module.exports = { }, }), }, -}; +} diff --git a/use-settings.ts b/use-settings.ts index 2f72009..f955a55 100644 --- a/use-settings.ts +++ b/use-settings.ts @@ -2,19 +2,19 @@ import React, {useContext} from 'react' import Settings from './settings' export const defaultSettings: Settings = { - alarm: 0, + alarm: true, color: '', date: '', - images: 1, - notify: 0, - showDate: 0, - showSets: 1, - showUnit: 1, + images: true, + notify: false, + showDate: false, + showSets: true, + showUnit: true, sound: '', - steps: 0, + steps: false, theme: 'system', - vibrate: 1, - noSound: 0, + vibrate: true, + noSound: false, } export const SettingsContext = React.createContext<{