Sidebar.svelte 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897
  1. <script lang="ts">
  2. import { goto } from '$app/navigation';
  3. import { user, chats, settings, showSettings, chatId, tags, showSidebar } from '$lib/stores';
  4. import { onMount, getContext } from 'svelte';
  5. const i18n = getContext('i18n');
  6. import {
  7. deleteChatById,
  8. getChatList,
  9. getChatById,
  10. getChatListByTagName,
  11. updateChatById,
  12. getAllChatTags,
  13. archiveChatById
  14. } from '$lib/apis/chats';
  15. import { toast } from 'svelte-sonner';
  16. import { fade, slide } from 'svelte/transition';
  17. import { WEBUI_BASE_URL } from '$lib/constants';
  18. import Tooltip from '../common/Tooltip.svelte';
  19. import ChatMenu from './Sidebar/ChatMenu.svelte';
  20. import ShareChatModal from '../chat/ShareChatModal.svelte';
  21. import ArchiveBox from '../icons/ArchiveBox.svelte';
  22. import ArchivedChatsModal from './Sidebar/ArchivedChatsModal.svelte';
  23. const BREAKPOINT = 1024;
  24. let show = false;
  25. let navElement;
  26. let title: string = 'UI';
  27. let search = '';
  28. let shareChatId = null;
  29. let selectedChatId = null;
  30. let chatDeleteId = null;
  31. let chatTitleEditId = null;
  32. let chatTitle = '';
  33. let showArchivedChatsModal = false;
  34. let showShareChatModal = false;
  35. let showDropdown = false;
  36. let isEditing = false;
  37. let filteredChatList = [];
  38. $: filteredChatList = $chats.filter((chat) => {
  39. if (search === '') {
  40. return true;
  41. } else {
  42. let title = chat.title.toLowerCase();
  43. const query = search.toLowerCase();
  44. let contentMatches = false;
  45. // Access the messages within chat.chat.messages
  46. if (chat.chat && chat.chat.messages && Array.isArray(chat.chat.messages)) {
  47. contentMatches = chat.chat.messages.some((message) => {
  48. // Check if message.content exists and includes the search query
  49. return message.content && message.content.toLowerCase().includes(query);
  50. });
  51. }
  52. return title.includes(query) || contentMatches;
  53. }
  54. });
  55. onMount(async () => {
  56. showSidebar.set(window.innerWidth > BREAKPOINT);
  57. await chats.set(await getChatList(localStorage.token));
  58. let touchstart;
  59. let touchend;
  60. function checkDirection() {
  61. const screenWidth = window.innerWidth;
  62. const swipeDistance = Math.abs(touchend.screenX - touchstart.screenX);
  63. if (touchstart.clientX < 40 && swipeDistance >= screenWidth / 8) {
  64. if (touchend.screenX < touchstart.screenX) {
  65. showSidebar.set(false);
  66. }
  67. if (touchend.screenX > touchstart.screenX) {
  68. showSidebar.set(true);
  69. }
  70. }
  71. }
  72. const onTouchStart = (e) => {
  73. touchstart = e.changedTouches[0];
  74. console.log(touchstart.clientX);
  75. };
  76. const onTouchEnd = (e) => {
  77. touchend = e.changedTouches[0];
  78. checkDirection();
  79. };
  80. const onResize = () => {
  81. if ($showSidebar && window.innerWidth < BREAKPOINT) {
  82. showSidebar.set(false);
  83. }
  84. };
  85. window.addEventListener('touchstart', onTouchStart);
  86. window.addEventListener('touchend', onTouchEnd);
  87. window.addEventListener('resize', onResize);
  88. return () => {
  89. window.removeEventListener('touchstart', onTouchStart);
  90. window.removeEventListener('touchend', onTouchEnd);
  91. window.removeEventListener('resize', onResize);
  92. };
  93. });
  94. // Helper function to fetch and add chat content to each chat
  95. const enrichChatsWithContent = async (chatList) => {
  96. const enrichedChats = await Promise.all(
  97. chatList.map(async (chat) => {
  98. const chatDetails = await getChatById(localStorage.token, chat.id).catch((error) => null); // Handle error or non-existent chat gracefully
  99. if (chatDetails) {
  100. chat.chat = chatDetails.chat; // Assuming chatDetails.chat contains the chat content
  101. }
  102. return chat;
  103. })
  104. );
  105. await chats.set(enrichedChats);
  106. };
  107. const loadChat = async (id) => {
  108. goto(`/c/${id}`);
  109. };
  110. const editChatTitle = async (id, _title) => {
  111. if (_title === '') {
  112. toast.error($i18n.t('Title cannot be an empty string.'));
  113. } else {
  114. title = _title;
  115. await updateChatById(localStorage.token, id, {
  116. title: _title
  117. });
  118. await chats.set(await getChatList(localStorage.token));
  119. }
  120. };
  121. const deleteChat = async (id) => {
  122. const res = await deleteChatById(localStorage.token, id).catch((error) => {
  123. toast.error(error);
  124. chatDeleteId = null;
  125. return null;
  126. });
  127. if (res) {
  128. if ($chatId === id) {
  129. goto('/');
  130. }
  131. await chats.set(await getChatList(localStorage.token));
  132. }
  133. };
  134. const saveSettings = async (updated) => {
  135. await settings.set({ ...$settings, ...updated });
  136. localStorage.setItem('settings', JSON.stringify($settings));
  137. location.href = '/';
  138. };
  139. const archiveChatHandler = async (id) => {
  140. await archiveChatById(localStorage.token, id);
  141. await chats.set(await getChatList(localStorage.token));
  142. };
  143. </script>
  144. <ShareChatModal bind:show={showShareChatModal} chatId={shareChatId} />
  145. <ArchivedChatsModal
  146. bind:show={showArchivedChatsModal}
  147. on:change={async () => {
  148. await chats.set(await getChatList(localStorage.token));
  149. }}
  150. />
  151. <div
  152. bind:this={navElement}
  153. id="sidebar"
  154. class="h-screen max-h-[100dvh] min-h-screen {$showSidebar
  155. ? 'lg:relative w-[260px]'
  156. : '-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
  157. "
  158. data-state={$showSidebar}
  159. >
  160. <div
  161. class="py-2.5 my-auto flex flex-col justify-between h-screen max-h-[100dvh] w-[260px] {$showSidebar
  162. ? ''
  163. : 'invisible'}"
  164. >
  165. <div class="px-2 flex justify-center space-x-2">
  166. <a
  167. id="sidebar-new-chat-button"
  168. class="flex-grow flex justify-between rounded-xl px-4 py-2 hover:bg-gray-100 dark:hover:bg-gray-900 transition"
  169. href="/"
  170. on:click={async () => {
  171. selectedChatId = null;
  172. await goto('/');
  173. const newChatButton = document.getElementById('new-chat-button');
  174. setTimeout(() => {
  175. newChatButton?.click();
  176. }, 0);
  177. }}
  178. >
  179. <div class="flex self-center">
  180. <div class="self-center mr-1.5">
  181. <img
  182. src="{WEBUI_BASE_URL}/static/favicon.png"
  183. class=" size-6 -translate-x-1.5 rounded-full"
  184. alt="logo"
  185. />
  186. </div>
  187. <div class=" self-center font-medium text-sm">{$i18n.t('New Chat')}</div>
  188. </div>
  189. <div class="self-center">
  190. <svg
  191. xmlns="http://www.w3.org/2000/svg"
  192. viewBox="0 0 20 20"
  193. fill="currentColor"
  194. class="w-4 h-4"
  195. >
  196. <path
  197. 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"
  198. />
  199. <path
  200. 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"
  201. />
  202. </svg>
  203. </div>
  204. </a>
  205. </div>
  206. {#if $user?.role === 'admin'}
  207. <div class="px-2 flex justify-center mt-0.5">
  208. <a
  209. class="flex-grow flex space-x-3 rounded-xl px-3.5 py-2 hover:bg-gray-100 dark:hover:bg-gray-900 transition"
  210. href="/modelfiles"
  211. on:click={() => {
  212. selectedChatId = null;
  213. chatId.set('');
  214. }}
  215. >
  216. <div class="self-center">
  217. <svg
  218. xmlns="http://www.w3.org/2000/svg"
  219. fill="none"
  220. viewBox="0 0 24 24"
  221. stroke-width="2"
  222. stroke="currentColor"
  223. class="w-4 h-4"
  224. >
  225. <path
  226. stroke-linecap="round"
  227. stroke-linejoin="round"
  228. 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"
  229. />
  230. </svg>
  231. </div>
  232. <div class="flex self-center">
  233. <div class=" self-center font-medium text-sm">{$i18n.t('Modelfiles')}</div>
  234. </div>
  235. </a>
  236. </div>
  237. <div class="px-2 flex justify-center">
  238. <a
  239. class="flex-grow flex space-x-3 rounded-xl px-3.5 py-2 hover:bg-gray-100 dark:hover:bg-gray-900 transition"
  240. href="/prompts"
  241. on:click={() => {
  242. selectedChatId = null;
  243. chatId.set('');
  244. }}
  245. >
  246. <div class="self-center">
  247. <svg
  248. xmlns="http://www.w3.org/2000/svg"
  249. fill="none"
  250. viewBox="0 0 24 24"
  251. stroke-width="2"
  252. stroke="currentColor"
  253. class="w-4 h-4"
  254. >
  255. <path
  256. stroke-linecap="round"
  257. stroke-linejoin="round"
  258. d="m16.862 4.487 1.687-1.688a1.875 1.875 0 1 1 2.652 2.652L6.832 19.82a4.5 4.5 0 0 1-1.897 1.13l-2.685.8.8-2.685a4.5 4.5 0 0 1 1.13-1.897L16.863 4.487Zm0 0L19.5 7.125"
  259. />
  260. </svg>
  261. </div>
  262. <div class="flex self-center">
  263. <div class=" self-center font-medium text-sm">{$i18n.t('Prompts')}</div>
  264. </div>
  265. </a>
  266. </div>
  267. <div class="px-2 flex justify-center mb-1">
  268. <a
  269. class="flex-grow flex space-x-3 rounded-xl px-3.5 py-2 hover:bg-gray-100 dark:hover:bg-gray-900 transition"
  270. href="/documents"
  271. on:click={() => {
  272. selectedChatId = null;
  273. chatId.set('');
  274. }}
  275. >
  276. <div class="self-center">
  277. <svg
  278. xmlns="http://www.w3.org/2000/svg"
  279. fill="none"
  280. viewBox="0 0 24 24"
  281. stroke-width="2"
  282. stroke="currentColor"
  283. class="w-4 h-4"
  284. >
  285. <path
  286. stroke-linecap="round"
  287. stroke-linejoin="round"
  288. d="M15.75 17.25v3.375c0 .621-.504 1.125-1.125 1.125h-9.75a1.125 1.125 0 0 1-1.125-1.125V7.875c0-.621.504-1.125 1.125-1.125H6.75a9.06 9.06 0 0 1 1.5.124m7.5 10.376h3.375c.621 0 1.125-.504 1.125-1.125V11.25c0-4.46-3.243-8.161-7.5-8.876a9.06 9.06 0 0 0-1.5-.124H9.375c-.621 0-1.125.504-1.125 1.125v3.5m7.5 10.375H9.375a1.125 1.125 0 0 1-1.125-1.125v-9.25m12 6.625v-1.875a3.375 3.375 0 0 0-3.375-3.375h-1.5a1.125 1.125 0 0 1-1.125-1.125v-1.5a3.375 3.375 0 0 0-3.375-3.375H9.75"
  289. />
  290. </svg>
  291. </div>
  292. <div class="flex self-center">
  293. <div class=" self-center font-medium text-sm">{$i18n.t('Documents')}</div>
  294. </div>
  295. </a>
  296. </div>
  297. {/if}
  298. <div class="relative flex flex-col flex-1 overflow-y-auto">
  299. {#if !($settings.saveChatHistory ?? true)}
  300. <div class="absolute z-40 w-full h-full bg-gray-50/90 dark:bg-black/90 flex justify-center">
  301. <div class=" text-left px-5 py-2">
  302. <div class=" font-medium">{$i18n.t('Chat History is off for this browser.')}</div>
  303. <div class="text-xs mt-2">
  304. {$i18n.t(
  305. "When history is turned off, new chats on this browser won't appear in your history on any of your devices."
  306. )}
  307. <span class=" font-semibold"
  308. >{$i18n.t('This setting does not sync across browsers or devices.')}</span
  309. >
  310. </div>
  311. <div class="mt-3">
  312. <button
  313. 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"
  314. type="button"
  315. on:click={() => {
  316. saveSettings({
  317. saveChatHistory: true
  318. });
  319. }}
  320. >
  321. <svg
  322. xmlns="http://www.w3.org/2000/svg"
  323. viewBox="0 0 16 16"
  324. fill="currentColor"
  325. class="w-3 h-3"
  326. >
  327. <path
  328. fill-rule="evenodd"
  329. 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"
  330. clip-rule="evenodd"
  331. />
  332. </svg>
  333. <div>{$i18n.t('Enable Chat History')}</div>
  334. </button>
  335. </div>
  336. </div>
  337. </div>
  338. {/if}
  339. <div class="px-2 mt-1 mb-2 flex justify-center space-x-2">
  340. <div class="flex w-full" id="chat-search">
  341. <div class="self-center pl-3 py-2 rounded-l-xl bg-white dark:bg-gray-950">
  342. <svg
  343. xmlns="http://www.w3.org/2000/svg"
  344. viewBox="0 0 20 20"
  345. fill="currentColor"
  346. class="w-4 h-4"
  347. >
  348. <path
  349. fill-rule="evenodd"
  350. 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"
  351. clip-rule="evenodd"
  352. />
  353. </svg>
  354. </div>
  355. <input
  356. class="w-full rounded-r-xl py-1.5 pl-2.5 pr-4 text-sm dark:text-gray-300 dark:bg-gray-950 outline-none"
  357. placeholder={$i18n.t('Search')}
  358. bind:value={search}
  359. on:focus={() => {
  360. enrichChatsWithContent($chats);
  361. }}
  362. />
  363. </div>
  364. </div>
  365. {#if $tags.length > 0}
  366. <div class="px-2.5 mt-0.5 mb-2 flex gap-1 flex-wrap">
  367. <button
  368. class="px-2.5 text-xs font-medium bg-gray-100 dark:bg-gray-900 dark:hover:bg-gray-800 transition rounded-full"
  369. on:click={async () => {
  370. await chats.set(await getChatList(localStorage.token));
  371. }}
  372. >
  373. {$i18n.t('all')}
  374. </button>
  375. {#each $tags as tag}
  376. <button
  377. class="px-2.5 text-xs font-medium bg-gray-100 dark:bg-gray-900 dark:hover:bg-gray-800 transition rounded-full"
  378. on:click={async () => {
  379. let chatIds = await getChatListByTagName(localStorage.token, tag.name);
  380. if (chatIds.length === 0) {
  381. await tags.set(await getAllChatTags(localStorage.token));
  382. chatIds = await getChatList(localStorage.token);
  383. }
  384. await chats.set(chatIds);
  385. }}
  386. >
  387. {tag.name}
  388. </button>
  389. {/each}
  390. </div>
  391. {/if}
  392. <div class="pl-2 my-2 flex-1 flex flex-col space-y-1 overflow-y-auto scrollbar-none">
  393. {#each filteredChatList as chat, idx}
  394. {#if idx === 0 || (idx > 0 && chat.time_range !== filteredChatList[idx - 1].time_range)}
  395. <div
  396. class="w-full pl-2.5 text-xs text-gray-500 dark:text-gray-500 font-medium {idx === 0
  397. ? ''
  398. : 'pt-5'} pb-0.5"
  399. >
  400. {$i18n.t(chat.time_range)}
  401. <!-- localisation keys for time_range to be recognized from the i18next parser (so they don't get automatically removed):
  402. {$i18n.t('Today')}
  403. {$i18n.t('Yesterday')}
  404. {$i18n.t('Previous 7 days')}
  405. {$i18n.t('Previous 30 days')}
  406. {$i18n.t('January')}
  407. {$i18n.t('February')}
  408. {$i18n.t('March')}
  409. {$i18n.t('April')}
  410. {$i18n.t('May')}
  411. {$i18n.t('June')}
  412. {$i18n.t('July')}
  413. {$i18n.t('August')}
  414. {$i18n.t('September')}
  415. {$i18n.t('October')}
  416. {$i18n.t('November')}
  417. {$i18n.t('December')}
  418. -->
  419. </div>
  420. {/if}
  421. <div class=" w-full pr-2 relative group">
  422. {#if chatTitleEditId === chat.id}
  423. <div
  424. class=" w-full flex justify-between rounded-xl px-3 py-2 {chat.id === $chatId ||
  425. chat.id === chatTitleEditId ||
  426. chat.id === chatDeleteId
  427. ? 'bg-gray-200 dark:bg-gray-900'
  428. : chat.id === selectedChatId
  429. ? 'bg-gray-100 dark:bg-gray-950'
  430. : 'group-hover:bg-gray-100 dark:group-hover:bg-gray-950'} whitespace-nowrap text-ellipsis"
  431. >
  432. <input bind:value={chatTitle} class=" bg-transparent w-full outline-none mr-10" />
  433. </div>
  434. {:else}
  435. <a
  436. class=" w-full flex justify-between rounded-xl px-3 py-2 {chat.id === $chatId ||
  437. chat.id === chatTitleEditId ||
  438. chat.id === chatDeleteId
  439. ? 'bg-gray-200 dark:bg-gray-900'
  440. : chat.id === selectedChatId
  441. ? 'bg-gray-100 dark:bg-gray-950'
  442. : ' group-hover:bg-gray-100 dark:group-hover:bg-gray-950'} whitespace-nowrap text-ellipsis"
  443. href="/c/{chat.id}"
  444. on:click={() => {
  445. selectedChatId = chat.id;
  446. if (window.innerWidth < 1024) {
  447. showSidebar.set(false);
  448. }
  449. }}
  450. draggable="false"
  451. >
  452. <div class=" flex self-center flex-1 w-full">
  453. <div class=" text-left self-center overflow-hidden w-full h-[20px]">
  454. {chat.title}
  455. </div>
  456. </div>
  457. </a>
  458. {/if}
  459. <div
  460. class="
  461. {chat.id === $chatId || chat.id === chatTitleEditId || chat.id === chatDeleteId
  462. ? 'from-gray-200 dark:from-gray-900'
  463. : chat.id === selectedChatId
  464. ? 'from-gray-100 dark:from-gray-950'
  465. : 'invisible group-hover:visible from-gray-100 dark:from-gray-950'}
  466. absolute right-[10px] top-[10px] pr-2 pl-5 bg-gradient-to-l from-80%
  467. to-transparent"
  468. >
  469. {#if chatTitleEditId === chat.id}
  470. <div class="flex self-center space-x-1.5 z-10">
  471. <button
  472. class=" self-center dark:hover:text-white transition"
  473. on:click={() => {
  474. editChatTitle(chat.id, chatTitle);
  475. chatTitleEditId = null;
  476. chatTitle = '';
  477. }}
  478. >
  479. <svg
  480. xmlns="http://www.w3.org/2000/svg"
  481. viewBox="0 0 20 20"
  482. fill="currentColor"
  483. class="w-4 h-4"
  484. >
  485. <path
  486. fill-rule="evenodd"
  487. 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"
  488. clip-rule="evenodd"
  489. />
  490. </svg>
  491. </button>
  492. <button
  493. class=" self-center dark:hover:text-white transition"
  494. on:click={() => {
  495. chatTitleEditId = null;
  496. chatTitle = '';
  497. }}
  498. >
  499. <svg
  500. xmlns="http://www.w3.org/2000/svg"
  501. viewBox="0 0 20 20"
  502. fill="currentColor"
  503. class="w-4 h-4"
  504. >
  505. <path
  506. 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"
  507. />
  508. </svg>
  509. </button>
  510. </div>
  511. {:else if chatDeleteId === chat.id}
  512. <div class="flex self-center space-x-1.5 z-10">
  513. <button
  514. class=" self-center dark:hover:text-white transition"
  515. on:click={() => {
  516. deleteChat(chat.id);
  517. }}
  518. >
  519. <svg
  520. xmlns="http://www.w3.org/2000/svg"
  521. viewBox="0 0 20 20"
  522. fill="currentColor"
  523. class="w-4 h-4"
  524. >
  525. <path
  526. fill-rule="evenodd"
  527. 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"
  528. clip-rule="evenodd"
  529. />
  530. </svg>
  531. </button>
  532. <button
  533. class=" self-center dark:hover:text-white transition"
  534. on:click={() => {
  535. chatDeleteId = null;
  536. }}
  537. >
  538. <svg
  539. xmlns="http://www.w3.org/2000/svg"
  540. viewBox="0 0 20 20"
  541. fill="currentColor"
  542. class="w-4 h-4"
  543. >
  544. <path
  545. 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"
  546. />
  547. </svg>
  548. </button>
  549. </div>
  550. {:else}
  551. <div class="flex self-center space-x-1 z-10">
  552. <ChatMenu
  553. chatId={chat.id}
  554. shareHandler={() => {
  555. shareChatId = selectedChatId;
  556. showShareChatModal = true;
  557. }}
  558. renameHandler={() => {
  559. chatTitle = chat.title;
  560. chatTitleEditId = chat.id;
  561. }}
  562. deleteHandler={() => {
  563. chatDeleteId = chat.id;
  564. }}
  565. onClose={() => {
  566. selectedChatId = null;
  567. }}
  568. >
  569. <button
  570. aria-label="Chat Menu"
  571. class=" self-center dark:hover:text-white transition"
  572. on:click={() => {
  573. selectedChatId = chat.id;
  574. }}
  575. >
  576. <svg
  577. xmlns="http://www.w3.org/2000/svg"
  578. viewBox="0 0 16 16"
  579. fill="currentColor"
  580. class="w-4 h-4"
  581. >
  582. <path
  583. 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"
  584. />
  585. </svg>
  586. </button>
  587. </ChatMenu>
  588. <Tooltip content={$i18n.t('Archive')}>
  589. <button
  590. aria-label="Archive"
  591. class=" self-center dark:hover:text-white transition"
  592. on:click={() => {
  593. archiveChatHandler(chat.id);
  594. }}
  595. >
  596. <ArchiveBox />
  597. </button>
  598. </Tooltip>
  599. {#if chat.id === $chatId}
  600. <button
  601. id="delete-chat-button"
  602. class="hidden"
  603. on:click={() => {
  604. chatDeleteId = chat.id;
  605. }}
  606. >
  607. <svg
  608. xmlns="http://www.w3.org/2000/svg"
  609. viewBox="0 0 16 16"
  610. fill="currentColor"
  611. class="w-4 h-4"
  612. >
  613. <path
  614. 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"
  615. />
  616. </svg>
  617. </button>
  618. {/if}
  619. </div>
  620. {/if}
  621. </div>
  622. </div>
  623. {/each}
  624. </div>
  625. </div>
  626. <div class="px-2.5">
  627. <!-- <hr class=" border-gray-900 mb-1 w-full" /> -->
  628. <div class="flex flex-col">
  629. {#if $user !== undefined}
  630. <button
  631. class=" flex rounded-xl py-3 px-3.5 w-full hover:bg-gray-100 dark:hover:bg-gray-900 transition"
  632. on:click={() => {
  633. showDropdown = !showDropdown;
  634. }}
  635. >
  636. <div class=" self-center mr-3">
  637. <img
  638. src={$user.profile_image_url}
  639. class=" max-w-[30px] object-cover rounded-full"
  640. alt="User profile"
  641. />
  642. </div>
  643. <div class=" self-center font-semibold">{$user.name}</div>
  644. </button>
  645. {#if showDropdown}
  646. <div
  647. id="dropdownDots"
  648. class="absolute z-40 bottom-[70px] rounded-lg shadow w-[240px] bg-white dark:bg-gray-900"
  649. transition:fade|slide={{ duration: 100 }}
  650. >
  651. <div class="p-1 py-2 w-full">
  652. {#if $user.role === 'admin'}
  653. <button
  654. class="flex rounded-md py-2.5 px-3.5 w-full hover:bg-gray-100 dark:hover:bg-gray-800 transition"
  655. on:click={() => {
  656. goto('/admin');
  657. showDropdown = false;
  658. }}
  659. >
  660. <div class=" self-center mr-3">
  661. <svg
  662. xmlns="http://www.w3.org/2000/svg"
  663. fill="none"
  664. viewBox="0 0 24 24"
  665. stroke-width="1.5"
  666. stroke="currentColor"
  667. class="w-5 h-5"
  668. >
  669. <path
  670. stroke-linecap="round"
  671. stroke-linejoin="round"
  672. d="M17.982 18.725A7.488 7.488 0 0012 15.75a7.488 7.488 0 00-5.982 2.975m11.963 0a9 9 0 10-11.963 0m11.963 0A8.966 8.966 0 0112 21a8.966 8.966 0 01-5.982-2.275M15 9.75a3 3 0 11-6 0 3 3 0 016 0z"
  673. />
  674. </svg>
  675. </div>
  676. <div class=" self-center font-medium">{$i18n.t('Admin Panel')}</div>
  677. </button>
  678. <button
  679. class="flex rounded-md py-2.5 px-3.5 w-full hover:bg-gray-100 dark:hover:bg-gray-800 transition"
  680. on:click={() => {
  681. goto('/playground');
  682. showDropdown = false;
  683. }}
  684. >
  685. <div class=" self-center mr-3">
  686. <svg
  687. xmlns="http://www.w3.org/2000/svg"
  688. fill="none"
  689. viewBox="0 0 24 24"
  690. stroke-width="1.5"
  691. stroke="currentColor"
  692. class="w-5 h-5"
  693. >
  694. <path
  695. stroke-linecap="round"
  696. stroke-linejoin="round"
  697. d="m6.75 7.5 3 2.25-3 2.25m4.5 0h3m-9 8.25h13.5A2.25 2.25 0 0 0 21 18V6a2.25 2.25 0 0 0-2.25-2.25H5.25A2.25 2.25 0 0 0 3 6v12a2.25 2.25 0 0 0 2.25 2.25Z"
  698. />
  699. </svg>
  700. </div>
  701. <div class=" self-center font-medium">{$i18n.t('Playground')}</div>
  702. </button>
  703. {/if}
  704. <button
  705. class="flex rounded-md py-2.5 px-3.5 w-full hover:bg-gray-100 dark:hover:bg-gray-800 transition"
  706. on:click={() => {
  707. showArchivedChatsModal = true;
  708. showDropdown = false;
  709. }}
  710. >
  711. <div class=" self-center mr-3">
  712. <ArchiveBox className="size-5" strokeWidth="1.5" />
  713. </div>
  714. <div class=" self-center font-medium">{$i18n.t('Archived Chats')}</div>
  715. </button>
  716. <button
  717. class="flex rounded-md py-2.5 px-3.5 w-full hover:bg-gray-100 dark:hover:bg-gray-800 transition"
  718. on:click={async () => {
  719. await showSettings.set(true);
  720. showDropdown = false;
  721. }}
  722. >
  723. <div class=" self-center mr-3">
  724. <svg
  725. xmlns="http://www.w3.org/2000/svg"
  726. fill="none"
  727. viewBox="0 0 24 24"
  728. stroke-width="1.5"
  729. stroke="currentColor"
  730. class="w-5 h-5"
  731. >
  732. <path
  733. stroke-linecap="round"
  734. stroke-linejoin="round"
  735. d="M10.343 3.94c.09-.542.56-.94 1.11-.94h1.093c.55 0 1.02.398 1.11.94l.149.894c.07.424.384.764.78.93.398.164.855.142 1.205-.108l.737-.527a1.125 1.125 0 011.45.12l.773.774c.39.389.44 1.002.12 1.45l-.527.737c-.25.35-.272.806-.107 1.204.165.397.505.71.93.78l.893.15c.543.09.94.56.94 1.109v1.094c0 .55-.397 1.02-.94 1.11l-.893.149c-.425.07-.765.383-.93.78-.165.398-.143.854.107 1.204l.527.738c.32.447.269 1.06-.12 1.45l-.774.773a1.125 1.125 0 01-1.449.12l-.738-.527c-.35-.25-.806-.272-1.203-.107-.397.165-.71.505-.781.929l-.149.894c-.09.542-.56.94-1.11.94h-1.094c-.55 0-1.019-.398-1.11-.94l-.148-.894c-.071-.424-.384-.764-.781-.93-.398-.164-.854-.142-1.204.108l-.738.527c-.447.32-1.06.269-1.45-.12l-.773-.774a1.125 1.125 0 01-.12-1.45l.527-.737c.25-.35.273-.806.108-1.204-.165-.397-.505-.71-.93-.78l-.894-.15c-.542-.09-.94-.56-.94-1.109v-1.094c0-.55.398-1.02.94-1.11l.894-.149c.424-.07.765-.383.93-.78.165-.398.143-.854-.107-1.204l-.527-.738a1.125 1.125 0 01.12-1.45l.773-.773a1.125 1.125 0 011.45-.12l.737.527c.35.25.807.272 1.204.107.397-.165.71-.505.78-.929l.15-.894z"
  736. />
  737. <path
  738. stroke-linecap="round"
  739. stroke-linejoin="round"
  740. d="M15 12a3 3 0 11-6 0 3 3 0 016 0z"
  741. />
  742. </svg>
  743. </div>
  744. <div class=" self-center font-medium">{$i18n.t('Settings')}</div>
  745. </button>
  746. </div>
  747. <hr class=" dark:border-gray-800 m-0 p-0" />
  748. <div class="p-1 py-2 w-full">
  749. <button
  750. class="flex rounded-md py-2.5 px-3.5 w-full hover:bg-gray-100 dark:hover:bg-gray-800 transition"
  751. on:click={() => {
  752. localStorage.removeItem('token');
  753. location.href = '/auth';
  754. showDropdown = false;
  755. }}
  756. >
  757. <div class=" self-center mr-3">
  758. <svg
  759. xmlns="http://www.w3.org/2000/svg"
  760. viewBox="0 0 20 20"
  761. fill="currentColor"
  762. class="w-5 h-5"
  763. >
  764. <path
  765. fill-rule="evenodd"
  766. d="M3 4.25A2.25 2.25 0 015.25 2h5.5A2.25 2.25 0 0113 4.25v2a.75.75 0 01-1.5 0v-2a.75.75 0 00-.75-.75h-5.5a.75.75 0 00-.75.75v11.5c0 .414.336.75.75.75h5.5a.75.75 0 00.75-.75v-2a.75.75 0 011.5 0v2A2.25 2.25 0 0110.75 18h-5.5A2.25 2.25 0 013 15.75V4.25z"
  767. clip-rule="evenodd"
  768. />
  769. <path
  770. fill-rule="evenodd"
  771. d="M6 10a.75.75 0 01.75-.75h9.546l-1.048-.943a.75.75 0 111.004-1.114l2.5 2.25a.75.75 0 010 1.114l-2.5 2.25a.75.75 0 11-1.004-1.114l1.048-.943H6.75A.75.75 0 016 10z"
  772. clip-rule="evenodd"
  773. />
  774. </svg>
  775. </div>
  776. <div class=" self-center font-medium">{$i18n.t('Sign Out')}</div>
  777. </button>
  778. </div>
  779. </div>
  780. {/if}
  781. {/if}
  782. </div>
  783. </div>
  784. </div>
  785. <div
  786. id="sidebar-handle"
  787. class="fixed left-0 top-[50dvh] -translate-y-1/2 transition-transform translate-x-[255px] md:translate-x-[260px] rotate-0"
  788. >
  789. <Tooltip
  790. placement="right"
  791. content={`${$showSidebar ? $i18n.t('Close') : $i18n.t('Open')} ${$i18n.t('sidebar')}`}
  792. touch={false}
  793. >
  794. <button
  795. id="sidebar-toggle-button"
  796. class=" group"
  797. on:click={() => {
  798. showSidebar.set(!$showSidebar);
  799. }}
  800. ><span class="" data-state="closed"
  801. ><div
  802. class="flex h-[72px] w-8 items-center justify-center opacity-50 group-hover:opacity-100 transition"
  803. >
  804. <div class="flex h-6 w-6 flex-col items-center">
  805. <div
  806. class="h-3 w-1 rounded-full bg-[#0f0f0f] dark:bg-white rotate-0 translate-y-[0.15rem] {$showSidebar
  807. ? 'group-hover:rotate-[15deg]'
  808. : 'group-hover:rotate-[-15deg]'}"
  809. />
  810. <div
  811. class="h-3 w-1 rounded-full bg-[#0f0f0f] dark:bg-white rotate-0 translate-y-[-0.15rem] {$showSidebar
  812. ? 'group-hover:rotate-[-15deg]'
  813. : 'group-hover:rotate-[15deg]'}"
  814. />
  815. </div>
  816. </div>
  817. </span>
  818. </button>
  819. </Tooltip>
  820. </div>
  821. </div>
  822. <style>
  823. .scrollbar-none:active::-webkit-scrollbar-thumb,
  824. .scrollbar-none:focus::-webkit-scrollbar-thumb,
  825. .scrollbar-none:hover::-webkit-scrollbar-thumb {
  826. visibility: visible;
  827. }
  828. .scrollbar-none::-webkit-scrollbar-thumb {
  829. visibility: hidden;
  830. }
  831. </style>