Sidebar.svelte 21 KB

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