Sidebar.svelte 19 KB

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