Skip to content

Commit

Permalink
fix(settings): select proper brain model (#943)
Browse files Browse the repository at this point in the history
* fix(settings): select proper brain model

* feat(settings): save model on change
  • Loading branch information
B0rrA authored Aug 18, 2023
1 parent d1dfd6c commit 3a44f54
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export const SettingsTab = ({ brainId }: SettingsTabProps): JSX.Element => {
<form
onSubmit={(e) => {
e.preventDefault();
void handleSubmit();
void handleSubmit(true);
}}
className="my-10 mb-0 flex flex-col items-center gap-2"
ref={formRef}
Expand Down Expand Up @@ -101,6 +101,9 @@ export const SettingsTab = ({ brainId }: SettingsTabProps): JSX.Element => {
id="model"
{...register("model")}
className="px-5 py-2 dark:bg-gray-700 bg-gray-200 rounded-md"
onChange={() => {
void handleSubmit(false); // Trigger form submission
}}
>
{(openAiKey !== undefined ? paidModels : freeModels).map(
(availableModel) => (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,13 @@ export const useSettingsTab = ({ brainId }: UseSettingsTabProps) => {
// eslint-disable-next-line
if (Boolean(brain[key])) setValue(key, brain[key]);
}

setTimeout(() => {
if (brain.model !== undefined) {
setValue("model", brain.model);
}
},50);

};
useEffect(() => {
void fetchBrain();
Expand All @@ -103,7 +110,7 @@ export const useSettingsTab = ({ brainId }: UseSettingsTabProps) => {
const handleKeyPress = (event: KeyboardEvent) => {
if (event.key === "Enter") {
event.preventDefault();
void handleSubmit();
void handleSubmit(true);
}
};

Expand Down Expand Up @@ -196,10 +203,9 @@ export const useSettingsTab = ({ brainId }: UseSettingsTabProps) => {
}
};

const handleSubmit = async () => {
const handleSubmit = async (checkDirty:boolean) => {
const hasChanges = Object.keys(dirtyFields).length > 0;

if (!hasChanges) {
if (!hasChanges && checkDirty) {
return;
}
const { name: isNameDirty } = dirtyFields;
Expand Down

0 comments on commit 3a44f54

Please sign in to comment.