Skip to content

Commit

Permalink
add option to save engine settings as default (#92)
Browse files Browse the repository at this point in the history
  • Loading branch information
franciscoBSalgueiro authored Nov 13, 2023
1 parent 9f16a37 commit f58ea9b
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 19 deletions.
28 changes: 17 additions & 11 deletions src/atoms/atoms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,17 +247,23 @@ export type EngineSettings = {
};

export const tabEngineSettingsFamily = atomFamily(
({ tab, engine }: { tab: string; engine: string }) =>
atom<EngineSettings>({
enabled: false,
go: {
t: "Depth",
c: 24,
},
cores: 2,
numberLines: 3,
extraOptions: [],
}),
({ tab, engine }: { tab: string; engine: string }) => {
const savedDefault = localStorage.getItem(`engine-${engine}`);
return atom<EngineSettings>(
savedDefault !== null
? { ...JSON.parse(savedDefault), enabled: false } as EngineSettings
:
{
enabled: false,
go: {
t: "Depth",
c: 24,
},
cores: 2,
numberLines: 3,
extraOptions: [],
})
},
(a, b) => a.tab === b.tab && a.engine === b.engine
);

Expand Down
1 change: 1 addition & 0 deletions src/components/panels/analysis/BestMoves.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ export default function BestMovesComponent({
</ActionIcon>
</Box>
<EngineSettings
engine={engine.name}
settingsOn={settingsOn}
settings={settings}
setSettings={setSettings}
Expand Down
29 changes: 21 additions & 8 deletions src/components/panels/analysis/EngineSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@ import LinesSlider from "./LinesSlider";
import { IconPlus, IconX } from "@tabler/icons-react";

interface EngineSettingsProps {
engine: string;
settingsOn: boolean;
settings: EngineSettings;
setSettings: React.Dispatch<React.SetStateAction<EngineSettings>>;
}

function EngineSettings({
engine,
settingsOn,
settings,
setSettings,
Expand Down Expand Up @@ -93,14 +95,25 @@ function EngineSettings({
/>
</SimpleGrid>

<Button
variant="light"
size="xs"
mt="sm"
onClick={() => setAdvancedOptions(true)}
>
Advanced Options
</Button>
<Group>
<Button
variant="default"
size="xs"
mt="sm"
onClick={() => setAdvancedOptions(true)}
>
Advanced options
</Button>

<Button
size="xs"
mt="sm"
onClick={() => localStorage.setItem(`engine-${engine}`, JSON.stringify(settings))}
>
Save as default
</Button>
</Group>

</Collapse>
</>
);
Expand Down

0 comments on commit f58ea9b

Please sign in to comment.