Skip to content

Commit

Permalink
Formatting 5, fix merge issue with preferences
Browse files Browse the repository at this point in the history
  • Loading branch information
ky28059 committed May 6, 2024
1 parent 8ba0977 commit fa8a80a
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 17 deletions.
43 changes: 34 additions & 9 deletions app/preferences/ClockContent.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
'use client'

import {useContext} from 'react';
import { useContext } from 'react';

// Components
import PreferencesInputGroup from './PreferencesInputGroup';
import PreferencesButton from './PreferencesButton';

// Contexts
import PreferencesContext from '../../contexts/PreferencesContext';


export default function ClockContent() {
const {preferences, setPreferences} = useContext(PreferencesContext);
const { preferences, setPreferences } = useContext(PreferencesContext);

function updateShowTenthSeconds(value: 'ALWAYS' | 'CRITICAL' | 'NEVER') {
const newPreferences = structuredClone(preferences); // TODO: structured clone necessary?
Expand All @@ -33,31 +37,52 @@ export default function ClockContent() {
<p>[...]</p>

<PreferencesInputGroup label="Show tenths of seconds">
<PreferencesButton onClick={() => updateShowTenthSeconds('ALWAYS')} selected={preferences.clock.showTenthSeconds === 'ALWAYS'}>
<PreferencesButton
onClick={() => updateShowTenthSeconds('ALWAYS')}
selected={preferences.clock.showTenthSeconds === 'ALWAYS'}
>
Always
</PreferencesButton>
<PreferencesButton onClick={() => updateShowTenthSeconds('CRITICAL')} selected={preferences.clock.showTenthSeconds === 'CRITICAL'}>
<PreferencesButton
onClick={() => updateShowTenthSeconds('CRITICAL')}
selected={preferences.clock.showTenthSeconds === 'CRITICAL'}
>
When time remaining {'<'} 10 seconds
</PreferencesButton>
<PreferencesButton onClick={() => updateShowTenthSeconds('NEVER')} selected={preferences.clock.showTenthSeconds === 'NEVER'}>
<PreferencesButton
onClick={() => updateShowTenthSeconds('NEVER')}
selected={preferences.clock.showTenthSeconds === 'NEVER'}
>
Never
</PreferencesButton>
</PreferencesInputGroup>

<PreferencesInputGroup label="Show green progress bars">
<PreferencesButton onClick={() => updateShowProgressBars(true)} selected={preferences.clock.showProgressBars}>
<PreferencesButton
onClick={() => updateShowProgressBars(true)}
selected={preferences.clock.showProgressBars}
>
Always
</PreferencesButton>
<PreferencesButton onClick={() => updateShowProgressBars(false)} selected={!preferences.clock.showProgressBars}>
<PreferencesButton
onClick={() => updateShowProgressBars(false)}
selected={!preferences.clock.showProgressBars}
>
Never
</PreferencesButton>
</PreferencesInputGroup>

<PreferencesInputGroup label="Play a sound when time gets critical">
<PreferencesButton onClick={() => updatePlayCriticalSound(true)} selected={preferences.clock.playCriticalSound}>
<PreferencesButton
onClick={() => updatePlayCriticalSound(true)}
selected={preferences.clock.playCriticalSound}
>
Always
</PreferencesButton>
<PreferencesButton onClick={() => updatePlayCriticalSound(false)} selected={!preferences.clock.playCriticalSound}>
<PreferencesButton
onClick={() => updatePlayCriticalSound(false)}
selected={!preferences.clock.playCriticalSound}
>
Never
</PreferencesButton>
</PreferencesInputGroup>
Expand Down
8 changes: 6 additions & 2 deletions app/preferences/PreferencesButton.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
'use client'

import {MouseEventHandler, ReactNode} from 'react';
import type { MouseEventHandler, ReactNode } from 'react';


export default function PreferencesButton(props: {onClick: MouseEventHandler<HTMLButtonElement>, selected: boolean, children: ReactNode}) {
export default function PreferencesButton(props: {
onClick: MouseEventHandler<HTMLButtonElement>,
selected: boolean,
children: ReactNode
}) {
return (
<button
onClick={props.onClick}
Expand Down
4 changes: 2 additions & 2 deletions app/preferences/PreferencesInputGroup.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {ReactNode} from 'react';
import { ReactNode } from 'react';


export default function PreferencesInputGroup(props: {label: string, children: ReactNode}) {
export default function PreferencesInputGroup(props: { label: string, children: ReactNode }) {
return (
<div className="mt-12">
<h2 className="flex items-center gap-4 mb-3 text-lg font-light text-secondary after:block after:h-0.5 after:w-full after:bg-gradient-to-r after:from-theme-orange/50 after:to-transparent">
Expand Down
6 changes: 4 additions & 2 deletions app/preferences/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import type {ReactNode} from 'react';
import type { ReactNode } from 'react';

// Components
import InfoSidebarItem from '../../components/InfoSidebarItem';
import InfoSidebar from '../../components/InfoSidebar';
import InfoPanel from '../../components/InfoPanel';


export default function Layout(props:{children: ReactNode}) {
export default function Layout(props: { children: ReactNode }) {
return (
<div className="container flex pt-4 pb-12 w-full">
<InfoSidebar>
Expand Down
2 changes: 1 addition & 1 deletion app/preferences/page.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type {Metadata} from 'next';
import type { Metadata } from 'next';
import ClockContent from './ClockContent';


Expand Down
5 changes: 4 additions & 1 deletion components/PreferencesProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ export default function PreferencesProvider(props: { children: ReactNode }) {
const raw = localStorage.getItem('preferences');
if (!raw) return localStorage.setItem('preferences', JSON.stringify(preferences));

setPreferences(JSON.parse(raw));
// TODO: eventually need deepmerge here
const merged = { ...defaultPreferences, ...JSON.parse(raw) };
setPreferences(merged);
localStorage.setItem('preferences', JSON.stringify(merged));
}, []);

// Update the user's preferences by fetching the backend with the new data (if signed in). If successful, the
Expand Down

0 comments on commit fa8a80a

Please sign in to comment.