Group conversations by date + small nav fixes (#582)
Browse files* fix: get rid of duplicate gradient in mobile nav
fix: remove top rounded corned in mobile nav
* feat: tighten navigation
* fix: gradients on mobile
* feat: group conversations by date
* ui tweaks
* refacto
- remove reduce
---------
Co-authored-by: Victor Mustar <[email protected]>
src/lib/components/MobileNav.svelte
CHANGED
@@ -45,7 +45,7 @@
|
|
45 |
>
|
46 |
</nav>
|
47 |
<nav
|
48 |
-
class="fixed inset-0 z-30 grid max-h-screen grid-cols-1 grid-rows-[auto,auto,1fr,auto] bg-white
|
49 |
? 'block'
|
50 |
: 'hidden'}"
|
51 |
>
|
|
|
45 |
>
|
46 |
</nav>
|
47 |
<nav
|
48 |
+
class="fixed inset-0 z-30 grid max-h-screen grid-cols-1 grid-rows-[auto,auto,1fr,auto] bg-white dark:bg-gray-900 {isOpen
|
49 |
? 'block'
|
50 |
: 'hidden'}"
|
51 |
>
|
src/lib/components/NavConversationItem.svelte
CHANGED
@@ -24,7 +24,7 @@
|
|
24 |
confirmDelete = false;
|
25 |
}}
|
26 |
href="{base}/conversation/{conv.id}"
|
27 |
-
class="group flex h-
|
28 |
$page.params.id
|
29 |
? 'bg-gray-100 dark:bg-gray-700'
|
30 |
: ''}"
|
|
|
24 |
confirmDelete = false;
|
25 |
}}
|
26 |
href="{base}/conversation/{conv.id}"
|
27 |
+
class="group flex h-10 flex-none items-center gap-1.5 rounded-lg pl-2.5 pr-2 text-gray-600 hover:bg-gray-100 dark:text-gray-300 dark:hover:bg-gray-700 {conv.id ===
|
28 |
$page.params.id
|
29 |
? 'bg-gray-100 dark:bg-gray-700'
|
30 |
: ''}"
|
src/lib/components/NavMenu.svelte
CHANGED
@@ -15,17 +15,43 @@
|
|
15 |
clickLogout: void;
|
16 |
}>();
|
17 |
|
18 |
-
|
19 |
id: string;
|
20 |
title: string;
|
21 |
-
|
|
|
22 |
|
|
|
23 |
export let canLogin: boolean;
|
24 |
export let user: LayoutData["user"];
|
25 |
|
26 |
function handleNewChatClick() {
|
27 |
isAborted.set(true);
|
28 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
29 |
</script>
|
30 |
|
31 |
<div class="sticky top-0 flex flex-none items-center justify-between px-3 py-3.5 max-sm:pt-0">
|
@@ -42,20 +68,27 @@
|
|
42 |
</a>
|
43 |
</div>
|
44 |
<div
|
45 |
-
class="scrollbar-custom flex flex-col gap-1 overflow-y-auto rounded-r-xl
|
46 |
>
|
47 |
-
{#each
|
48 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
49 |
{/each}
|
50 |
</div>
|
51 |
<div
|
52 |
-
class="mt-0.5 flex flex-col gap-1 rounded-r-xl bg-gradient-to-l from-gray-50
|
53 |
>
|
54 |
{#if user?.username || user?.email}
|
55 |
<form
|
56 |
action="{base}/logout"
|
57 |
method="post"
|
58 |
-
class="group flex items-center gap-1.5 rounded-lg pl-
|
59 |
>
|
60 |
<span
|
61 |
class="flex h-9 flex-none shrink items-center gap-1.5 truncate pr-2 text-gray-500 dark:text-gray-400"
|
@@ -73,7 +106,7 @@
|
|
73 |
<form action="{base}/login" method="POST" target="_parent">
|
74 |
<button
|
75 |
type="submit"
|
76 |
-
class="flex h-9 w-full flex-none items-center gap-1.5 rounded-lg pl-
|
77 |
>
|
78 |
Login
|
79 |
</button>
|
@@ -82,14 +115,14 @@
|
|
82 |
<button
|
83 |
on:click={switchTheme}
|
84 |
type="button"
|
85 |
-
class="flex h-9 flex-none items-center gap-1.5 rounded-lg pl-
|
86 |
>
|
87 |
Theme
|
88 |
</button>
|
89 |
<button
|
90 |
on:click={() => dispatch("clickSettings")}
|
91 |
type="button"
|
92 |
-
class="flex h-9 flex-none items-center gap-1.5 rounded-lg pl-
|
93 |
>
|
94 |
Settings
|
95 |
</button>
|
@@ -98,13 +131,13 @@
|
|
98 |
href="https://huggingface.co/spaces/huggingchat/chat-ui/discussions"
|
99 |
target="_blank"
|
100 |
rel="noreferrer"
|
101 |
-
class="flex h-9 flex-none items-center gap-1.5 rounded-lg pl-
|
102 |
>
|
103 |
Feedback
|
104 |
</a>
|
105 |
<a
|
106 |
href="{base}/privacy"
|
107 |
-
class="flex h-9 flex-none items-center gap-1.5 rounded-lg pl-
|
108 |
>
|
109 |
About & Privacy
|
110 |
</a>
|
|
|
15 |
clickLogout: void;
|
16 |
}>();
|
17 |
|
18 |
+
interface Conv {
|
19 |
id: string;
|
20 |
title: string;
|
21 |
+
updatedAt: Date;
|
22 |
+
}
|
23 |
|
24 |
+
export let conversations: Array<Conv> = [];
|
25 |
export let canLogin: boolean;
|
26 |
export let user: LayoutData["user"];
|
27 |
|
28 |
function handleNewChatClick() {
|
29 |
isAborted.set(true);
|
30 |
}
|
31 |
+
|
32 |
+
const dateRanges = [
|
33 |
+
new Date().setDate(new Date().getDate() - 1),
|
34 |
+
new Date().setDate(new Date().getDate() - 7),
|
35 |
+
new Date().setMonth(new Date().getMonth() - 1),
|
36 |
+
];
|
37 |
+
|
38 |
+
$: groupedConversations = {
|
39 |
+
today: conversations.filter(({ updatedAt }) => updatedAt.getTime() > dateRanges[0]),
|
40 |
+
week: conversations.filter(
|
41 |
+
({ updatedAt }) => updatedAt.getTime() > dateRanges[1] && updatedAt.getTime() < dateRanges[0]
|
42 |
+
),
|
43 |
+
month: conversations.filter(
|
44 |
+
({ updatedAt }) => updatedAt.getTime() > dateRanges[2] && updatedAt.getTime() < dateRanges[1]
|
45 |
+
),
|
46 |
+
older: conversations.filter(({ updatedAt }) => updatedAt.getTime() < dateRanges[2]),
|
47 |
+
};
|
48 |
+
|
49 |
+
const titles: { [key: string]: string } = {
|
50 |
+
today: "Today",
|
51 |
+
week: "This week",
|
52 |
+
month: "This month",
|
53 |
+
older: "Older",
|
54 |
+
} as const;
|
55 |
</script>
|
56 |
|
57 |
<div class="sticky top-0 flex flex-none items-center justify-between px-3 py-3.5 max-sm:pt-0">
|
|
|
68 |
</a>
|
69 |
</div>
|
70 |
<div
|
71 |
+
class="scrollbar-custom flex flex-col gap-1 overflow-y-auto rounded-r-xl from-gray-50 px-3 pb-3 pt-2 dark:from-gray-800/30 max-sm:bg-gradient-to-t md:bg-gradient-to-l"
|
72 |
>
|
73 |
+
{#each Object.entries(groupedConversations) as [group, convs]}
|
74 |
+
{#if convs.length}
|
75 |
+
<h4 class="mb-1.5 mt-4 pl-0.5 text-sm text-gray-400 first:mt-0 dark:text-gray-500">
|
76 |
+
{titles[group]}
|
77 |
+
</h4>
|
78 |
+
{#each convs as conv}
|
79 |
+
<NavConversationItem on:editConversationTitle on:deleteConversation {conv} />
|
80 |
+
{/each}
|
81 |
+
{/if}
|
82 |
{/each}
|
83 |
</div>
|
84 |
<div
|
85 |
+
class="mt-0.5 flex flex-col gap-1 rounded-r-xl p-3 text-sm md:bg-gradient-to-l md:from-gray-50 md:dark:from-gray-800/30"
|
86 |
>
|
87 |
{#if user?.username || user?.email}
|
88 |
<form
|
89 |
action="{base}/logout"
|
90 |
method="post"
|
91 |
+
class="group flex items-center gap-1.5 rounded-lg pl-2.5 pr-2 hover:bg-gray-100 dark:hover:bg-gray-700"
|
92 |
>
|
93 |
<span
|
94 |
class="flex h-9 flex-none shrink items-center gap-1.5 truncate pr-2 text-gray-500 dark:text-gray-400"
|
|
|
106 |
<form action="{base}/login" method="POST" target="_parent">
|
107 |
<button
|
108 |
type="submit"
|
109 |
+
class="flex h-9 w-full flex-none items-center gap-1.5 rounded-lg pl-2.5 pr-2 text-gray-500 hover:bg-gray-100 dark:text-gray-400 dark:hover:bg-gray-700"
|
110 |
>
|
111 |
Login
|
112 |
</button>
|
|
|
115 |
<button
|
116 |
on:click={switchTheme}
|
117 |
type="button"
|
118 |
+
class="flex h-9 flex-none items-center gap-1.5 rounded-lg pl-2.5 pr-2 text-gray-500 hover:bg-gray-100 dark:text-gray-400 dark:hover:bg-gray-700"
|
119 |
>
|
120 |
Theme
|
121 |
</button>
|
122 |
<button
|
123 |
on:click={() => dispatch("clickSettings")}
|
124 |
type="button"
|
125 |
+
class="flex h-9 flex-none items-center gap-1.5 rounded-lg pl-2.5 pr-2 text-gray-500 hover:bg-gray-100 dark:text-gray-400 dark:hover:bg-gray-700"
|
126 |
>
|
127 |
Settings
|
128 |
</button>
|
|
|
131 |
href="https://huggingface.co/spaces/huggingchat/chat-ui/discussions"
|
132 |
target="_blank"
|
133 |
rel="noreferrer"
|
134 |
+
class="flex h-9 flex-none items-center gap-1.5 rounded-lg pl-2.5 pr-2 text-gray-500 hover:bg-gray-100 dark:text-gray-400 dark:hover:bg-gray-700"
|
135 |
>
|
136 |
Feedback
|
137 |
</a>
|
138 |
<a
|
139 |
href="{base}/privacy"
|
140 |
+
class="flex h-9 flex-none items-center gap-1.5 rounded-lg pl-2.5 pr-2 text-gray-500 hover:bg-gray-100 dark:text-gray-400 dark:hover:bg-gray-700"
|
141 |
>
|
142 |
About & Privacy
|
143 |
</a>
|
src/routes/+layout.server.ts
CHANGED
@@ -79,6 +79,7 @@ export const load: LayoutServerLoad = async ({ locals, depends, url }) => {
|
|
79 |
id: conv._id.toString(),
|
80 |
title: settings?.hideEmojiOnSidebar ? conv.title.replace(/\p{Emoji}/gu, "") : conv.title,
|
81 |
model: conv.model ?? defaultModel,
|
|
|
82 |
}))
|
83 |
.toArray(),
|
84 |
settings: {
|
|
|
79 |
id: conv._id.toString(),
|
80 |
title: settings?.hideEmojiOnSidebar ? conv.title.replace(/\p{Emoji}/gu, "") : conv.title,
|
81 |
model: conv.model ?? defaultModel,
|
82 |
+
updatedAt: conv.updatedAt,
|
83 |
}))
|
84 |
.toArray(),
|
85 |
settings: {
|