|
15 | 15 | clickLogout: void;
|
16 | 16 | }>();
|
17 | 17 |
|
18 |
| - export let conversations: Array<{ |
| 18 | + interface Conv { |
19 | 19 | id: string;
|
20 | 20 | title: string;
|
21 |
| - }> = []; |
| 21 | + updatedAt: Date; |
| 22 | + } |
22 | 23 |
|
| 24 | + export let conversations: Array<Conv> = []; |
23 | 25 | export let canLogin: boolean;
|
24 | 26 | export let user: LayoutData["user"];
|
25 | 27 |
|
26 | 28 | function handleNewChatClick() {
|
27 | 29 | isAborted.set(true);
|
28 | 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; |
29 | 55 | </script>
|
30 | 56 |
|
31 | 57 | <div class="sticky top-0 flex flex-none items-center justify-between px-3 py-3.5 max-sm:pt-0">
|
|
42 | 68 | </a>
|
43 | 69 | </div>
|
44 | 70 | <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" |
46 | 72 | >
|
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} |
49 | 82 | {/each}
|
50 | 83 | </div>
|
51 | 84 | <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" |
53 | 86 | >
|
54 | 87 | {#if user?.username || user?.email}
|
55 | 88 | <form
|
56 | 89 | action="{base}/logout"
|
57 | 90 | 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" |
59 | 92 | >
|
60 | 93 | <span
|
61 | 94 | class="flex h-9 flex-none shrink items-center gap-1.5 truncate pr-2 text-gray-500 dark:text-gray-400"
|
|
73 | 106 | <form action="{base}/login" method="POST" target="_parent">
|
74 | 107 | <button
|
75 | 108 | 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" |
77 | 110 | >
|
78 | 111 | Login
|
79 | 112 | </button>
|
|
82 | 115 | <button
|
83 | 116 | on:click={switchTheme}
|
84 | 117 | 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" |
86 | 119 | >
|
87 | 120 | Theme
|
88 | 121 | </button>
|
89 | 122 | <button
|
90 | 123 | on:click={() => dispatch("clickSettings")}
|
91 | 124 | 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" |
93 | 126 | >
|
94 | 127 | Settings
|
95 | 128 | </button>
|
|
98 | 131 | href="https://huggingface.co/spaces/huggingchat/chat-ui/discussions"
|
99 | 132 | target="_blank"
|
100 | 133 | 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" |
102 | 135 | >
|
103 | 136 | Feedback
|
104 | 137 | </a>
|
105 | 138 | <a
|
106 | 139 | 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" |
108 | 141 | >
|
109 | 142 | About & Privacy
|
110 | 143 | </a>
|
|
0 commit comments