Skip to content

Commit cdb33a9

Browse files
nsarrazinMishig
andauthored
Apply settings without reloading the page (#682)
* Invalidate conversation list when settings update * improve trimming on conv titles * Update src/routes/+layout.server.ts Co-authored-by: Mishig <mishig.davaadorj@coloradocollege.edu> --------- Co-authored-by: Mishig <mishig.davaadorj@coloradocollege.edu>
1 parent 884fe73 commit cdb33a9

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

src/lib/stores/settings.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { browser } from "$app/environment";
2+
import { invalidate } from "$app/navigation";
23
import { base } from "$app/paths";
4+
import { UrlDependency } from "$lib/types/UrlDependency";
35
import { getContext, setContext } from "svelte";
46
import { type Writable, writable, get } from "svelte/store";
57

@@ -53,6 +55,7 @@ export function createSettingsStore(initialValue: Omit<SettingsStore, "recentlyS
5355
recentlySaved: false,
5456
}));
5557
}, 3000);
58+
invalidate(UrlDependency.ConversationList);
5659
}, 300);
5760
// debounce server calls by 300ms
5861
}

src/routes/+layout.server.ts

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,21 @@ export const load: LayoutServerLoad = async ({ locals, depends }) => {
7070
updatedAt: 1,
7171
createdAt: 1,
7272
})
73-
.map((conv) => ({
74-
id: conv._id.toString(),
75-
title: settings?.hideEmojiOnSidebar ? conv.title.replace(/\p{Emoji}/gu, "") : conv.title,
76-
model: conv.model ?? defaultModel,
77-
updatedAt: conv.updatedAt,
78-
}))
73+
.map((conv) => {
74+
// remove emojis if settings say so
75+
if (settings?.hideEmojiOnSidebar) {
76+
conv.title = conv.title.replace(/\p{Emoji}/gu, "");
77+
}
78+
79+
// remove invalid unicode and trim whitespaces
80+
conv.title = conv.title.replace(/\uFFFD/gu, "").trimStart();
81+
return {
82+
id: conv._id.toString(),
83+
title: settings?.hideEmojiOnSidebar ? conv.title.replace(/\p{Emoji}/gu, "") : conv.title,
84+
model: conv.model ?? defaultModel,
85+
updatedAt: conv.updatedAt,
86+
};
87+
})
7988
.toArray(),
8089
settings: {
8190
searchEnabled: !!(

0 commit comments

Comments
 (0)