Sidebar.svelte 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729
  1. <script lang="ts">
  2. import { goto } from '$app/navigation';
  3. import {
  4. user,
  5. chats,
  6. settings,
  7. showSettings,
  8. chatId,
  9. tags,
  10. showSidebar,
  11. mobile,
  12. showArchivedChats
  13. } from '$lib/stores';
  14. import { onMount, getContext } from 'svelte';
  15. const i18n = getContext('i18n');
  16. import {
  17. deleteChatById,
  18. getChatList,
  19. getChatById,
  20. getChatListByTagName,
  21. updateChatById,
  22. getAllChatTags,
  23. archiveChatById
  24. } from '$lib/apis/chats';
  25. import { toast } from 'svelte-sonner';
  26. import { fade, slide } from 'svelte/transition';
  27. import { WEBUI_BASE_URL } from '$lib/constants';
  28. import Tooltip from '../common/Tooltip.svelte';
  29. import ChatMenu from './Sidebar/ChatMenu.svelte';
  30. import ShareChatModal from '../chat/ShareChatModal.svelte';
  31. import ArchiveBox from '../icons/ArchiveBox.svelte';
  32. import ArchivedChatsModal from './Sidebar/ArchivedChatsModal.svelte';
  33. import UserMenu from './Sidebar/UserMenu.svelte';
  34. const BREAKPOINT = 768;
  35. let show = false;
  36. let navElement;
  37. let title: string = 'UI';
  38. let search = '';
  39. let shareChatId = null;
  40. let selectedChatId = null;
  41. let chatDeleteId = null;
  42. let chatTitleEditId = null;
  43. let chatTitle = '';
  44. let showShareChatModal = false;
  45. let showDropdown = false;
  46. let isEditing = false;
  47. let filteredChatList = [];
  48. $: filteredChatList = $chats.filter((chat) => {
  49. if (search === '') {
  50. return true;
  51. } else {
  52. let title = chat.title.toLowerCase();
  53. const query = search.toLowerCase();
  54. let contentMatches = false;
  55. // Access the messages within chat.chat.messages
  56. if (chat.chat && chat.chat.messages && Array.isArray(chat.chat.messages)) {
  57. contentMatches = chat.chat.messages.some((message) => {
  58. // Check if message.content exists and includes the search query
  59. return message.content && message.content.toLowerCase().includes(query);
  60. });
  61. }
  62. return title.includes(query) || contentMatches;
  63. }
  64. });
  65. onMount(async () => {
  66. showSidebar.set(window.innerWidth > BREAKPOINT);
  67. await chats.set(await getChatList(localStorage.token));
  68. let touchstart;
  69. let touchend;
  70. function checkDirection() {
  71. const screenWidth = window.innerWidth;
  72. const swipeDistance = Math.abs(touchend.screenX - touchstart.screenX);
  73. if (touchstart.clientX < 40 && swipeDistance >= screenWidth / 8) {
  74. if (touchend.screenX < touchstart.screenX) {
  75. showSidebar.set(false);
  76. }
  77. if (touchend.screenX > touchstart.screenX) {
  78. showSidebar.set(true);
  79. }
  80. }
  81. }
  82. const onTouchStart = (e) => {
  83. touchstart = e.changedTouches[0];
  84. console.log(touchstart.clientX);
  85. };
  86. const onTouchEnd = (e) => {
  87. touchend = e.changedTouches[0];
  88. checkDirection();
  89. };
  90. const onResize = () => {
  91. if ($showSidebar && window.innerWidth < BREAKPOINT) {
  92. showSidebar.set(false);
  93. }
  94. };
  95. window.addEventListener('touchstart', onTouchStart);
  96. window.addEventListener('touchend', onTouchEnd);
  97. window.addEventListener('resize', onResize);
  98. return () => {
  99. window.removeEventListener('touchstart', onTouchStart);
  100. window.removeEventListener('touchend', onTouchEnd);
  101. window.removeEventListener('resize', onResize);
  102. };
  103. });
  104. // Helper function to fetch and add chat content to each chat
  105. const enrichChatsWithContent = async (chatList) => {
  106. const enrichedChats = await Promise.all(
  107. chatList.map(async (chat) => {
  108. const chatDetails = await getChatById(localStorage.token, chat.id).catch((error) => null); // Handle error or non-existent chat gracefully
  109. if (chatDetails) {
  110. chat.chat = chatDetails.chat; // Assuming chatDetails.chat contains the chat content
  111. }
  112. return chat;
  113. })
  114. );
  115. await chats.set(enrichedChats);
  116. };
  117. const loadChat = async (id) => {
  118. goto(`/c/${id}`);
  119. };
  120. const editChatTitle = async (id, _title) => {
  121. if (_title === '') {
  122. toast.error($i18n.t('Title cannot be an empty string.'));
  123. } else {
  124. title = _title;
  125. await updateChatById(localStorage.token, id, {
  126. title: _title
  127. });
  128. await chats.set(await getChatList(localStorage.token));
  129. }
  130. };
  131. const deleteChat = async (id) => {
  132. const res = await deleteChatById(localStorage.token, id).catch((error) => {
  133. toast.error(error);
  134. chatDeleteId = null;
  135. return null;
  136. });
  137. if (res) {
  138. if ($chatId === id) {
  139. goto('/');
  140. }
  141. await chats.set(await getChatList(localStorage.token));
  142. }
  143. };
  144. const saveSettings = async (updated) => {
  145. await settings.set({ ...$settings, ...updated });
  146. localStorage.setItem('settings', JSON.stringify($settings));
  147. location.href = '/';
  148. };
  149. const archiveChatHandler = async (id) => {
  150. await archiveChatById(localStorage.token, id);
  151. await chats.set(await getChatList(localStorage.token));
  152. };
  153. </script>
  154. <ShareChatModal bind:show={showShareChatModal} chatId={shareChatId} />
  155. <ArchivedChatsModal
  156. bind:show={$showArchivedChats}
  157. on:change={async () => {
  158. await chats.set(await getChatList(localStorage.token));
  159. }}
  160. />
  161. <!-- svelte-ignore a11y-no-static-element-interactions -->
  162. {#if $showSidebar}
  163. <div
  164. class=" fixed md:hidden z-40 top-0 right-0 left-0 bottom-0 bg-black/60 w-full min-h-screen h-screen flex justify-center overflow-hidden overscroll-contain"
  165. on:mousedown={() => {
  166. showSidebar.set(!$showSidebar);
  167. }}
  168. />
  169. {/if}
  170. <div
  171. bind:this={navElement}
  172. id="sidebar"
  173. class="h-screen max-h-[100dvh] min-h-screen select-none {$showSidebar
  174. ? 'lg:relative w-[260px]'
  175. : '-translate-x-[260px] w-[0px]'} bg-gray-50 text-gray-900 dark:bg-gray-950 dark:text-gray-200 text-sm transition fixed z-50 top-0 left-0 rounded-r-2xl
  176. "
  177. data-state={$showSidebar}
  178. >
  179. <div
  180. class="py-2.5 my-auto flex flex-col justify-between h-screen max-h-[100dvh] w-[260px] z-50 {$showSidebar
  181. ? ''
  182. : 'invisible'}"
  183. >
  184. <div class="px-2.5 flex justify-between space-x-1 text-gray-600 dark:text-gray-400">
  185. <button
  186. class=" cursor-pointer px-2 py-2 flex rounded-xl hover:bg-gray-100 dark:hover:bg-gray-850 transition"
  187. on:click={() => {
  188. showSidebar.set(!$showSidebar);
  189. }}
  190. >
  191. <div class=" m-auto self-center">
  192. <svg
  193. xmlns="http://www.w3.org/2000/svg"
  194. fill="none"
  195. viewBox="0 0 24 24"
  196. stroke-width="2"
  197. stroke="currentColor"
  198. class="size-5"
  199. >
  200. <path
  201. stroke-linecap="round"
  202. stroke-linejoin="round"
  203. d="M3.75 6.75h16.5M3.75 12h16.5m-16.5 5.25H12"
  204. />
  205. </svg>
  206. </div>
  207. </button>
  208. <a
  209. id="sidebar-new-chat-button"
  210. class="flex justify-between rounded-xl px-2 py-2 hover:bg-gray-100 dark:hover:bg-gray-850 transition"
  211. href="/"
  212. on:click={async () => {
  213. selectedChatId = null;
  214. await goto('/');
  215. const newChatButton = document.getElementById('new-chat-button');
  216. setTimeout(() => {
  217. newChatButton?.click();
  218. if ($mobile) {
  219. showSidebar.set(false);
  220. }
  221. }, 0);
  222. }}
  223. >
  224. <div class="self-center">
  225. <svg
  226. xmlns="http://www.w3.org/2000/svg"
  227. viewBox="0 0 20 20"
  228. fill="currentColor"
  229. class="size-5"
  230. >
  231. <path
  232. d="M5.433 13.917l1.262-3.155A4 4 0 017.58 9.42l6.92-6.918a2.121 2.121 0 013 3l-6.92 6.918c-.383.383-.84.685-1.343.886l-3.154 1.262a.5.5 0 01-.65-.65z"
  233. />
  234. <path
  235. d="M3.5 5.75c0-.69.56-1.25 1.25-1.25H10A.75.75 0 0010 3H4.75A2.75 2.75 0 002 5.75v9.5A2.75 2.75 0 004.75 18h9.5A2.75 2.75 0 0017 15.25V10a.75.75 0 00-1.5 0v5.25c0 .69-.56 1.25-1.25 1.25h-9.5c-.69 0-1.25-.56-1.25-1.25v-9.5z"
  236. />
  237. </svg>
  238. </div>
  239. </a>
  240. </div>
  241. {#if $user?.role === 'admin'}
  242. <div class="px-2.5 flex justify-center text-gray-800 dark:text-gray-200">
  243. <a
  244. class="flex-grow flex space-x-3 rounded-xl px-2.5 py-2 hover:bg-gray-100 dark:hover:bg-gray-900 transition"
  245. href="/workspace"
  246. on:click={() => {
  247. selectedChatId = null;
  248. chatId.set('');
  249. }}
  250. >
  251. <div class="self-center">
  252. <svg
  253. xmlns="http://www.w3.org/2000/svg"
  254. fill="none"
  255. viewBox="0 0 24 24"
  256. stroke-width="2"
  257. stroke="currentColor"
  258. class="size-[1.1rem]"
  259. >
  260. <path
  261. stroke-linecap="round"
  262. stroke-linejoin="round"
  263. d="M13.5 16.875h3.375m0 0h3.375m-3.375 0V13.5m0 3.375v3.375M6 10.5h2.25a2.25 2.25 0 0 0 2.25-2.25V6a2.25 2.25 0 0 0-2.25-2.25H6A2.25 2.25 0 0 0 3.75 6v2.25A2.25 2.25 0 0 0 6 10.5Zm0 9.75h2.25A2.25 2.25 0 0 0 10.5 18v-2.25a2.25 2.25 0 0 0-2.25-2.25H6a2.25 2.25 0 0 0-2.25 2.25V18A2.25 2.25 0 0 0 6 20.25Zm9.75-9.75H18a2.25 2.25 0 0 0 2.25-2.25V6A2.25 2.25 0 0 0 18 3.75h-2.25A2.25 2.25 0 0 0 13.5 6v2.25a2.25 2.25 0 0 0 2.25 2.25Z"
  264. />
  265. </svg>
  266. </div>
  267. <div class="flex self-center">
  268. <div class=" self-center font-medium text-sm">{$i18n.t('Workspace')}</div>
  269. </div>
  270. </a>
  271. </div>
  272. {/if}
  273. <div class="relative flex flex-col flex-1 overflow-y-auto">
  274. {#if !($settings.saveChatHistory ?? true)}
  275. <div class="absolute z-40 w-full h-full bg-gray-50/90 dark:bg-black/90 flex justify-center">
  276. <div class=" text-left px-5 py-2">
  277. <div class=" font-medium">{$i18n.t('Chat History is off for this browser.')}</div>
  278. <div class="text-xs mt-2">
  279. {$i18n.t(
  280. "When history is turned off, new chats on this browser won't appear in your history on any of your devices."
  281. )}
  282. <span class=" font-semibold"
  283. >{$i18n.t('This setting does not sync across browsers or devices.')}</span
  284. >
  285. </div>
  286. <div class="mt-3">
  287. <button
  288. class="flex justify-center items-center space-x-1.5 px-3 py-2.5 rounded-lg text-xs bg-gray-100 hover:bg-gray-200 transition text-gray-800 font-medium w-full"
  289. type="button"
  290. on:click={() => {
  291. saveSettings({
  292. saveChatHistory: true
  293. });
  294. }}
  295. >
  296. <svg
  297. xmlns="http://www.w3.org/2000/svg"
  298. viewBox="0 0 16 16"
  299. fill="currentColor"
  300. class="w-3 h-3"
  301. >
  302. <path
  303. fill-rule="evenodd"
  304. d="M8 1a.75.75 0 0 1 .75.75v6.5a.75.75 0 0 1-1.5 0v-6.5A.75.75 0 0 1 8 1ZM4.11 3.05a.75.75 0 0 1 0 1.06 5.5 5.5 0 1 0 7.78 0 .75.75 0 0 1 1.06-1.06 7 7 0 1 1-9.9 0 .75.75 0 0 1 1.06 0Z"
  305. clip-rule="evenodd"
  306. />
  307. </svg>
  308. <div>{$i18n.t('Enable Chat History')}</div>
  309. </button>
  310. </div>
  311. </div>
  312. </div>
  313. {/if}
  314. <div class="px-2 mt-0.5 mb-2 flex justify-center space-x-2">
  315. <div class="flex w-full rounded-xl" id="chat-search">
  316. <div class="self-center pl-3 py-2 rounded-l-xl bg-transparent">
  317. <svg
  318. xmlns="http://www.w3.org/2000/svg"
  319. viewBox="0 0 20 20"
  320. fill="currentColor"
  321. class="w-4 h-4"
  322. >
  323. <path
  324. fill-rule="evenodd"
  325. d="M9 3.5a5.5 5.5 0 100 11 5.5 5.5 0 000-11zM2 9a7 7 0 1112.452 4.391l3.328 3.329a.75.75 0 11-1.06 1.06l-3.329-3.328A7 7 0 012 9z"
  326. clip-rule="evenodd"
  327. />
  328. </svg>
  329. </div>
  330. <input
  331. class="w-full rounded-r-xl py-1.5 pl-2.5 pr-4 text-sm bg-transparent dark:text-gray-300 outline-none"
  332. placeholder={$i18n.t('Search')}
  333. bind:value={search}
  334. on:focus={() => {
  335. enrichChatsWithContent($chats);
  336. }}
  337. />
  338. </div>
  339. </div>
  340. {#if $tags.length > 0}
  341. <div class="px-2.5 mb-2 flex gap-1 flex-wrap">
  342. <button
  343. class="px-2.5 text-xs font-medium bg-gray-50 dark:bg-gray-900 dark:hover:bg-gray-800 transition rounded-full"
  344. on:click={async () => {
  345. await chats.set(await getChatList(localStorage.token));
  346. }}
  347. >
  348. {$i18n.t('all')}
  349. </button>
  350. {#each $tags as tag}
  351. <button
  352. class="px-2.5 text-xs font-medium bg-gray-50 dark:bg-gray-900 dark:hover:bg-gray-800 transition rounded-full"
  353. on:click={async () => {
  354. let chatIds = await getChatListByTagName(localStorage.token, tag.name);
  355. if (chatIds.length === 0) {
  356. await tags.set(await getAllChatTags(localStorage.token));
  357. chatIds = await getChatList(localStorage.token);
  358. }
  359. await chats.set(chatIds);
  360. }}
  361. >
  362. {tag.name}
  363. </button>
  364. {/each}
  365. </div>
  366. {/if}
  367. <div class="pl-2 my-2 flex-1 flex flex-col space-y-1 overflow-y-auto scrollbar-hidden">
  368. {#each filteredChatList as chat, idx}
  369. {#if idx === 0 || (idx > 0 && chat.time_range !== filteredChatList[idx - 1].time_range)}
  370. <div
  371. class="w-full pl-2.5 text-xs text-gray-500 dark:text-gray-500 font-medium {idx === 0
  372. ? ''
  373. : 'pt-5'} pb-0.5"
  374. >
  375. {$i18n.t(chat.time_range)}
  376. <!-- localisation keys for time_range to be recognized from the i18next parser (so they don't get automatically removed):
  377. {$i18n.t('Today')}
  378. {$i18n.t('Yesterday')}
  379. {$i18n.t('Previous 7 days')}
  380. {$i18n.t('Previous 30 days')}
  381. {$i18n.t('January')}
  382. {$i18n.t('February')}
  383. {$i18n.t('March')}
  384. {$i18n.t('April')}
  385. {$i18n.t('May')}
  386. {$i18n.t('June')}
  387. {$i18n.t('July')}
  388. {$i18n.t('August')}
  389. {$i18n.t('September')}
  390. {$i18n.t('October')}
  391. {$i18n.t('November')}
  392. {$i18n.t('December')}
  393. -->
  394. </div>
  395. {/if}
  396. <div class=" w-full pr-2 relative group">
  397. {#if chatTitleEditId === chat.id}
  398. <div
  399. class=" w-full flex justify-between rounded-xl px-3 py-2 {chat.id === $chatId ||
  400. chat.id === chatTitleEditId ||
  401. chat.id === chatDeleteId
  402. ? 'bg-gray-200 dark:bg-gray-900'
  403. : chat.id === selectedChatId
  404. ? 'bg-gray-100 dark:bg-gray-950'
  405. : 'group-hover:bg-gray-100 dark:group-hover:bg-gray-950'} whitespace-nowrap text-ellipsis"
  406. >
  407. <input bind:value={chatTitle} class=" bg-transparent w-full outline-none mr-10" />
  408. </div>
  409. {:else}
  410. <a
  411. class=" w-full flex justify-between rounded-xl px-3 py-2 {chat.id === $chatId ||
  412. chat.id === chatTitleEditId ||
  413. chat.id === chatDeleteId
  414. ? 'bg-gray-200 dark:bg-gray-900'
  415. : chat.id === selectedChatId
  416. ? 'bg-gray-100 dark:bg-gray-950'
  417. : ' group-hover:bg-gray-100 dark:group-hover:bg-gray-950'} whitespace-nowrap text-ellipsis"
  418. href="/c/{chat.id}"
  419. on:click={() => {
  420. selectedChatId = chat.id;
  421. if ($mobile) {
  422. showSidebar.set(false);
  423. }
  424. }}
  425. draggable="false"
  426. >
  427. <div class=" flex self-center flex-1 w-full">
  428. <div class=" text-left self-center overflow-hidden w-full h-[20px]">
  429. {chat.title}
  430. </div>
  431. </div>
  432. </a>
  433. {/if}
  434. <div
  435. class="
  436. {chat.id === $chatId || chat.id === chatTitleEditId || chat.id === chatDeleteId
  437. ? 'from-gray-200 dark:from-gray-900'
  438. : chat.id === selectedChatId
  439. ? 'from-gray-100 dark:from-gray-950'
  440. : 'invisible group-hover:visible from-gray-100 dark:from-gray-950'}
  441. absolute right-[10px] top-[10px] pr-2 pl-5 bg-gradient-to-l from-80%
  442. to-transparent"
  443. >
  444. {#if chatTitleEditId === chat.id}
  445. <div class="flex self-center space-x-1.5 z-10">
  446. <button
  447. class=" self-center dark:hover:text-white transition"
  448. on:click={() => {
  449. editChatTitle(chat.id, chatTitle);
  450. chatTitleEditId = null;
  451. chatTitle = '';
  452. }}
  453. >
  454. <svg
  455. xmlns="http://www.w3.org/2000/svg"
  456. viewBox="0 0 20 20"
  457. fill="currentColor"
  458. class="w-4 h-4"
  459. >
  460. <path
  461. fill-rule="evenodd"
  462. d="M16.704 4.153a.75.75 0 01.143 1.052l-8 10.5a.75.75 0 01-1.127.075l-4.5-4.5a.75.75 0 011.06-1.06l3.894 3.893 7.48-9.817a.75.75 0 011.05-.143z"
  463. clip-rule="evenodd"
  464. />
  465. </svg>
  466. </button>
  467. <button
  468. class=" self-center dark:hover:text-white transition"
  469. on:click={() => {
  470. chatTitleEditId = null;
  471. chatTitle = '';
  472. }}
  473. >
  474. <svg
  475. xmlns="http://www.w3.org/2000/svg"
  476. viewBox="0 0 20 20"
  477. fill="currentColor"
  478. class="w-4 h-4"
  479. >
  480. <path
  481. d="M6.28 5.22a.75.75 0 00-1.06 1.06L8.94 10l-3.72 3.72a.75.75 0 101.06 1.06L10 11.06l3.72 3.72a.75.75 0 101.06-1.06L11.06 10l3.72-3.72a.75.75 0 00-1.06-1.06L10 8.94 6.28 5.22z"
  482. />
  483. </svg>
  484. </button>
  485. </div>
  486. {:else if chatDeleteId === chat.id}
  487. <div class="flex self-center space-x-1.5 z-10">
  488. <button
  489. class=" self-center dark:hover:text-white transition"
  490. on:click={() => {
  491. deleteChat(chat.id);
  492. }}
  493. >
  494. <svg
  495. xmlns="http://www.w3.org/2000/svg"
  496. viewBox="0 0 20 20"
  497. fill="currentColor"
  498. class="w-4 h-4"
  499. >
  500. <path
  501. fill-rule="evenodd"
  502. d="M16.704 4.153a.75.75 0 01.143 1.052l-8 10.5a.75.75 0 01-1.127.075l-4.5-4.5a.75.75 0 011.06-1.06l3.894 3.893 7.48-9.817a.75.75 0 011.05-.143z"
  503. clip-rule="evenodd"
  504. />
  505. </svg>
  506. </button>
  507. <button
  508. class=" self-center dark:hover:text-white transition"
  509. on:click={() => {
  510. chatDeleteId = null;
  511. }}
  512. >
  513. <svg
  514. xmlns="http://www.w3.org/2000/svg"
  515. viewBox="0 0 20 20"
  516. fill="currentColor"
  517. class="w-4 h-4"
  518. >
  519. <path
  520. d="M6.28 5.22a.75.75 0 00-1.06 1.06L8.94 10l-3.72 3.72a.75.75 0 101.06 1.06L10 11.06l3.72 3.72a.75.75 0 101.06-1.06L11.06 10l3.72-3.72a.75.75 0 00-1.06-1.06L10 8.94 6.28 5.22z"
  521. />
  522. </svg>
  523. </button>
  524. </div>
  525. {:else}
  526. <div class="flex self-center space-x-1 z-10">
  527. <ChatMenu
  528. chatId={chat.id}
  529. shareHandler={() => {
  530. shareChatId = selectedChatId;
  531. showShareChatModal = true;
  532. }}
  533. archiveChatHandler={() => {
  534. archiveChatHandler(chat.id);
  535. }}
  536. renameHandler={() => {
  537. chatTitle = chat.title;
  538. chatTitleEditId = chat.id;
  539. }}
  540. deleteHandler={() => {
  541. chatDeleteId = chat.id;
  542. }}
  543. onClose={() => {
  544. selectedChatId = null;
  545. }}
  546. >
  547. <button
  548. aria-label="Chat Menu"
  549. class=" self-center dark:hover:text-white transition"
  550. on:click={() => {
  551. selectedChatId = chat.id;
  552. }}
  553. >
  554. <svg
  555. xmlns="http://www.w3.org/2000/svg"
  556. viewBox="0 0 16 16"
  557. fill="currentColor"
  558. class="w-4 h-4"
  559. >
  560. <path
  561. d="M2 8a1.5 1.5 0 1 1 3 0 1.5 1.5 0 0 1-3 0ZM6.5 8a1.5 1.5 0 1 1 3 0 1.5 1.5 0 0 1-3 0ZM12.5 6.5a1.5 1.5 0 1 0 0 3 1.5 1.5 0 0 0 0-3Z"
  562. />
  563. </svg>
  564. </button>
  565. </ChatMenu>
  566. {#if chat.id === $chatId}
  567. <button
  568. id="delete-chat-button"
  569. class="hidden"
  570. on:click={() => {
  571. chatDeleteId = chat.id;
  572. }}
  573. >
  574. <svg
  575. xmlns="http://www.w3.org/2000/svg"
  576. viewBox="0 0 16 16"
  577. fill="currentColor"
  578. class="w-4 h-4"
  579. >
  580. <path
  581. d="M2 8a1.5 1.5 0 1 1 3 0 1.5 1.5 0 0 1-3 0ZM6.5 8a1.5 1.5 0 1 1 3 0 1.5 1.5 0 0 1-3 0ZM12.5 6.5a1.5 1.5 0 1 0 0 3 1.5 1.5 0 0 0 0-3Z"
  582. />
  583. </svg>
  584. </button>
  585. {/if}
  586. </div>
  587. {/if}
  588. </div>
  589. </div>
  590. {/each}
  591. </div>
  592. </div>
  593. {#if $mobile}
  594. <div class="px-2.5">
  595. <!-- <hr class=" border-gray-900 mb-1 w-full" /> -->
  596. <div class="flex flex-col">
  597. {#if $user !== undefined}
  598. <UserMenu
  599. role={$user.role}
  600. on:show={(e) => {
  601. if (e.detail === 'archived-chat') {
  602. showArchivedChats.set(true);
  603. }
  604. }}
  605. >
  606. <button
  607. class=" flex rounded-xl py-3 px-3.5 w-full hover:bg-gray-100 dark:hover:bg-gray-900 transition"
  608. on:click={() => {
  609. showDropdown = !showDropdown;
  610. }}
  611. >
  612. <div class=" self-center mr-3">
  613. <img
  614. src={$user.profile_image_url}
  615. class=" max-w-[30px] object-cover rounded-full"
  616. alt="User profile"
  617. />
  618. </div>
  619. <div class=" self-center font-semibold">{$user.name}</div>
  620. </button>
  621. </UserMenu>
  622. {/if}
  623. </div>
  624. </div>
  625. {/if}
  626. </div>
  627. <div
  628. id="sidebar-handle"
  629. class=" hidden md:fixed left-0 top-[50dvh] -translate-y-1/2 transition-transform translate-x-[255px] md:translate-x-[260px] rotate-0"
  630. >
  631. <Tooltip
  632. placement="right"
  633. content={`${$showSidebar ? $i18n.t('Close') : $i18n.t('Open')} ${$i18n.t('sidebar')}`}
  634. touch={false}
  635. >
  636. <button
  637. id="sidebar-toggle-button"
  638. class=" group"
  639. on:click={() => {
  640. showSidebar.set(!$showSidebar);
  641. }}
  642. ><span class="" data-state="closed"
  643. ><div
  644. class="flex h-[72px] w-8 items-center justify-center opacity-50 group-hover:opacity-100 transition"
  645. >
  646. <div class="flex h-6 w-6 flex-col items-center">
  647. <div
  648. class="h-3 w-1 rounded-full bg-[#0f0f0f] dark:bg-white rotate-0 translate-y-[0.15rem] {$showSidebar
  649. ? 'group-hover:rotate-[15deg]'
  650. : 'group-hover:rotate-[-15deg]'}"
  651. />
  652. <div
  653. class="h-3 w-1 rounded-full bg-[#0f0f0f] dark:bg-white rotate-0 translate-y-[-0.15rem] {$showSidebar
  654. ? 'group-hover:rotate-[-15deg]'
  655. : 'group-hover:rotate-[15deg]'}"
  656. />
  657. </div>
  658. </div>
  659. </span>
  660. </button>
  661. </Tooltip>
  662. </div>
  663. </div>
  664. <style>
  665. .scrollbar-hidden:active::-webkit-scrollbar-thumb,
  666. .scrollbar-hidden:focus::-webkit-scrollbar-thumb,
  667. .scrollbar-hidden:hover::-webkit-scrollbar-thumb {
  668. visibility: visible;
  669. }
  670. .scrollbar-hidden::-webkit-scrollbar-thumb {
  671. visibility: hidden;
  672. }
  673. </style>