Sidebar.svelte 21 KB

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