Skip to content

Commit 332d815

Browse files
nsarrazingary149
andauthored
Group conversations by date + small nav fixes (#582)
* 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 <victor.mustar@gmail.com>
1 parent cb29148 commit 332d815

File tree

4 files changed

+48
-14
lines changed

4 files changed

+48
-14
lines changed

src/lib/components/MobileNav.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
>
4646
</nav>
4747
<nav
48-
class="fixed inset-0 z-30 grid max-h-screen grid-cols-1 grid-rows-[auto,auto,1fr,auto] bg-white bg-gradient-to-l from-gray-50 dark:bg-gray-900 dark:from-gray-800/30 max-sm:rounded-t-2xl {isOpen
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
4949
? 'block'
5050
: 'hidden'}"
5151
>

src/lib/components/NavConversationItem.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
confirmDelete = false;
2525
}}
2626
href="{base}/conversation/{conv.id}"
27-
class="group flex h-11 flex-none items-center gap-1.5 rounded-lg pl-3 pr-2 text-gray-500 hover:bg-gray-100 dark:text-gray-400 dark:hover:bg-gray-700 {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 ===
2828
$page.params.id
2929
? 'bg-gray-100 dark:bg-gray-700'
3030
: ''}"

src/lib/components/NavMenu.svelte

Lines changed: 45 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,43 @@
1515
clickLogout: void;
1616
}>();
1717
18-
export let conversations: Array<{
18+
interface Conv {
1919
id: string;
2020
title: string;
21-
}> = [];
21+
updatedAt: Date;
22+
}
2223
24+
export let conversations: Array<Conv> = [];
2325
export let canLogin: boolean;
2426
export let user: LayoutData["user"];
2527
2628
function handleNewChatClick() {
2729
isAborted.set(true);
2830
}
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;
2955
</script>
3056

3157
<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 @@
4268
</a>
4369
</div>
4470
<div
45-
class="scrollbar-custom flex flex-col gap-1 overflow-y-auto rounded-r-xl bg-gradient-to-l from-gray-50 px-3 pb-3 pt-2 dark:from-gray-800/30"
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"
4672
>
47-
{#each conversations as conv (conv.id)}
48-
<NavConversationItem on:editConversationTitle on:deleteConversation {conv} />
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}
4982
{/each}
5083
</div>
5184
<div
52-
class="mt-0.5 flex flex-col gap-1 rounded-r-xl bg-gradient-to-l from-gray-50 p-3 text-sm dark:from-gray-800/30"
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"
5386
>
5487
{#if user?.username || user?.email}
5588
<form
5689
action="{base}/logout"
5790
method="post"
58-
class="group flex items-center gap-1.5 rounded-lg pl-3 pr-2 hover:bg-gray-100 dark:hover:bg-gray-700"
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"
5992
>
6093
<span
6194
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 @@
73106
<form action="{base}/login" method="POST" target="_parent">
74107
<button
75108
type="submit"
76-
class="flex h-9 w-full flex-none items-center gap-1.5 rounded-lg pl-3 pr-2 text-gray-500 hover:bg-gray-100 dark:text-gray-400 dark:hover:bg-gray-700"
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"
77110
>
78111
Login
79112
</button>
@@ -82,14 +115,14 @@
82115
<button
83116
on:click={switchTheme}
84117
type="button"
85-
class="flex h-9 flex-none items-center gap-1.5 rounded-lg pl-3 pr-2 text-gray-500 hover:bg-gray-100 dark:text-gray-400 dark:hover:bg-gray-700"
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"
86119
>
87120
Theme
88121
</button>
89122
<button
90123
on:click={() => dispatch("clickSettings")}
91124
type="button"
92-
class="flex h-9 flex-none items-center gap-1.5 rounded-lg pl-3 pr-2 text-gray-500 hover:bg-gray-100 dark:text-gray-400 dark:hover:bg-gray-700"
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"
93126
>
94127
Settings
95128
</button>
@@ -98,13 +131,13 @@
98131
href="https://huggingface.co/spaces/huggingchat/chat-ui/discussions"
99132
target="_blank"
100133
rel="noreferrer"
101-
class="flex h-9 flex-none items-center gap-1.5 rounded-lg pl-3 pr-2 text-gray-500 hover:bg-gray-100 dark:text-gray-400 dark:hover:bg-gray-700"
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"
102135
>
103136
Feedback
104137
</a>
105138
<a
106139
href="{base}/privacy"
107-
class="flex h-9 flex-none items-center gap-1.5 rounded-lg pl-3 pr-2 text-gray-500 hover:bg-gray-100 dark:text-gray-400 dark:hover:bg-gray-700"
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"
108141
>
109142
About & Privacy
110143
</a>

src/routes/+layout.server.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ export const load: LayoutServerLoad = async ({ locals, depends, url }) => {
7979
id: conv._id.toString(),
8080
title: settings?.hideEmojiOnSidebar ? conv.title.replace(/\p{Emoji}/gu, "") : conv.title,
8181
model: conv.model ?? defaultModel,
82+
updatedAt: conv.updatedAt,
8283
}))
8384
.toArray(),
8485
settings: {

0 commit comments

Comments
 (0)