Skip to content

Commit

Permalink
persist report settings
Browse files Browse the repository at this point in the history
  • Loading branch information
franciscoBSalgueiro committed Feb 14, 2024
1 parent e6b66e1 commit e733f67
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions src/components/panels/analysis/ReportModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,15 @@ import {
Stack,
} from "@mantine/core";
import { useForm } from "@mantine/form";
import { useAtomValue } from "jotai";
import { memo, useContext } from "react";
import { useAtom, useAtomValue } from "jotai";
import { atomWithStorage } from "jotai/utils";
import { memo, useContext, useEffect } from "react";

const reportSettingsAtom = atomWithStorage("report-settings", {
novelty: true,
reversed: true,
goMode: { t: "Time", c: 500 } as Exclude<GoMode, { t: "Infinite" }>,
});

function ReportModal({
tab,
Expand All @@ -38,12 +45,17 @@ function ReportModal({
);
const dispatch = useContext(TreeDispatchContext);

useEffect(() => {
if (!form.values.engine && localEngines.length > 0) {
form.setFieldValue("engine", localEngines[0].path);
}
}, [localEngines.length]);
const [reportSettings, setReportSettings] = useAtom(reportSettingsAtom);

const form = useForm({
initialValues: {
engine: localEngines[0]?.path ?? "",
novelty: true,
reversed: true,
goMode: { t: "Time", c: 500 } as Exclude<GoMode, { t: "Infinite" }>,
...reportSettings,
engine: "",
},

validate: {
Expand All @@ -58,6 +70,7 @@ function ReportModal({
});

function analyze() {
setReportSettings(form.values);
setInProgress(true);
toggleReportingMode();
const engine = localEngines.find((e) => e.path === form.values.engine);
Expand Down

0 comments on commit e733f67

Please sign in to comment.