Sidebar.svelte 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734
  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. } from '$lib/stores';
  13. import { onMount, getContext } from 'svelte';
  14. const i18n = getContext('i18n');
  15. import {
  16. deleteChatById,
  17. getChatList,
  18. getChatById,
  19. getChatListByTagName,
  20. updateChatById,
  21. getAllChatTags,
  22. archiveChatById
  23. } from '$lib/apis/chats';
  24. import { toast } from 'svelte-sonner';
  25. import { fade, slide } from 'svelte/transition';
  26. import { WEBUI_BASE_URL } from '$lib/constants';
  27. import Tooltip from '../common/Tooltip.svelte';
  28. import ChatMenu from './Sidebar/ChatMenu.svelte';
  29. import ShareChatModal from '../chat/ShareChatModal.svelte';
  30. import ArchiveBox from '../icons/ArchiveBox.svelte';
  31. import ArchivedChatsModal from './Sidebar/ArchivedChatsModal.svelte';
  32. import UserMenu from './Sidebar/UserMenu.svelte';
  33. const BREAKPOINT = 768;
  34. let show = false;
  35. let navElement;
  36. let title: string = 'UI';
  37. let search = '';
  38. let shareChatId = null;
  39. let selectedChatId = null;
  40. let chatDeleteId = null;
  41. let chatTitleEditId = null;
  42. let chatTitle = '';
  43. let showArchivedChatsModal = false;
  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={showArchivedChatsModal}
  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. }, 0);
  219. }}
  220. >
  221. <div class="self-center">
  222. <svg
  223. xmlns="http://www.w3.org/2000/svg"
  224. viewBox="0 0 20 20"
  225. fill="currentColor"
  226. class="size-5"
  227. >
  228. <path
  229. 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"
  230. />
  231. <path
  232. 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"
  233. />
  234. </svg>
  235. </div>
  236. </a>
  237. </div>
  238. {#if $user?.role === 'admin'}
  239. <div class="px-2.5 flex justify-center text-gray-800 dark:text-gray-200">
  240. <a
  241. class="flex-grow flex space-x-3 rounded-xl px-2.5 py-2 hover:bg-gray-100 dark:hover:bg-gray-900 transition"
  242. href="/workspace"
  243. on:click={() => {
  244. selectedChatId = null;
  245. chatId.set('');
  246. }}
  247. >
  248. <div class="self-center">
  249. <svg
  250. xmlns="http://www.w3.org/2000/svg"
  251. fill="none"
  252. viewBox="0 0 24 24"
  253. stroke-width="2"
  254. stroke="currentColor"
  255. class="size-[1.1rem]"
  256. >
  257. <path
  258. stroke-linecap="round"
  259. stroke-linejoin="round"
  260. 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"
  261. />
  262. </svg>
  263. </div>
  264. <div class="flex self-center">
  265. <div class=" self-center font-medium text-sm">{$i18n.t('Workspace')}</div>
  266. </div>
  267. </a>
  268. </div>
  269. {/if}
  270. <div class="relative flex flex-col flex-1 overflow-y-auto">
  271. {#if !($settings.saveChatHistory ?? true)}
  272. <div class="absolute z-40 w-full h-full bg-gray-50/90 dark:bg-black/90 flex justify-center">
  273. <div class=" text-left px-5 py-2">
  274. <div class=" font-medium">{$i18n.t('Chat History is off for this browser.')}</div>
  275. <div class="text-xs mt-2">
  276. {$i18n.t(
  277. "When history is turned off, new chats on this browser won't appear in your history on any of your devices."
  278. )}
  279. <span class=" font-semibold"
  280. >{$i18n.t('This setting does not sync across browsers or devices.')}</span
  281. >
  282. </div>
  283. <div class="mt-3">
  284. <button
  285. 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"
  286. type="button"
  287. on:click={() => {
  288. saveSettings({
  289. saveChatHistory: true
  290. });
  291. }}
  292. >
  293. <svg
  294. xmlns="http://www.w3.org/2000/svg"
  295. viewBox="0 0 16 16"
  296. fill="currentColor"
  297. class="w-3 h-3"
  298. >
  299. <path
  300. fill-rule="evenodd"
  301. 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"
  302. clip-rule="evenodd"
  303. />
  304. </svg>
  305. <div>{$i18n.t('Enable Chat History')}</div>
  306. </button>
  307. </div>
  308. </div>
  309. </div>
  310. {/if}
  311. <div class="px-2 mt-0.5 mb-2 flex justify-center space-x-2">
  312. <div class="flex w-full rounded-xl" id="chat-search">
  313. <div class="self-center pl-3 py-2 rounded-l-xl bg-transparent">
  314. <svg
  315. xmlns="http://www.w3.org/2000/svg"
  316. viewBox="0 0 20 20"
  317. fill="currentColor"
  318. class="w-4 h-4"
  319. >
  320. <path
  321. fill-rule="evenodd"
  322. 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"
  323. clip-rule="evenodd"
  324. />
  325. </svg>
  326. </div>
  327. <input
  328. class="w-full rounded-r-xl py-1.5 pl-2.5 pr-4 text-sm bg-transparent dark:text-gray-300 outline-none"
  329. placeholder={$i18n.t('Search')}
  330. bind:value={search}
  331. on:focus={() => {
  332. enrichChatsWithContent($chats);
  333. }}
  334. />
  335. </div>
  336. </div>
  337. {#if $tags.length > 0}
  338. <div class="px-2.5 mb-2 flex gap-0.5 flex-wrap">
  339. <button
  340. class="px-2.5 text-xs font-medium bg-gray-50 dark:bg-gray-900 dark:hover:bg-gray-800 transition rounded-full"
  341. on:click={async () => {
  342. await chats.set(await getChatList(localStorage.token));
  343. }}
  344. >
  345. {$i18n.t('all')}
  346. </button>
  347. {#each $tags as tag}
  348. <button
  349. class="px-2.5 text-xs font-medium bg-gray-50 dark:bg-gray-900 dark:hover:bg-gray-800 transition rounded-full"
  350. on:click={async () => {
  351. let chatIds = await getChatListByTagName(localStorage.token, tag.name);
  352. if (chatIds.length === 0) {
  353. await tags.set(await getAllChatTags(localStorage.token));
  354. chatIds = await getChatList(localStorage.token);
  355. }
  356. await chats.set(chatIds);
  357. }}
  358. >
  359. {tag.name}
  360. </button>
  361. {/each}
  362. </div>
  363. {/if}
  364. <div class="pl-2 my-2 flex-1 flex flex-col space-y-1 overflow-y-auto scrollbar-hidden">
  365. {#each filteredChatList as chat, idx}
  366. {#if idx === 0 || (idx > 0 && chat.time_range !== filteredChatList[idx - 1].time_range)}
  367. <div
  368. class="w-full pl-2.5 text-xs text-gray-500 dark:text-gray-500 font-medium {idx === 0
  369. ? ''
  370. : 'pt-5'} pb-0.5"
  371. >
  372. {$i18n.t(chat.time_range)}
  373. <!-- localisation keys for time_range to be recognized from the i18next parser (so they don't get automatically removed):
  374. {$i18n.t('Today')}
  375. {$i18n.t('Yesterday')}
  376. {$i18n.t('Previous 7 days')}
  377. {$i18n.t('Previous 30 days')}
  378. {$i18n.t('January')}
  379. {$i18n.t('February')}
  380. {$i18n.t('March')}
  381. {$i18n.t('April')}
  382. {$i18n.t('May')}
  383. {$i18n.t('June')}
  384. {$i18n.t('July')}
  385. {$i18n.t('August')}
  386. {$i18n.t('September')}
  387. {$i18n.t('October')}
  388. {$i18n.t('November')}
  389. {$i18n.t('December')}
  390. -->
  391. </div>
  392. {/if}
  393. <div class=" w-full pr-2 relative group">
  394. {#if chatTitleEditId === chat.id}
  395. <div
  396. class=" w-full flex justify-between rounded-xl px-3 py-2 {chat.id === $chatId ||
  397. chat.id === chatTitleEditId ||
  398. chat.id === chatDeleteId
  399. ? 'bg-gray-200 dark:bg-gray-900'
  400. : chat.id === selectedChatId
  401. ? 'bg-gray-100 dark:bg-gray-950'
  402. : 'group-hover:bg-gray-100 dark:group-hover:bg-gray-950'} whitespace-nowrap text-ellipsis"
  403. >
  404. <input bind:value={chatTitle} class=" bg-transparent w-full outline-none mr-10" />
  405. </div>
  406. {:else}
  407. <a
  408. class=" w-full flex justify-between rounded-xl px-3 py-2 {chat.id === $chatId ||
  409. chat.id === chatTitleEditId ||
  410. chat.id === chatDeleteId
  411. ? 'bg-gray-200 dark:bg-gray-900'
  412. : chat.id === selectedChatId
  413. ? 'bg-gray-100 dark:bg-gray-950'
  414. : ' group-hover:bg-gray-100 dark:group-hover:bg-gray-950'} whitespace-nowrap text-ellipsis"
  415. href="/c/{chat.id}"
  416. on:click={() => {
  417. selectedChatId = chat.id;
  418. if (window.innerWidth < 1024) {
  419. showSidebar.set(false);
  420. }
  421. }}
  422. draggable="false"
  423. >
  424. <div class=" flex self-center flex-1 w-full">
  425. <div class=" text-left self-center overflow-hidden w-full h-[20px]">
  426. {chat.title}
  427. </div>
  428. </div>
  429. </a>
  430. {/if}
  431. <div
  432. class="
  433. {chat.id === $chatId || chat.id === chatTitleEditId || chat.id === chatDeleteId
  434. ? 'from-gray-200 dark:from-gray-900'
  435. : chat.id === selectedChatId
  436. ? 'from-gray-100 dark:from-gray-950'
  437. : 'invisible group-hover:visible from-gray-100 dark:from-gray-950'}
  438. absolute right-[10px] top-[10px] pr-2 pl-5 bg-gradient-to-l from-80%
  439. to-transparent"
  440. >
  441. {#if chatTitleEditId === chat.id}
  442. <div class="flex self-center space-x-1.5 z-10">
  443. <button
  444. class=" self-center dark:hover:text-white transition"
  445. on:click={() => {
  446. editChatTitle(chat.id, chatTitle);
  447. chatTitleEditId = null;
  448. chatTitle = '';
  449. }}
  450. >
  451. <svg
  452. xmlns="http://www.w3.org/2000/svg"
  453. viewBox="0 0 20 20"
  454. fill="currentColor"
  455. class="w-4 h-4"
  456. >
  457. <path
  458. fill-rule="evenodd"
  459. 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"
  460. clip-rule="evenodd"
  461. />
  462. </svg>
  463. </button>
  464. <button
  465. class=" self-center dark:hover:text-white transition"
  466. on:click={() => {
  467. chatTitleEditId = null;
  468. chatTitle = '';
  469. }}
  470. >
  471. <svg
  472. xmlns="http://www.w3.org/2000/svg"
  473. viewBox="0 0 20 20"
  474. fill="currentColor"
  475. class="w-4 h-4"
  476. >
  477. <path
  478. 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"
  479. />
  480. </svg>
  481. </button>
  482. </div>
  483. {:else if chatDeleteId === chat.id}
  484. <div class="flex self-center space-x-1.5 z-10">
  485. <button
  486. class=" self-center dark:hover:text-white transition"
  487. on:click={() => {
  488. deleteChat(chat.id);
  489. }}
  490. >
  491. <svg
  492. xmlns="http://www.w3.org/2000/svg"
  493. viewBox="0 0 20 20"
  494. fill="currentColor"
  495. class="w-4 h-4"
  496. >
  497. <path
  498. fill-rule="evenodd"
  499. 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"
  500. clip-rule="evenodd"
  501. />
  502. </svg>
  503. </button>
  504. <button
  505. class=" self-center dark:hover:text-white transition"
  506. on:click={() => {
  507. chatDeleteId = null;
  508. }}
  509. >
  510. <svg
  511. xmlns="http://www.w3.org/2000/svg"
  512. viewBox="0 0 20 20"
  513. fill="currentColor"
  514. class="w-4 h-4"
  515. >
  516. <path
  517. 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"
  518. />
  519. </svg>
  520. </button>
  521. </div>
  522. {:else}
  523. <div class="flex self-center space-x-1 z-10">
  524. <ChatMenu
  525. chatId={chat.id}
  526. shareHandler={() => {
  527. shareChatId = selectedChatId;
  528. showShareChatModal = true;
  529. }}
  530. renameHandler={() => {
  531. chatTitle = chat.title;
  532. chatTitleEditId = chat.id;
  533. }}
  534. deleteHandler={() => {
  535. chatDeleteId = chat.id;
  536. }}
  537. onClose={() => {
  538. selectedChatId = null;
  539. }}
  540. >
  541. <button
  542. aria-label="Chat Menu"
  543. class=" self-center dark:hover:text-white transition"
  544. on:click={() => {
  545. selectedChatId = chat.id;
  546. }}
  547. >
  548. <svg
  549. xmlns="http://www.w3.org/2000/svg"
  550. viewBox="0 0 16 16"
  551. fill="currentColor"
  552. class="w-4 h-4"
  553. >
  554. <path
  555. 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"
  556. />
  557. </svg>
  558. </button>
  559. </ChatMenu>
  560. <Tooltip content={$i18n.t('Archive')}>
  561. <button
  562. aria-label="Archive"
  563. class=" self-center dark:hover:text-white transition"
  564. on:click={() => {
  565. archiveChatHandler(chat.id);
  566. }}
  567. >
  568. <ArchiveBox />
  569. </button>
  570. </Tooltip>
  571. {#if chat.id === $chatId}
  572. <button
  573. id="delete-chat-button"
  574. class="hidden"
  575. on:click={() => {
  576. chatDeleteId = chat.id;
  577. }}
  578. >
  579. <svg
  580. xmlns="http://www.w3.org/2000/svg"
  581. viewBox="0 0 16 16"
  582. fill="currentColor"
  583. class="w-4 h-4"
  584. >
  585. <path
  586. 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"
  587. />
  588. </svg>
  589. </button>
  590. {/if}
  591. </div>
  592. {/if}
  593. </div>
  594. </div>
  595. {/each}
  596. </div>
  597. </div>
  598. {#if $mobile}
  599. <div class="px-2.5">
  600. <!-- <hr class=" border-gray-900 mb-1 w-full" /> -->
  601. <div class="flex flex-col">
  602. {#if $user !== undefined}
  603. <UserMenu
  604. role={$user.role}
  605. on:show={(e) => {
  606. if (e.detail === 'archived-chat') {
  607. showArchivedChatsModal = true;
  608. }
  609. }}
  610. >
  611. <button
  612. class=" flex rounded-xl py-3 px-3.5 w-full hover:bg-gray-100 dark:hover:bg-gray-900 transition"
  613. on:click={() => {
  614. showDropdown = !showDropdown;
  615. }}
  616. >
  617. <div class=" self-center mr-3">
  618. <img
  619. src={$user.profile_image_url}
  620. class=" max-w-[30px] object-cover rounded-full"
  621. alt="User profile"
  622. />
  623. </div>
  624. <div class=" self-center font-semibold">{$user.name}</div>
  625. </button>
  626. </UserMenu>
  627. {/if}
  628. </div>
  629. </div>
  630. {/if}
  631. </div>
  632. <div
  633. id="sidebar-handle"
  634. class=" hidden md:fixed left-0 top-[50dvh] -translate-y-1/2 transition-transform translate-x-[255px] md:translate-x-[260px] rotate-0"
  635. >
  636. <Tooltip
  637. placement="right"
  638. content={`${$showSidebar ? $i18n.t('Close') : $i18n.t('Open')} ${$i18n.t('sidebar')}`}
  639. touch={false}
  640. >
  641. <button
  642. id="sidebar-toggle-button"
  643. class=" group"
  644. on:click={() => {
  645. showSidebar.set(!$showSidebar);
  646. }}
  647. ><span class="" data-state="closed"
  648. ><div
  649. class="flex h-[72px] w-8 items-center justify-center opacity-50 group-hover:opacity-100 transition"
  650. >
  651. <div class="flex h-6 w-6 flex-col items-center">
  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. class="h-3 w-1 rounded-full bg-[#0f0f0f] dark:bg-white rotate-0 translate-y-[-0.15rem] {$showSidebar
  659. ? 'group-hover:rotate-[-15deg]'
  660. : 'group-hover:rotate-[15deg]'}"
  661. />
  662. </div>
  663. </div>
  664. </span>
  665. </button>
  666. </Tooltip>
  667. </div>
  668. </div>
  669. <style>
  670. .scrollbar-hidden:active::-webkit-scrollbar-thumb,
  671. .scrollbar-hidden:focus::-webkit-scrollbar-thumb,
  672. .scrollbar-hidden:hover::-webkit-scrollbar-thumb {
  673. visibility: visible;
  674. }
  675. .scrollbar-hidden::-webkit-scrollbar-thumb {
  676. visibility: hidden;
  677. }
  678. </style>