Skip to content

Commit

Permalink
✨ Fix reset
Browse files Browse the repository at this point in the history
  • Loading branch information
asim-shrestha committed Apr 29, 2023
1 parent e514f28 commit 4e83cd0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
2 changes: 0 additions & 2 deletions src/components/SettingsDialog.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import React, { useEffect } from "react";
import { useTranslation } from "next-i18next";
import Button from "./Button";
import {
FaKey,
Expand Down Expand Up @@ -63,7 +62,6 @@ export const SettingsDialog: React.FC<{

const handleReset = () => {
customSettings.resetSettings();
updateSettings("customApiKey", "");
close();
};

Expand Down
18 changes: 10 additions & 8 deletions src/hooks/useSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,33 +16,35 @@ const DEFAULT_SETTINGS: ModelSettings = {
};

const loadSettings = () => {
const settings = { ...DEFAULT_SETTINGS };

if (typeof window === "undefined") {
return DEFAULT_SETTINGS;
return settings;
}

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

try {
const obj = JSON.parse(data) as ModelSettings;
Object.entries(obj).forEach(([key, value]) => {
if (DEFAULT_SETTINGS.hasOwnProperty(key)) {
if (settings.hasOwnProperty(key)) {
// @ts-ignore
DEFAULT_SETTINGS[key] = value;
settings[key] = value;
}
});
} catch (error) {}

if (
DEFAULT_SETTINGS.customApiKey &&
DEFAULT_SETTINGS.customMaxLoops === DEFAULT_MAX_LOOPS_FREE
settings.customApiKey &&
settings.customMaxLoops === DEFAULT_MAX_LOOPS_FREE
) {
DEFAULT_SETTINGS.customMaxLoops = DEFAULT_MAX_LOOPS_CUSTOM_API_KEY;
settings.customMaxLoops = DEFAULT_MAX_LOOPS_CUSTOM_API_KEY;
}

return DEFAULT_SETTINGS;
return settings;
};

export function useSettings(): SettingModel {
Expand Down

1 comment on commit 4e83cd0

@vercel
Copy link

@vercel vercel bot commented on 4e83cd0 Apr 29, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.