Skip to content

Commit

Permalink
fix: saveSettings Thread only if value changed
Browse files Browse the repository at this point in the history
  • Loading branch information
mikbry authored Mar 11, 2024
2 parents 1a9af65 + e4f0a76 commit 1db0e9a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
14 changes: 9 additions & 5 deletions webapp/components/views/Threads/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import { ModalsContext } from '@/context/modals';
import { AppContext } from '@/context';
import { MenuAction, Page, ViewName } from '@/types/ui';
import { getAssistantId } from '@/utils/services';
import { deepEqual } from '@/utils/data';
import { ResizableHandle, ResizablePanel, ResizablePanelGroup } from '../../ui/resizable';
import Explorer from './Explorer';
import Settings from './Settings';
Expand Down Expand Up @@ -86,11 +87,14 @@ export default function Threads({ selectedThreadId, view = ViewName.Recent }: Th
if (settings.selectedPage) {
const pages = settings.pages || {};
const page = pages[currentPage] || DefaultPageSettings;
if (partialSettings) {
setSettings({
...settings,
pages: { ...pages, [currentPage]: { ...page, ...partialSettings } },
});
const newSettings = { ...page, ...partialSettings };
if (partialSettings && !deepEqual(newSettings, DefaultPageSettings)) {
if (!deepEqual(newSettings, page)) {
setSettings({
...settings,
pages: { ...pages, [currentPage]: newSettings },
});
}
} else if (pages[currentPage]) {
delete pages[currentPage];
setSettings({
Expand Down
5 changes: 1 addition & 4 deletions webapp/utils/data/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,7 @@ export const deepEqual = <T>(a: T, b: T): boolean => {
if (typeof a !== 'object' || typeof b !== 'object') return false;
if (a === null || b === null) return false;
if (a === undefined || b === undefined) return false;
if (
Array.isArray(a) === Array.isArray(b) &&
(a as unknown[]).length === (b as unknown[]).length
) {
if (Array.isArray(a) && Array.isArray(b) && (a as unknown[]).length === (b as unknown[]).length) {
return (a as unknown[]).every((v: unknown, i: number) => deepEqual(v, (b as unknown[])[i]));
}
if (Object.keys(a).length === Object.keys(b).length) {
Expand Down

0 comments on commit 1db0e9a

Please sign in to comment.