Sidebar.svelte 22 KB

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