Skip to content

Commit

Permalink
persist expanded engines (closes #232)
Browse files Browse the repository at this point in the history
  • Loading branch information
franciscoBSalgueiro committed Mar 1, 2024
1 parent 41ea97b commit b5ca713
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
11 changes: 8 additions & 3 deletions src/atoms/atoms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,9 +205,9 @@ export const missingMovesAtom = atomWithStorage<TabMap<MissingMove[] | null>>(
createJSONStorage(() => sessionStorage),
);

function tabValue<T extends object | string | boolean | number>(
family: AtomFamily<string, PrimitiveAtom<T>>,
) {
function tabValue<
T extends object | string | boolean | number | null | undefined,
>(family: AtomFamily<string, PrimitiveAtom<T>>) {
return atom(
(get) => {
const tab = get(currentTabAtom);
Expand Down Expand Up @@ -283,6 +283,11 @@ export const currentDbTabAtom = tabValue(dbTabFamily);
const analysisTabFamily = atomFamily((tab: string) => atom("engines"));
export const currentAnalysisTabAtom = tabValue(analysisTabFamily);

const expandedEnginesFamily = atomFamily((tab: string) =>
atom<string[] | undefined>(undefined),
);
export const currentExpandedEnginesAtom = tabValue(expandedEnginesFamily);

const pgnOptionsFamily = atomFamily((tab: string) =>
atom({
comments: true,
Expand Down
5 changes: 4 additions & 1 deletion src/components/panels/analysis/AnalysisPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {
activeTabAtom,
allEnabledAtom,
currentAnalysisTabAtom,
currentExpandedEnginesAtom,
enableAllAtom,
engineMovesFamily,
enginesAtom,
Expand Down Expand Up @@ -74,6 +75,7 @@ function AnalysisPanel({
allEnabledLoader.state === "hasData" && allEnabledLoader.data;

const [tab, setTab] = useAtom(currentAnalysisTabAtom);
const [expanded, setExpanded] = useAtom(currentExpandedEnginesAtom);

const stats = useMemo(() => getGameStats(root), [root]);
const is960 = useMemo(() => headers.variant === "Chess960", [headers]);
Expand All @@ -90,7 +92,6 @@ function AnalysisPanel({
<Stack h="100%">
<Tabs
h="100%"
defaultValue="engines"
orientation="vertical"
placement="right"
value={tab}
Expand Down Expand Up @@ -165,6 +166,8 @@ function AnalysisPanel({
multiple
chevronSize={0}
defaultValue={loadedEngines.map((e) => e.name)}
value={expanded}
onChange={(v) => setExpanded(v)}
styles={{
label: {
paddingTop: 0,
Expand Down

0 comments on commit b5ca713

Please sign in to comment.