Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
fix(kit): await conversations in server load function again
Browse files
src/lib/components/MobileNav.svelte
CHANGED
@@ -10,7 +10,7 @@
|
|
10 |
import IconNew from "$lib/components/icons/IconNew.svelte";
|
11 |
|
12 |
export let isOpen = false;
|
13 |
-
export let title:
|
14 |
|
15 |
$: title = title ?? "New Chat";
|
16 |
|
|
|
10 |
import IconNew from "$lib/components/icons/IconNew.svelte";
|
11 |
|
12 |
export let isOpen = false;
|
13 |
+
export let title: string | undefined;
|
14 |
|
15 |
$: title = title ?? "New Chat";
|
16 |
|
src/lib/components/NavMenu.svelte
CHANGED
@@ -11,7 +11,7 @@
|
|
11 |
import type { Model } from "$lib/types/Model";
|
12 |
import { page } from "$app/stores";
|
13 |
|
14 |
-
export let conversations:
|
15 |
export let canLogin: boolean;
|
16 |
export let user: LayoutData["user"];
|
17 |
|
@@ -25,16 +25,16 @@
|
|
25 |
new Date().setMonth(new Date().getMonth() - 1),
|
26 |
];
|
27 |
|
28 |
-
$: groupedConversations =
|
29 |
-
today:
|
30 |
-
week:
|
31 |
({ updatedAt }) => updatedAt.getTime() > dateRanges[1] && updatedAt.getTime() < dateRanges[0]
|
32 |
),
|
33 |
-
month:
|
34 |
({ updatedAt }) => updatedAt.getTime() > dateRanges[2] && updatedAt.getTime() < dateRanges[1]
|
35 |
),
|
36 |
-
older:
|
37 |
-
}
|
38 |
|
39 |
const titles: { [key: string]: string } = {
|
40 |
today: "Today",
|
|
|
11 |
import type { Model } from "$lib/types/Model";
|
12 |
import { page } from "$app/stores";
|
13 |
|
14 |
+
export let conversations: ConvSidebar[];
|
15 |
export let canLogin: boolean;
|
16 |
export let user: LayoutData["user"];
|
17 |
|
|
|
25 |
new Date().setMonth(new Date().getMonth() - 1),
|
26 |
];
|
27 |
|
28 |
+
$: groupedConversations = {
|
29 |
+
today: conversations.filter(({ updatedAt }) => updatedAt.getTime() > dateRanges[0]),
|
30 |
+
week: conversations.filter(
|
31 |
({ updatedAt }) => updatedAt.getTime() > dateRanges[1] && updatedAt.getTime() < dateRanges[0]
|
32 |
),
|
33 |
+
month: conversations.filter(
|
34 |
({ updatedAt }) => updatedAt.getTime() > dateRanges[2] && updatedAt.getTime() < dateRanges[1]
|
35 |
),
|
36 |
+
older: conversations.filter(({ updatedAt }) => updatedAt.getTime() < dateRanges[2]),
|
37 |
+
};
|
38 |
|
39 |
const titles: { [key: string]: string } = {
|
40 |
today: "Today",
|
src/routes/+layout.server.ts
CHANGED
@@ -146,7 +146,7 @@ export const load: LayoutServerLoad = async ({ locals, depends }) => {
|
|
146 |
|
147 |
return {
|
148 |
nConversations,
|
149 |
-
conversations: conversations.then(
|
150 |
async (convs) =>
|
151 |
await Promise.all(
|
152 |
convs.map(async (conv) => {
|
|
|
146 |
|
147 |
return {
|
148 |
nConversations,
|
149 |
+
conversations: await conversations.then(
|
150 |
async (convs) =>
|
151 |
await Promise.all(
|
152 |
convs.map(async (conv) => {
|
src/routes/+layout.svelte
CHANGED
@@ -58,10 +58,7 @@
|
|
58 |
return;
|
59 |
}
|
60 |
|
61 |
-
data.conversations.
|
62 |
-
const newConvs = convs.filter((conv) => conv.id !== id);
|
63 |
-
data.conversations = Promise.resolve(newConvs);
|
64 |
-
});
|
65 |
|
66 |
if ($page.params.id === id) {
|
67 |
await goto(`${base}/`, { invalidateAll: true });
|
@@ -87,10 +84,9 @@
|
|
87 |
return;
|
88 |
}
|
89 |
|
90 |
-
data.conversations.
|
91 |
-
|
92 |
-
|
93 |
-
});
|
94 |
} catch (err) {
|
95 |
console.error(err);
|
96 |
$error = String(err);
|
@@ -104,17 +100,13 @@
|
|
104 |
$: if ($error) onError();
|
105 |
|
106 |
$: if ($titleUpdate) {
|
107 |
-
data.conversations.
|
108 |
-
const convIdx = convs.findIndex(({ id }) => id === $titleUpdate?.convId);
|
109 |
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
// update data.conversations
|
114 |
-
data.conversations = Promise.resolve([...convs]);
|
115 |
|
116 |
-
|
117 |
-
});
|
118 |
}
|
119 |
|
120 |
const settings = createSettingsStore(data.settings);
|
@@ -153,7 +145,7 @@
|
|
153 |
|
154 |
$: mobileNavTitle = ["/models", "/assistants", "/privacy"].includes($page.route.id ?? "")
|
155 |
? ""
|
156 |
-
: data.conversations.
|
157 |
</script>
|
158 |
|
159 |
<svelte:head>
|
|
|
58 |
return;
|
59 |
}
|
60 |
|
61 |
+
data.conversations = data.conversations.filter((conv) => conv.id !== id);
|
|
|
|
|
|
|
62 |
|
63 |
if ($page.params.id === id) {
|
64 |
await goto(`${base}/`, { invalidateAll: true });
|
|
|
84 |
return;
|
85 |
}
|
86 |
|
87 |
+
data.conversations = data.conversations.map((conv) =>
|
88 |
+
conv.id === id ? { ...conv, title } : conv
|
89 |
+
);
|
|
|
90 |
} catch (err) {
|
91 |
console.error(err);
|
92 |
$error = String(err);
|
|
|
100 |
$: if ($error) onError();
|
101 |
|
102 |
$: if ($titleUpdate) {
|
103 |
+
const convIdx = data.conversations.findIndex(({ id }) => id === $titleUpdate?.convId);
|
|
|
104 |
|
105 |
+
if (convIdx != -1) {
|
106 |
+
data.conversations[convIdx].title = $titleUpdate?.title ?? data.conversations[convIdx].title;
|
107 |
+
}
|
|
|
|
|
108 |
|
109 |
+
$titleUpdate = null;
|
|
|
110 |
}
|
111 |
|
112 |
const settings = createSettingsStore(data.settings);
|
|
|
145 |
|
146 |
$: mobileNavTitle = ["/models", "/assistants", "/privacy"].includes($page.route.id ?? "")
|
147 |
? ""
|
148 |
+
: data.conversations.find((conv) => conv.id === $page.params.id)?.title;
|
149 |
</script>
|
150 |
|
151 |
<svelte:head>
|
src/routes/conversation/[id]/+page.svelte
CHANGED
@@ -247,9 +247,7 @@
|
|
247 |
) {
|
248 |
$error = update.message ?? "An error has occurred";
|
249 |
} else if (update.type === MessageUpdateType.Title) {
|
250 |
-
const convInData =
|
251 |
-
convs.find(({ id }) => id === $page.params.id)
|
252 |
-
);
|
253 |
if (convInData) {
|
254 |
convInData.title = update.title;
|
255 |
|
@@ -378,9 +376,7 @@
|
|
378 |
}
|
379 |
|
380 |
$: $page.params.id, (($isAborted = true), (loading = false), ($convTreeStore.editing = null));
|
381 |
-
$: title = data.conversations.
|
382 |
-
(convs) => convs.find((conv) => conv.id === $page.params.id)?.title ?? data.title
|
383 |
-
);
|
384 |
|
385 |
const convTreeStore = createConvTreeStore();
|
386 |
const settings = useSettingsStore();
|
|
|
247 |
) {
|
248 |
$error = update.message ?? "An error has occurred";
|
249 |
} else if (update.type === MessageUpdateType.Title) {
|
250 |
+
const convInData = data.conversations.find(({ id }) => id === $page.params.id);
|
|
|
|
|
251 |
if (convInData) {
|
252 |
convInData.title = update.title;
|
253 |
|
|
|
376 |
}
|
377 |
|
378 |
$: $page.params.id, (($isAborted = true), (loading = false), ($convTreeStore.editing = null));
|
379 |
+
$: title = data.conversations.find((conv) => conv.id === $page.params.id)?.title ?? data.title;
|
|
|
|
|
380 |
|
381 |
const convTreeStore = createConvTreeStore();
|
382 |
const settings = useSettingsStore();
|