Sidebar.svelte 19 KB

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