Sidebar.svelte 22 KB

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