Sidebar.svelte 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804
  1. <script lang="ts">
  2. import { toast } from 'svelte-sonner';
  3. import { goto } from '$app/navigation';
  4. import {
  5. user,
  6. chats,
  7. settings,
  8. showSettings,
  9. chatId,
  10. tags,
  11. showSidebar,
  12. mobile,
  13. showArchivedChats,
  14. pinnedChats,
  15. scrollPaginationEnabled,
  16. currentChatPage,
  17. temporaryChatEnabled
  18. } from '$lib/stores';
  19. import { onMount, getContext, tick, onDestroy } from 'svelte';
  20. const i18n = getContext('i18n');
  21. import {
  22. deleteChatById,
  23. getChatList,
  24. getAllTags,
  25. getChatListBySearchText,
  26. createNewChat,
  27. getPinnedChatList,
  28. toggleChatPinnedStatusById,
  29. getChatPinnedStatusById
  30. } from '$lib/apis/chats';
  31. import { WEBUI_BASE_URL } from '$lib/constants';
  32. import ArchivedChatsModal from './Sidebar/ArchivedChatsModal.svelte';
  33. import UserMenu from './Sidebar/UserMenu.svelte';
  34. import ChatItem from './Sidebar/ChatItem.svelte';
  35. import DeleteConfirmDialog from '$lib/components/common/ConfirmDialog.svelte';
  36. import Spinner from '../common/Spinner.svelte';
  37. import Loader from '../common/Loader.svelte';
  38. import AddFilesPlaceholder from '../AddFilesPlaceholder.svelte';
  39. import SearchInput from './Sidebar/SearchInput.svelte';
  40. import Folder from '../common/Folder.svelte';
  41. import Plus from '../icons/Plus.svelte';
  42. import Tooltip from '../common/Tooltip.svelte';
  43. import { createNewFolder, getFolders } from '$lib/apis/folders';
  44. import Folders from './Sidebar/Folders.svelte';
  45. const BREAKPOINT = 768;
  46. let navElement;
  47. let search = '';
  48. let shiftKey = false;
  49. let selectedChatId = null;
  50. let deleteChat = null;
  51. let showDeleteConfirm = false;
  52. let showDropdown = false;
  53. let selectedTagName = null;
  54. let showPinnedChat = true;
  55. // Pagination variables
  56. let chatListLoading = false;
  57. let allChatsLoaded = false;
  58. let folders = {};
  59. const initFolders = async () => {
  60. const folderList = await getFolders(localStorage.token).catch((error) => {
  61. toast.error(error);
  62. return [];
  63. });
  64. folders = {};
  65. for (const folder of folderList) {
  66. folders[folder.id] = { ...(folders[folder.id] ? folders[folder.id] : {}), ...folder };
  67. if (folders[folder.id].parent_id) {
  68. folders[folders[folder.id].parent_id].childrenIds = folders[folders[folder.id].parent_id]
  69. .childrenIds
  70. ? [...folders[folders[folder.id].parent_id].childrenIds, folder.id]
  71. : [folder.id];
  72. folders[folders[folder.id].parent_id].childrenIds.sort((a, b) => {
  73. return folders[b].updated_at - folders[a].updated_at;
  74. });
  75. }
  76. }
  77. };
  78. const createFolder = async (name = 'Untitled') => {
  79. if (name === '') {
  80. toast.error($i18n.t('Folder name cannot be empty.'));
  81. return;
  82. }
  83. if (Object.values(folders).find((folder) => folder.name.toLowerCase() === name.toLowerCase())) {
  84. // If a folder with the same name already exists, append a number to the name
  85. let i = 1;
  86. while (
  87. Object.values(folders).find(
  88. (folder) => folder.name.toLowerCase() === `${name} ${i}`.toLowerCase()
  89. )
  90. ) {
  91. i++;
  92. }
  93. name = `${name} ${i}`;
  94. }
  95. const res = await createNewFolder(localStorage.token, name).catch((error) => {
  96. toast.error(error);
  97. return null;
  98. });
  99. if (res) {
  100. await initFolders();
  101. }
  102. };
  103. const initChatList = async () => {
  104. // Reset pagination variables
  105. tags.set(await getAllTags(localStorage.token));
  106. currentChatPage.set(1);
  107. allChatsLoaded = false;
  108. await chats.set(await getChatList(localStorage.token, $currentChatPage));
  109. // Enable pagination
  110. scrollPaginationEnabled.set(true);
  111. };
  112. const loadMoreChats = async () => {
  113. chatListLoading = true;
  114. currentChatPage.set($currentChatPage + 1);
  115. let newChatList = [];
  116. if (search) {
  117. newChatList = await getChatListBySearchText(localStorage.token, search, $currentChatPage);
  118. } else {
  119. newChatList = await getChatList(localStorage.token, $currentChatPage);
  120. }
  121. // once the bottom of the list has been reached (no results) there is no need to continue querying
  122. allChatsLoaded = newChatList.length === 0;
  123. await chats.set([...($chats ? $chats : []), ...newChatList]);
  124. chatListLoading = false;
  125. };
  126. let searchDebounceTimeout;
  127. const searchDebounceHandler = async () => {
  128. console.log('search', search);
  129. chats.set(null);
  130. selectedTagName = null;
  131. if (searchDebounceTimeout) {
  132. clearTimeout(searchDebounceTimeout);
  133. }
  134. if (search === '') {
  135. await initChatList();
  136. return;
  137. } else {
  138. searchDebounceTimeout = setTimeout(async () => {
  139. currentChatPage.set(1);
  140. await chats.set(await getChatListBySearchText(localStorage.token, search));
  141. if ($chats.length === 0) {
  142. tags.set(await getAllTags(localStorage.token));
  143. }
  144. }, 1000);
  145. }
  146. };
  147. const deleteChatHandler = async (id) => {
  148. const res = await deleteChatById(localStorage.token, id).catch((error) => {
  149. toast.error(error);
  150. return null;
  151. });
  152. if (res) {
  153. tags.set(await getAllTags(localStorage.token));
  154. if ($chatId === id) {
  155. await chatId.set('');
  156. await tick();
  157. goto('/');
  158. }
  159. allChatsLoaded = false;
  160. currentChatPage.set(1);
  161. await chats.set(await getChatList(localStorage.token, $currentChatPage));
  162. await pinnedChats.set(await getPinnedChatList(localStorage.token));
  163. }
  164. };
  165. const inputFilesHandler = async (files) => {
  166. console.log(files);
  167. for (const file of files) {
  168. const reader = new FileReader();
  169. reader.onload = async (e) => {
  170. const content = e.target.result;
  171. try {
  172. const items = JSON.parse(content);
  173. for (const item of items) {
  174. if (item.chat) {
  175. await createNewChat(localStorage.token, item.chat);
  176. }
  177. }
  178. } catch {
  179. toast.error($i18n.t(`Invalid file format.`));
  180. }
  181. initChatList();
  182. };
  183. reader.readAsText(file);
  184. }
  185. };
  186. const tagEventHandler = async (type, tagName, chatId) => {
  187. console.log(type, tagName, chatId);
  188. if (type === 'delete') {
  189. currentChatPage.set(1);
  190. await chats.set(await getChatListBySearchText(localStorage.token, search, $currentChatPage));
  191. } else if (type === 'add') {
  192. currentChatPage.set(1);
  193. await chats.set(await getChatListBySearchText(localStorage.token, search, $currentChatPage));
  194. }
  195. };
  196. let dragged = false;
  197. const onDragOver = (e) => {
  198. e.preventDefault();
  199. // Check if a file is being dragged.
  200. if (e.dataTransfer?.types?.includes('Files')) {
  201. dragged = true;
  202. } else {
  203. dragged = false;
  204. }
  205. };
  206. const onDragLeave = () => {
  207. dragged = false;
  208. };
  209. const onDrop = async (e) => {
  210. e.preventDefault();
  211. console.log(e); // Log the drop event
  212. // Perform file drop check and handle it accordingly
  213. if (e.dataTransfer?.files) {
  214. const inputFiles = Array.from(e.dataTransfer?.files);
  215. if (inputFiles && inputFiles.length > 0) {
  216. console.log(inputFiles); // Log the dropped files
  217. inputFilesHandler(inputFiles); // Handle the dropped files
  218. }
  219. }
  220. dragged = false; // Reset dragged status after drop
  221. };
  222. let touchstart;
  223. let touchend;
  224. function checkDirection() {
  225. const screenWidth = window.innerWidth;
  226. const swipeDistance = Math.abs(touchend.screenX - touchstart.screenX);
  227. if (touchstart.clientX < 40 && swipeDistance >= screenWidth / 8) {
  228. if (touchend.screenX < touchstart.screenX) {
  229. showSidebar.set(false);
  230. }
  231. if (touchend.screenX > touchstart.screenX) {
  232. showSidebar.set(true);
  233. }
  234. }
  235. }
  236. const onTouchStart = (e) => {
  237. touchstart = e.changedTouches[0];
  238. console.log(touchstart.clientX);
  239. };
  240. const onTouchEnd = (e) => {
  241. touchend = e.changedTouches[0];
  242. checkDirection();
  243. };
  244. const onKeyDown = (e) => {
  245. if (e.key === 'Shift') {
  246. shiftKey = true;
  247. }
  248. };
  249. const onKeyUp = (e) => {
  250. if (e.key === 'Shift') {
  251. shiftKey = false;
  252. }
  253. };
  254. const onFocus = () => {};
  255. const onBlur = () => {
  256. shiftKey = false;
  257. selectedChatId = null;
  258. };
  259. onMount(async () => {
  260. showPinnedChat = localStorage?.showPinnedChat ? localStorage.showPinnedChat === 'true' : true;
  261. mobile.subscribe((e) => {
  262. if ($showSidebar && e) {
  263. showSidebar.set(false);
  264. }
  265. if (!$showSidebar && !e) {
  266. showSidebar.set(true);
  267. }
  268. });
  269. showSidebar.set(!$mobile ? localStorage.sidebar === 'true' : false);
  270. showSidebar.subscribe((value) => {
  271. localStorage.sidebar = value;
  272. });
  273. await initFolders();
  274. await pinnedChats.set(await getPinnedChatList(localStorage.token));
  275. await initChatList();
  276. window.addEventListener('keydown', onKeyDown);
  277. window.addEventListener('keyup', onKeyUp);
  278. window.addEventListener('touchstart', onTouchStart);
  279. window.addEventListener('touchend', onTouchEnd);
  280. window.addEventListener('focus', onFocus);
  281. window.addEventListener('blur', onBlur);
  282. const dropZone = document.getElementById('sidebar');
  283. dropZone?.addEventListener('dragover', onDragOver);
  284. dropZone?.addEventListener('drop', onDrop);
  285. dropZone?.addEventListener('dragleave', onDragLeave);
  286. });
  287. onDestroy(() => {
  288. window.removeEventListener('keydown', onKeyDown);
  289. window.removeEventListener('keyup', onKeyUp);
  290. window.removeEventListener('touchstart', onTouchStart);
  291. window.removeEventListener('touchend', onTouchEnd);
  292. window.removeEventListener('focus', onFocus);
  293. window.removeEventListener('blur', onBlur);
  294. const dropZone = document.getElementById('sidebar');
  295. dropZone?.removeEventListener('dragover', onDragOver);
  296. dropZone?.removeEventListener('drop', onDrop);
  297. dropZone?.removeEventListener('dragleave', onDragLeave);
  298. });
  299. </script>
  300. <ArchivedChatsModal
  301. bind:show={$showArchivedChats}
  302. on:change={async () => {
  303. await pinnedChats.set(await getPinnedChatList(localStorage.token));
  304. await initChatList();
  305. }}
  306. />
  307. <DeleteConfirmDialog
  308. bind:show={showDeleteConfirm}
  309. title={$i18n.t('Delete chat?')}
  310. on:confirm={() => {
  311. deleteChatHandler(deleteChat.id);
  312. }}
  313. >
  314. <div class=" text-sm text-gray-500 flex-1 line-clamp-3">
  315. {$i18n.t('This will delete')} <span class=" font-semibold">{deleteChat.title}</span>.
  316. </div>
  317. </DeleteConfirmDialog>
  318. <!-- svelte-ignore a11y-no-static-element-interactions -->
  319. {#if $showSidebar}
  320. <div
  321. 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"
  322. on:mousedown={() => {
  323. showSidebar.set(!$showSidebar);
  324. }}
  325. />
  326. {/if}
  327. <div
  328. bind:this={navElement}
  329. id="sidebar"
  330. class="h-screen max-h-[100dvh] min-h-screen select-none {$showSidebar
  331. ? 'md:relative w-[260px] max-w-[260px]'
  332. : '-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 overflow-x-hidden
  333. "
  334. data-state={$showSidebar}
  335. >
  336. {#if dragged}
  337. <div
  338. class="absolute w-full h-full max-h-full backdrop-blur bg-gray-800/40 flex justify-center z-[999] touch-none pointer-events-none"
  339. >
  340. <div class="m-auto pt-64 flex flex-col justify-center">
  341. <AddFilesPlaceholder
  342. title={$i18n.t('Drop Chat Export')}
  343. content={$i18n.t('Drop a chat export file here to import it.')}
  344. />
  345. </div>
  346. </div>
  347. {/if}
  348. <div
  349. class="py-2.5 my-auto flex flex-col justify-between h-screen max-h-[100dvh] w-[260px] overflow-x-hidden z-50 {$showSidebar
  350. ? ''
  351. : 'invisible'}"
  352. >
  353. <div class="px-2.5 flex justify-between space-x-1 text-gray-600 dark:text-gray-400">
  354. <a
  355. id="sidebar-new-chat-button"
  356. class="flex flex-1 justify-between rounded-lg px-2 h-full hover:bg-gray-100 dark:hover:bg-gray-900 transition"
  357. href="/"
  358. draggable="false"
  359. on:click={async () => {
  360. selectedChatId = null;
  361. await goto('/');
  362. const newChatButton = document.getElementById('new-chat-button');
  363. setTimeout(() => {
  364. newChatButton?.click();
  365. if ($mobile) {
  366. showSidebar.set(false);
  367. }
  368. }, 0);
  369. }}
  370. >
  371. <div class="self-center mx-1.5">
  372. <img
  373. crossorigin="anonymous"
  374. src="{WEBUI_BASE_URL}/static/favicon.png"
  375. class=" size-6 -translate-x-1.5 rounded-full"
  376. alt="logo"
  377. />
  378. </div>
  379. <div class=" self-center font-medium text-sm text-gray-850 dark:text-white font-primary">
  380. {$i18n.t('New Chat')}
  381. </div>
  382. <div class="self-center ml-auto">
  383. <svg
  384. xmlns="http://www.w3.org/2000/svg"
  385. viewBox="0 0 20 20"
  386. fill="currentColor"
  387. class="size-5"
  388. >
  389. <path
  390. 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"
  391. />
  392. <path
  393. 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"
  394. />
  395. </svg>
  396. </div>
  397. </a>
  398. <button
  399. class=" cursor-pointer px-2 py-2 flex rounded-lg hover:bg-gray-100 dark:hover:bg-gray-900 transition"
  400. on:click={() => {
  401. showSidebar.set(!$showSidebar);
  402. }}
  403. >
  404. <div class=" m-auto self-center">
  405. <svg
  406. xmlns="http://www.w3.org/2000/svg"
  407. fill="none"
  408. viewBox="0 0 24 24"
  409. stroke-width="2"
  410. stroke="currentColor"
  411. class="size-5"
  412. >
  413. <path
  414. stroke-linecap="round"
  415. stroke-linejoin="round"
  416. d="M3.75 6.75h16.5M3.75 12h16.5m-16.5 5.25H12"
  417. />
  418. </svg>
  419. </div>
  420. </button>
  421. </div>
  422. {#if $user?.role === 'admin'}
  423. <div class="px-2.5 flex justify-center text-gray-800 dark:text-gray-200">
  424. <a
  425. class="flex-grow flex space-x-3 rounded-lg px-2.5 py-2 hover:bg-gray-100 dark:hover:bg-gray-900 transition"
  426. href="/workspace"
  427. on:click={() => {
  428. selectedChatId = null;
  429. chatId.set('');
  430. if ($mobile) {
  431. showSidebar.set(false);
  432. }
  433. }}
  434. draggable="false"
  435. >
  436. <div class="self-center">
  437. <svg
  438. xmlns="http://www.w3.org/2000/svg"
  439. fill="none"
  440. viewBox="0 0 24 24"
  441. stroke-width="2"
  442. stroke="currentColor"
  443. class="size-[1.1rem]"
  444. >
  445. <path
  446. stroke-linecap="round"
  447. stroke-linejoin="round"
  448. 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"
  449. />
  450. </svg>
  451. </div>
  452. <div class="flex self-center">
  453. <div class=" self-center font-medium text-sm font-primary">{$i18n.t('Workspace')}</div>
  454. </div>
  455. </a>
  456. </div>
  457. {/if}
  458. <div class="relative {$temporaryChatEnabled ? 'opacity-20' : ''}">
  459. {#if $temporaryChatEnabled}
  460. <div class="absolute z-40 w-full h-full flex justify-center"></div>
  461. {/if}
  462. <div class="absolute z-40 right-4 top-1">
  463. <Tooltip content={$i18n.t('New folder')}>
  464. <button
  465. class="p-1 rounded-lg bg-gray-50 hover:bg-gray-100 dark:bg-gray-950 dark:hover:bg-gray-900 transition"
  466. on:click={() => {
  467. createFolder();
  468. }}
  469. >
  470. <Plus />
  471. </button>
  472. </Tooltip>
  473. </div>
  474. <SearchInput
  475. bind:value={search}
  476. on:input={searchDebounceHandler}
  477. placeholder={$i18n.t('Search')}
  478. />
  479. </div>
  480. <div
  481. class="relative flex flex-col flex-1 overflow-y-auto {$temporaryChatEnabled
  482. ? 'opacity-20'
  483. : ''}"
  484. >
  485. {#if $temporaryChatEnabled}
  486. <div class="absolute z-40 w-full h-full flex justify-center"></div>
  487. {/if}
  488. {#if !search && $pinnedChats.length > 0}
  489. <div class="flex flex-col space-y-1 rounded-xl">
  490. <Folder
  491. className="px-2"
  492. bind:open={showPinnedChat}
  493. on:change={(e) => {
  494. localStorage.setItem('showPinnedChat', e.detail);
  495. console.log(e.detail);
  496. }}
  497. on:drop={async (e) => {
  498. const { type, id } = e.detail;
  499. if (type === 'chat') {
  500. const status = await getChatPinnedStatusById(localStorage.token, id);
  501. if (!status) {
  502. const res = await toggleChatPinnedStatusById(localStorage.token, id);
  503. if (res) {
  504. await pinnedChats.set(await getPinnedChatList(localStorage.token));
  505. initChatList();
  506. }
  507. }
  508. }
  509. }}
  510. name={$i18n.t('Pinned')}
  511. >
  512. <div
  513. class="ml-3 pl-1 mt-[1px] flex flex-col overflow-y-auto scrollbar-hidden border-s dark:border-gray-850"
  514. >
  515. {#each $pinnedChats as chat, idx}
  516. <ChatItem
  517. className=""
  518. id={chat.id}
  519. title={chat.title}
  520. {shiftKey}
  521. selected={selectedChatId === chat.id}
  522. on:select={() => {
  523. selectedChatId = chat.id;
  524. }}
  525. on:unselect={() => {
  526. selectedChatId = null;
  527. }}
  528. on:delete={(e) => {
  529. if ((e?.detail ?? '') === 'shift') {
  530. deleteChatHandler(chat.id);
  531. } else {
  532. deleteChat = chat;
  533. showDeleteConfirm = true;
  534. }
  535. }}
  536. on:change={async () => {
  537. await pinnedChats.set(await getPinnedChatList(localStorage.token));
  538. initChatList();
  539. }}
  540. on:tag={(e) => {
  541. const { type, name } = e.detail;
  542. tagEventHandler(type, name, chat.id);
  543. }}
  544. />
  545. {/each}
  546. </div>
  547. </Folder>
  548. </div>
  549. {/if}
  550. <div class=" flex-1 flex flex-col overflow-y-auto scrollbar-hidden">
  551. {#if !search && folders}
  552. <Folders {folders} />
  553. {/if}
  554. <Folder
  555. collapsible={!search}
  556. className="px-2"
  557. name={$i18n.t('All chats')}
  558. on:drop={async (e) => {
  559. const { type, id } = e.detail;
  560. if (type === 'chat') {
  561. const status = await getChatPinnedStatusById(localStorage.token, id);
  562. if (status) {
  563. const res = await toggleChatPinnedStatusById(localStorage.token, id);
  564. if (res) {
  565. await pinnedChats.set(await getPinnedChatList(localStorage.token));
  566. initChatList();
  567. }
  568. }
  569. }
  570. }}
  571. >
  572. <div class="pt-1.5">
  573. {#if $chats}
  574. {#each $chats as chat, idx}
  575. {#if idx === 0 || (idx > 0 && chat.time_range !== $chats[idx - 1].time_range)}
  576. <div
  577. class="w-full pl-2.5 text-xs text-gray-500 dark:text-gray-500 font-medium {idx ===
  578. 0
  579. ? ''
  580. : 'pt-5'} pb-1.5"
  581. >
  582. {$i18n.t(chat.time_range)}
  583. <!-- localisation keys for time_range to be recognized from the i18next parser (so they don't get automatically removed):
  584. {$i18n.t('Today')}
  585. {$i18n.t('Yesterday')}
  586. {$i18n.t('Previous 7 days')}
  587. {$i18n.t('Previous 30 days')}
  588. {$i18n.t('January')}
  589. {$i18n.t('February')}
  590. {$i18n.t('March')}
  591. {$i18n.t('April')}
  592. {$i18n.t('May')}
  593. {$i18n.t('June')}
  594. {$i18n.t('July')}
  595. {$i18n.t('August')}
  596. {$i18n.t('September')}
  597. {$i18n.t('October')}
  598. {$i18n.t('November')}
  599. {$i18n.t('December')}
  600. -->
  601. </div>
  602. {/if}
  603. <ChatItem
  604. className=""
  605. id={chat.id}
  606. title={chat.title}
  607. {shiftKey}
  608. selected={selectedChatId === chat.id}
  609. on:select={() => {
  610. selectedChatId = chat.id;
  611. }}
  612. on:unselect={() => {
  613. selectedChatId = null;
  614. }}
  615. on:delete={(e) => {
  616. if ((e?.detail ?? '') === 'shift') {
  617. deleteChatHandler(chat.id);
  618. } else {
  619. deleteChat = chat;
  620. showDeleteConfirm = true;
  621. }
  622. }}
  623. on:change={async () => {
  624. await pinnedChats.set(await getPinnedChatList(localStorage.token));
  625. initChatList();
  626. }}
  627. on:tag={(e) => {
  628. const { type, name } = e.detail;
  629. tagEventHandler(type, name, chat.id);
  630. }}
  631. />
  632. {/each}
  633. {#if $scrollPaginationEnabled && !allChatsLoaded}
  634. <Loader
  635. on:visible={(e) => {
  636. if (!chatListLoading) {
  637. loadMoreChats();
  638. }
  639. }}
  640. >
  641. <div
  642. class="w-full flex justify-center py-1 text-xs animate-pulse items-center gap-2"
  643. >
  644. <Spinner className=" size-4" />
  645. <div class=" ">Loading...</div>
  646. </div>
  647. </Loader>
  648. {/if}
  649. {:else}
  650. <div class="w-full flex justify-center py-1 text-xs animate-pulse items-center gap-2">
  651. <Spinner className=" size-4" />
  652. <div class=" ">Loading...</div>
  653. </div>
  654. {/if}
  655. </div>
  656. </Folder>
  657. </div>
  658. </div>
  659. <div class="px-2">
  660. <div class="flex flex-col font-primary">
  661. {#if $user !== undefined}
  662. <UserMenu
  663. role={$user.role}
  664. on:show={(e) => {
  665. if (e.detail === 'archived-chat') {
  666. showArchivedChats.set(true);
  667. }
  668. }}
  669. >
  670. <button
  671. class=" flex items-center rounded-xl py-2.5 px-2.5 w-full hover:bg-gray-100 dark:hover:bg-gray-900 transition"
  672. on:click={() => {
  673. showDropdown = !showDropdown;
  674. }}
  675. >
  676. <div class=" self-center mr-3">
  677. <img
  678. src={$user.profile_image_url}
  679. class=" max-w-[30px] object-cover rounded-full"
  680. alt="User profile"
  681. />
  682. </div>
  683. <div class=" self-center font-medium">{$user.name}</div>
  684. </button>
  685. </UserMenu>
  686. {/if}
  687. </div>
  688. </div>
  689. </div>
  690. </div>
  691. <style>
  692. .scrollbar-hidden:active::-webkit-scrollbar-thumb,
  693. .scrollbar-hidden:focus::-webkit-scrollbar-thumb,
  694. .scrollbar-hidden:hover::-webkit-scrollbar-thumb {
  695. visibility: visible;
  696. }
  697. .scrollbar-hidden::-webkit-scrollbar-thumb {
  698. visibility: hidden;
  699. }
  700. </style>