nsarrazin HF staff Mishig commited on
Commit
cdb33a9
1 Parent(s): 884fe73

Apply settings without reloading the page (#682)

Browse files

* 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]>

src/lib/stores/settings.ts CHANGED
@@ -1,5 +1,7 @@
1
  import { browser } from "$app/environment";
 
2
  import { base } from "$app/paths";
 
3
  import { getContext, setContext } from "svelte";
4
  import { type Writable, writable, get } from "svelte/store";
5
 
@@ -53,6 +55,7 @@ export function createSettingsStore(initialValue: Omit<SettingsStore, "recentlyS
53
  recentlySaved: false,
54
  }));
55
  }, 3000);
 
56
  }, 300);
57
  // debounce server calls by 300ms
58
  }
 
1
  import { browser } from "$app/environment";
2
+ import { invalidate } from "$app/navigation";
3
  import { base } from "$app/paths";
4
+ import { UrlDependency } from "$lib/types/UrlDependency";
5
  import { getContext, setContext } from "svelte";
6
  import { type Writable, writable, get } from "svelte/store";
7
 
 
55
  recentlySaved: false,
56
  }));
57
  }, 3000);
58
+ invalidate(UrlDependency.ConversationList);
59
  }, 300);
60
  // debounce server calls by 300ms
61
  }
src/routes/+layout.server.ts CHANGED
@@ -70,12 +70,21 @@ export const load: LayoutServerLoad = async ({ locals, depends }) => {
70
  updatedAt: 1,
71
  createdAt: 1,
72
  })
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
- }))
 
 
 
 
 
 
 
 
 
79
  .toArray(),
80
  settings: {
81
  searchEnabled: !!(
 
70
  updatedAt: 1,
71
  createdAt: 1,
72
  })
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
+ })
88
  .toArray(),
89
  settings: {
90
  searchEnabled: !!(