Sidebar.svelte 21 KB

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