From 7e99f70c257f601ed17f3fd447ac0e00090196cb Mon Sep 17 00:00:00 2001 From: Denis Slavik Date: Sat, 20 Mar 2021 21:22:28 +0100 Subject: [PATCH] Reset only timers on settings --- src/components/settings/index.tsx | 6 +++--- src/context/settings/index.tsx | 17 ++++++++++------- src/pages/index.tsx | 6 ++++-- yarn.lock | 18 +++++++++--------- 4 files changed, 26 insertions(+), 21 deletions(-) diff --git a/src/components/settings/index.tsx b/src/components/settings/index.tsx index 59e56ee..c3cd4b0 100644 --- a/src/components/settings/index.tsx +++ b/src/components/settings/index.tsx @@ -25,7 +25,7 @@ const SettingsDrawer = ({ finalFocusRef, }: SettingsDrawerProps) => { // Settings context - const { setDefaultValues, areSettingsDefault } = useSettingsContext(); + const { setDefaultValues, areTimerSettingsDefault } = useSettingsContext(); return ( - {!areSettingsDefault ? ( + {!areTimerSettingsDefault ? ( ) : null} diff --git a/src/context/settings/index.tsx b/src/context/settings/index.tsx index 8427d91..79268fe 100644 --- a/src/context/settings/index.tsx +++ b/src/context/settings/index.tsx @@ -15,6 +15,11 @@ type SettingsContextState = { vibrations: boolean; }; +export type TimeSettingContextKeys = keyof Pick< + SettingsContextState, + 'blazeTime' | 'heatingTime' +>; + type SettingsContextFunctions = { setSetting: ( key: keyof SettingsContextState, @@ -25,7 +30,7 @@ type SettingsContextFunctions = { type SettingsContextConstants = { waveTime: number; - areSettingsDefault: boolean; + areTimerSettingsDefault: boolean; }; export const DEFAULT_HEATING_TIME = 30; @@ -37,7 +42,7 @@ const initialSettingsContext: SettingsContextState & heatingTime: DEFAULT_HEATING_TIME, blazeTime: DEFAULT_BLAZE_TIME, waveTime: DEFAULT_HEATING_TIME + DEFAULT_BLAZE_TIME, - areSettingsDefault: true, + areTimerSettingsDefault: true, screenWakeLock: true, vibrations: true, // eslint-disable-next-line @typescript-eslint/no-empty-function @@ -59,12 +64,10 @@ export const SettingsProvider: React.FC = ({ children }) => { ); // Check if settings are default - const areSettingsDefault = useMemo(() => { + const areTimerSettingsDefault = useMemo(() => { return ( state.blazeTime === initialSettingsContext.blazeTime && - state.heatingTime === initialSettingsContext.heatingTime && - state.screenWakeLock === initialSettingsContext.screenWakeLock && - state.vibrations === initialSettingsContext.vibrations + state.heatingTime === initialSettingsContext.heatingTime ); }, [state]); @@ -113,7 +116,7 @@ export const SettingsProvider: React.FC = ({ children }) => { value={{ ...state, waveTime: state.heatingTime + state.blazeTime, - areSettingsDefault, + areTimerSettingsDefault, setSetting, setDefaultValues, }} diff --git a/src/pages/index.tsx b/src/pages/index.tsx index db396ea..e3f95e4 100644 --- a/src/pages/index.tsx +++ b/src/pages/index.tsx @@ -1,11 +1,11 @@ import Head from 'next/head'; import dynamic from 'next/dynamic'; -import { useEffect } from 'react'; +import { memo, useEffect } from 'react'; import { useColorMode } from '@chakra-ui/react'; const DynamicTimer = dynamic(() => import('../components/timer')); -export default function App() { +function App() { const { colorMode, toggleColorMode } = useColorMode(); // Force dark mode @@ -31,3 +31,5 @@ export default function App() { ); } + +export default memo(App); diff --git a/yarn.lock b/yarn.lock index 5f317bd..2241335 100644 --- a/yarn.lock +++ b/yarn.lock @@ -995,9 +995,9 @@ ajv@^6.10.0, ajv@^6.12.4: uri-js "^4.2.2" ajv@^7.0.2: - version "7.2.1" - resolved "https://registry.yarnpkg.com/ajv/-/ajv-7.2.1.tgz#a5ac226171912447683524fa2f1248fcf8bac83d" - integrity sha512-+nu0HDv7kNSOua9apAVc979qd932rrZeb3WOvoiD31A/p1mIE5/9bN2027pE2rOPYEdS3UHzsvof4hY+lM9/WQ== + version "7.2.3" + resolved "https://registry.yarnpkg.com/ajv/-/ajv-7.2.3.tgz#ca78d1cf458d7d36d1c3fa0794dd143406db5772" + integrity sha512-idv5WZvKVXDqKralOImQgPM9v6WOdLNa0IY3B3doOjw/YxRGT8I+allIJ6kd7Uaj+SF1xZUSU+nPM5aDNBVtnw== dependencies: fast-deep-equal "^3.1.1" json-schema-traverse "^1.0.0" @@ -1298,9 +1298,9 @@ callsites@^3.0.0: integrity sha512-P8BjAsXvZS+VIDUI11hHCQEv74YT67YUi5JJFNWIqL235sBmjX4+qx9Muvls5ivyNENctx46xQLQ3aTuE7ssaQ== caniuse-lite@^1.0.30001173, caniuse-lite@^1.0.30001179: - version "1.0.30001202" - resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001202.tgz#4cb3bd5e8a808e8cd89e4e66c549989bc8137201" - integrity sha512-ZcijQNqrcF8JNLjzvEiXqX4JUYxoZa7Pvcsd9UD8Kz4TvhTonOSNRsK+qtvpVL4l6+T1Rh4LFtLfnNWg6BGWCQ== + version "1.0.30001203" + resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001203.tgz#a7a34df21a387d9deffcd56c000b8cf5ab540580" + integrity sha512-/I9tvnzU/PHMH7wBPrfDMSuecDeUKerjCPX7D0xBbaJZPxoT9m+yYxt0zCTkcijCkjTdim3H56Zm0i5Adxch4w== chalk@2.4.2, chalk@^2.0.0, chalk@^2.4.2: version "2.4.2" @@ -1660,9 +1660,9 @@ domain-browser@^1.1.1: integrity sha512-jnjyiM6eRyZl2H+W8Q/zLMA481hzi0eszAaBUzIVnmYVDBbnLxVNnfu1HgEBvCbL+71FrxMl3E6lpKH7Ge3OXA== electron-to-chromium@^1.3.634: - version "1.3.692" - resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.3.692.tgz#4d00479055a7282cdd1b19caec09ed7779529640" - integrity sha512-Ix+zDUAXWZuUzqKdhkgN5dP7ZM+IwMG4yAGFGDLpGJP/3vNEEwuHG1LIhtXUfW0FFV0j38t5PUv2n/3MFSRviQ== + version "1.3.693" + resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.3.693.tgz#5089c506a925c31f93fcb173a003a22e341115dd" + integrity sha512-vUdsE8yyeu30RecppQtI+XTz2++LWLVEIYmzeCaCRLSdtKZ2eXqdJcrs85KwLiPOPVc6PELgWyXBsfqIvzGZag== elliptic@^6.5.3: version "6.5.4"