Sidebar.svelte 22 KB

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