Sidebar.svelte 22 KB

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