Skip to content

Commit

Permalink
Reset only timers on settings
Browse files Browse the repository at this point in the history
  • Loading branch information
slavikdenis committed Mar 20, 2021
1 parent fa54aa9 commit 7e99f70
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 21 deletions.
6 changes: 3 additions & 3 deletions src/components/settings/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const SettingsDrawer = ({
finalFocusRef,
}: SettingsDrawerProps) => {
// Settings context
const { setDefaultValues, areSettingsDefault } = useSettingsContext();
const { setDefaultValues, areTimerSettingsDefault } = useSettingsContext();

return (
<Drawer
Expand All @@ -49,10 +49,10 @@ const SettingsDrawer = ({
<Content />
</DrawerBody>

{!areSettingsDefault ? (
{!areTimerSettingsDefault ? (
<DrawerFooter>
<Button minimal fullWidth onClick={setDefaultValues}>
Load defaults
Reset timers
</Button>
</DrawerFooter>
) : null}
Expand Down
17 changes: 10 additions & 7 deletions src/context/settings/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ type SettingsContextState = {
vibrations: boolean;
};

export type TimeSettingContextKeys = keyof Pick<
SettingsContextState,
'blazeTime' | 'heatingTime'
>;

type SettingsContextFunctions = {
setSetting: (
key: keyof SettingsContextState,
Expand All @@ -25,7 +30,7 @@ type SettingsContextFunctions = {

type SettingsContextConstants = {
waveTime: number;
areSettingsDefault: boolean;
areTimerSettingsDefault: boolean;
};

export const DEFAULT_HEATING_TIME = 30;
Expand All @@ -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
Expand All @@ -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]);

Expand Down Expand Up @@ -113,7 +116,7 @@ export const SettingsProvider: React.FC = ({ children }) => {
value={{
...state,
waveTime: state.heatingTime + state.blazeTime,
areSettingsDefault,
areTimerSettingsDefault,
setSetting,
setDefaultValues,
}}
Expand Down
6 changes: 4 additions & 2 deletions src/pages/index.tsx
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -31,3 +31,5 @@ export default function App() {
</>
);
}

export default memo(App);
18 changes: 9 additions & 9 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit 7e99f70

Please sign in to comment.