Sidebar.svelte 26 KB

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