Skip to content

Commit

Permalink
Apply settings without reloading the page (#682)
Browse files Browse the repository at this point in the history
* Invalidate conversation list when settings update

* improve trimming on conv titles

* Update src/routes/+layout.server.ts

Co-authored-by: Mishig <[email protected]>

---------

Co-authored-by: Mishig <[email protected]>
  • Loading branch information
nsarrazin and Mishig authored Jan 8, 2024
1 parent 884fe73 commit cdb33a9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
3 changes: 3 additions & 0 deletions src/lib/stores/settings.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { browser } from "$app/environment";
import { invalidate } from "$app/navigation";
import { base } from "$app/paths";
import { UrlDependency } from "$lib/types/UrlDependency";
import { getContext, setContext } from "svelte";
import { type Writable, writable, get } from "svelte/store";

Expand Down Expand Up @@ -53,6 +55,7 @@ export function createSettingsStore(initialValue: Omit<SettingsStore, "recentlyS
recentlySaved: false,
}));
}, 3000);
invalidate(UrlDependency.ConversationList);
}, 300);
// debounce server calls by 300ms
}
Expand Down
21 changes: 15 additions & 6 deletions src/routes/+layout.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,21 @@ export const load: LayoutServerLoad = async ({ locals, depends }) => {
updatedAt: 1,
createdAt: 1,
})
.map((conv) => ({
id: conv._id.toString(),
title: settings?.hideEmojiOnSidebar ? conv.title.replace(/\p{Emoji}/gu, "") : conv.title,
model: conv.model ?? defaultModel,
updatedAt: conv.updatedAt,
}))
.map((conv) => {
// remove emojis if settings say so
if (settings?.hideEmojiOnSidebar) {
conv.title = conv.title.replace(/\p{Emoji}/gu, "");
}

// remove invalid unicode and trim whitespaces
conv.title = conv.title.replace(/\uFFFD/gu, "").trimStart();
return {
id: conv._id.toString(),
title: settings?.hideEmojiOnSidebar ? conv.title.replace(/\p{Emoji}/gu, "") : conv.title,
model: conv.model ?? defaultModel,
updatedAt: conv.updatedAt,
};
})
.toArray(),
settings: {
searchEnabled: !!(
Expand Down

0 comments on commit cdb33a9

Please sign in to comment.