Skip to content

Commit

Permalink
feat: persist custom settings
Browse files Browse the repository at this point in the history
  • Loading branch information
awtkns committed Apr 22, 2023
1 parent f9f3776 commit 1630a95
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
3 changes: 2 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"@typescript-eslint/no-unsafe-member-access": "off",
"@typescript-eslint/no-unsafe-call": "off",
"@typescript-eslint/no-unsafe-assignment": "off",
"@typescript-eslint/no-unsafe-argument": "off"
"@typescript-eslint/no-unsafe-argument": "off",
"@typescript-eslint/ban-ts-comment": "off"
}
}
10 changes: 9 additions & 1 deletion src/hooks/useSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,15 @@ const loadSettings = () => {
}

const data = localStorage.getItem(SETTINGS_KEY);
if (!data) {
return DEFAULT_SETTINGS;
}

try {
const obj = JSON.parse(data) as ModelSettings;
Object.entries(obj).forEach(([key, value]) => {
if (DEFAULT_SETTINGS.hasOwnProperty(key)) {
// @ts-ignore
DEFAULT_SETTINGS[key] = value;
}
});
Expand All @@ -48,5 +53,8 @@ export function useSettings() {
localStorage.setItem(SETTINGS_KEY, JSON.stringify(settings));
};

return [settings, saveSettings];
return {
settings,
saveSettings,
};
}
8 changes: 4 additions & 4 deletions src/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const Home: NextPage = () => {
const [name, setName] = React.useState<string>("");
const [goalInput, setGoalInput] = React.useState<string>("");
const [agent, setAgent] = React.useState<AutonomousAgent | null>(null);
const [customSettings, setCustomSettings] = useSettings();
const { settings, saveSettings } = useSettings();
const [shouldAgentStop, setShouldAgentStop] = React.useState(false);
const [messages, setMessages] = React.useState<Message[]>([]);
const [showHelpDialog, setShowHelpDialog] = React.useState(false);
Expand Down Expand Up @@ -73,7 +73,7 @@ const Home: NextPage = () => {
goalInput.trim(),
handleAddMessage,
() => setAgent(null),
customSettings,
settings,
session ?? undefined
);
setAgent(agent);
Expand Down Expand Up @@ -119,7 +119,7 @@ const Home: NextPage = () => {
close={() => setShowHelpDialog(false)}
/>
<SettingsDialog
customSettings={[customSettings, setCustomSettings]}
customSettings={[settings, saveSettings]}
show={showSettingsDialog}
close={() => setShowSettingsDialog(false)}
/>
Expand Down Expand Up @@ -246,7 +246,7 @@ const Home: NextPage = () => {
<span className="ml-2">Stopping</span>
</>
) : (
<span>"Stop agent"</span>
<span>Stop agent</span>
)}
</Button>
</Expand>
Expand Down

0 comments on commit 1630a95

Please sign in to comment.