Skip to content

Commit

Permalink
Run formatter
Browse files Browse the repository at this point in the history
  • Loading branch information
mdirolf committed Feb 2, 2024
1 parent 6d79523 commit f542f5e
Show file tree
Hide file tree
Showing 5 changed files with 114 additions and 112 deletions.
49 changes: 24 additions & 25 deletions app/components/Puzzle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,10 @@ export const Puzzle = ({

// Pause when page goes out of focus
function prodPause() {
if (process.env.NODE_ENV !== 'development' && !props.prefs?.dontPauseOnLostFocus) {
if (
process.env.NODE_ENV !== 'development' &&
!props.prefs?.dontPauseOnLostFocus
) {
window.parent.postMessage(
{
type: 'pause',
Expand Down Expand Up @@ -696,12 +699,7 @@ export const Puzzle = ({
e.preventDefault();
}
},
[
dispatch,
loadingPlayState,
state.success,
state.dismissedSuccess,
]
[dispatch, loadingPlayState, state.success, state.dismissedSuccess]
);
useEventListener('keydown', physicalKeyboardHandler);

Expand Down Expand Up @@ -1032,7 +1030,7 @@ export const Puzzle = ({
),
[state.autocheck, isSlate]
);

const user = props.user;
const moreMenu = useMemo(
() => (
Expand Down Expand Up @@ -1157,25 +1155,26 @@ export const Puzzle = ({
) : null}
{user !== undefined ? (
<NestedDropDown
closeParent={closeDropdown}
icon={<FaCog /> }
text={"Solver Preferences"}
closeParent={closeDropdown}
icon={<FaCog />}
text={'Solver Preferences'}
>
{() =>
<ul
css={{
listStyleType: 'none',
padding: '0 10vw',
}}
>
<SolverPreferencesList
prefs={props.prefs}
userId={user.uid}
/>
</ul>
}
{() => (
<ul
css={{
listStyleType: 'none',
padding: '0 10vw',
}}
>
<SolverPreferencesList
prefs={props.prefs}
userId={user.uid}
/>
</ul>
)}
</NestedDropDown>
) : (''
) : (
''
)}
<TopBarDropDownLinkA
href="/account"
Expand Down
156 changes: 81 additions & 75 deletions app/components/SolverPreferencesList.tsx
Original file line number Diff line number Diff line change
@@ -1,95 +1,101 @@
import { setDoc } from "firebase/firestore";
import { AccountPrefsFlagsT, AccountPrefsT } from "../lib/prefs";
import { logAsyncErrors } from "../lib/utils";
import { useSnackbar } from "./Snackbar";
import { getDocRef } from "../lib/firebaseWrapper";
import { setDoc } from 'firebase/firestore';
import { AccountPrefsFlagsT, AccountPrefsT } from '../lib/prefs';
import { logAsyncErrors } from '../lib/utils';
import { useSnackbar } from './Snackbar';
import { getDocRef } from '../lib/firebaseWrapper';

interface PrefSettingProps {
prefs: AccountPrefsT | undefined;
userId: string;
flag: keyof AccountPrefsFlagsT;
text: string;
invert?: boolean;
prefs: AccountPrefsT | undefined;
userId: string;
flag: keyof AccountPrefsFlagsT;
text: string;
invert?: boolean;
}

export const PrefSetting = (props: PrefSettingProps) => {
const { showSnackbar } = useSnackbar();
const prefSet = props.prefs?.[props.flag] ?? false;
return (
<label>
<input
css={{ marginRight: '1em' }}
type="checkbox"
checked={props.invert ? !prefSet : prefSet}
onChange={logAsyncErrors(async (e) => {
await setDoc(
getDocRef('prefs', props.userId),
<input
css={{ marginRight: '1em' }}
type="checkbox"
checked={props.invert ? !prefSet : prefSet}
onChange={logAsyncErrors(async (e) => {
await setDoc(
getDocRef('prefs', props.userId),
{
[props.flag]: props.invert ? !e.target.checked : e.target.checked,
[props.flag]: props.invert ? !e.target.checked : e.target.checked,
},
{ merge: true }
).then(() => {
).then(() => {
showSnackbar('Preferences Updated');
});
});
})}
onClick={(e) => {
e.stopPropagation();
}}
/>
{props.text}
onClick={(e) => {
e.stopPropagation();
}}
/>
{props.text}
</label>
);
);
};

export const SolverPreferencesList = ({prefs, userId}: {prefs?: AccountPrefsT, userId: string}) => {
export const SolverPreferencesList = ({
prefs,
userId,
}: {
prefs?: AccountPrefsT;
userId: string;
}) => {
if (!prefs) {
return null; // or some default content
}
return (
<>
<li>
<PrefSetting
prefs={prefs}
userId={userId}
flag={'advanceOnPerpendicular'}
text="Advance to next square when changing direction with arrow keys"
/>
</li>
<li>
<PrefSetting
prefs={prefs}
userId={userId}
flag={'dontSkipCompleted'}
invert={true}
text="Skip over completed squares after entering a letter"
/>
</li>
<li>
<PrefSetting
prefs={prefs}
userId={userId}
flag={'dontAdvanceWordAfterCompletion'}
invert={true}
text="Move to next clue after completing an entry"
/>
</li>
<li>
<PrefSetting
prefs={prefs}
userId={userId}
flag={'solveDownsOnly'}
text="Start puzzles in downs-only mode"
/>
</li>
<li>
<PrefSetting
prefs={prefs}
userId={userId}
flag={'dontPauseOnLostFocus'}
invert={true}
text="Automatically pause solving when page loses focus"
/>
</li>
</>
return (
<>
<li>
<PrefSetting
prefs={prefs}
userId={userId}
flag={'advanceOnPerpendicular'}
text="Advance to next square when changing direction with arrow keys"
/>
</li>
<li>
<PrefSetting
prefs={prefs}
userId={userId}
flag={'dontSkipCompleted'}
invert={true}
text="Skip over completed squares after entering a letter"
/>
</li>
<li>
<PrefSetting
prefs={prefs}
userId={userId}
flag={'dontAdvanceWordAfterCompletion'}
invert={true}
text="Move to next clue after completing an entry"
/>
</li>
<li>
<PrefSetting
prefs={prefs}
userId={userId}
flag={'solveDownsOnly'}
text="Start puzzles in downs-only mode"
/>
</li>
<li>
<PrefSetting
prefs={prefs}
userId={userId}
flag={'dontPauseOnLostFocus'}
invert={true}
text="Automatically pause solving when page loses focus"
/>
</li>
</>
);
};
};
2 changes: 1 addition & 1 deletion app/lib/prefs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const AccountPrefsFlagsV = t.partial({
dontAdvanceWordAfterCompletion: t.boolean,
solveDownsOnly: t.boolean,
disableCommentsByDefault: t.boolean,
dontPauseOnLostFocus: t.boolean
dontPauseOnLostFocus: t.boolean,
});
export type AccountPrefsFlagsT = t.TypeOf<typeof AccountPrefsFlagsV>;

Expand Down
15 changes: 6 additions & 9 deletions app/pages/account.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@ import { Link } from '../components/Link';
import { CreatePageForm } from '../components/ConstructorPage';
import { Button } from '../components/Buttons';
import { PROFILE_PIC, COVER_PIC } from '../lib/style';
import {
UnsubscribeFlags,
AccountPrefsT,
} from '../lib/prefs';
import { UnsubscribeFlags, AccountPrefsT } from '../lib/prefs';

import dynamic from 'next/dynamic';
import { useSnackbar } from '../components/Snackbar';
Expand All @@ -35,7 +32,10 @@ import {
import { signOut } from 'firebase/auth';
import { BioEditor } from '../components/BioEditor';
import { logAsyncErrors } from '../lib/utils';
import { PrefSetting, SolverPreferencesList } from '../components/SolverPreferencesList';
import {
PrefSetting,
SolverPreferencesList,
} from '../components/SolverPreferencesList';

export const getStaticProps = withStaticTranslation(() => {
return { props: {} };
Expand Down Expand Up @@ -175,10 +175,7 @@ export const AccountPage = ({ user, constructorPage, prefs }: AuthProps) => {
padding: '0 0',
}}
>
<SolverPreferencesList
prefs={prefs}
userId={user.uid}
/>
<SolverPreferencesList prefs={prefs} userId={user.uid} />
</ul>
<hr css={{ margin: '2em 0' }} />
<h2>Browser-specific Settings</h2>
Expand Down
4 changes: 2 additions & 2 deletions app/reducers/reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -822,8 +822,8 @@ export function gridInterfaceReducer<T extends GridInterfaceState>(
if (key.k === KeyK.Escape) {
return {
...state,
currentTimeWindowStart: new Date().getTime()
}
currentTimeWindowStart: new Date().getTime(),
};
}
return state;
}
Expand Down

0 comments on commit f542f5e

Please sign in to comment.