Sidebar.svelte 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770
  1. <script lang="ts">
  2. import { v4 as uuidv4 } from 'uuid';
  3. import fileSaver from 'file-saver';
  4. const { saveAs } = fileSaver;
  5. import { goto, invalidateAll } from '$app/navigation';
  6. import { page } from '$app/stores';
  7. import { user, chats, settings, showSettings, chatId, tags } from '$lib/stores';
  8. import { onMount, getContext } from 'svelte';
  9. const i18n = getContext('i18n');
  10. import {
  11. deleteChatById,
  12. getChatList,
  13. getChatById,
  14. getChatListByTagName,
  15. updateChatById,
  16. getAllChatTags
  17. } from '$lib/apis/chats';
  18. import { toast } from 'svelte-sonner';
  19. import { fade, slide } from 'svelte/transition';
  20. import { WEBUI_BASE_URL } from '$lib/constants';
  21. import Tooltip from '../common/Tooltip.svelte';
  22. import ChatMenu from './Sidebar/ChatMenu.svelte';
  23. let show = false;
  24. let navElement;
  25. let title: string = 'UI';
  26. let search = '';
  27. let selectedChatId = null;
  28. let chatDeleteId = null;
  29. let chatTitleEditId = null;
  30. let chatTitle = '';
  31. let showDropdown = false;
  32. let isEditing = false;
  33. onMount(async () => {
  34. if (window.innerWidth > 1024) {
  35. show = true;
  36. }
  37. await chats.set(await getChatList(localStorage.token));
  38. let touchstartX = 0;
  39. let touchendX = 0;
  40. function checkDirection() {
  41. const screenWidth = window.innerWidth;
  42. const swipeDistance = Math.abs(touchendX - touchstartX);
  43. if (swipeDistance >= screenWidth / 4) {
  44. if (touchendX < touchstartX) {
  45. show = false;
  46. }
  47. if (touchendX > touchstartX) {
  48. show = true;
  49. }
  50. }
  51. }
  52. document.addEventListener('touchstart', (e) => {
  53. touchstartX = e.changedTouches[0].screenX;
  54. });
  55. document.addEventListener('touchend', (e) => {
  56. touchendX = e.changedTouches[0].screenX;
  57. checkDirection();
  58. });
  59. });
  60. // Helper function to fetch and add chat content to each chat
  61. const enrichChatsWithContent = async (chatList) => {
  62. const enrichedChats = await Promise.all(
  63. chatList.map(async (chat) => {
  64. const chatDetails = await getChatById(localStorage.token, chat.id).catch((error) => null); // Handle error or non-existent chat gracefully
  65. if (chatDetails) {
  66. chat.chat = chatDetails.chat; // Assuming chatDetails.chat contains the chat content
  67. }
  68. return chat;
  69. })
  70. );
  71. await chats.set(enrichedChats);
  72. };
  73. const loadChat = async (id) => {
  74. goto(`/c/${id}`);
  75. };
  76. const editChatTitle = async (id, _title) => {
  77. if (_title === '') {
  78. toast.error('Title cannot be an empty string.');
  79. } else {
  80. title = _title;
  81. await updateChatById(localStorage.token, id, {
  82. title: _title
  83. });
  84. await chats.set(await getChatList(localStorage.token));
  85. }
  86. };
  87. const deleteChat = async (id) => {
  88. const res = await deleteChatById(localStorage.token, id).catch((error) => {
  89. toast.error(error);
  90. chatDeleteId = null;
  91. return null;
  92. });
  93. if (res) {
  94. if ($chatId === id) {
  95. goto('/');
  96. }
  97. await chats.set(await getChatList(localStorage.token));
  98. }
  99. };
  100. const saveSettings = async (updated) => {
  101. await settings.set({ ...$settings, ...updated });
  102. localStorage.setItem('settings', JSON.stringify($settings));
  103. location.href = '/';
  104. };
  105. </script>
  106. <div
  107. bind:this={navElement}
  108. class="h-screen max-h-[100dvh] min-h-screen {show
  109. ? 'lg:relative w-[260px]'
  110. : '-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
  111. "
  112. >
  113. <div
  114. class="py-2.5 my-auto flex flex-col justify-between h-screen max-h-[100dvh] w-[260px] {show
  115. ? ''
  116. : 'invisible'}"
  117. >
  118. <div class="px-2 flex justify-center space-x-2">
  119. <a
  120. id="sidebar-new-chat-button"
  121. class="flex-grow flex justify-between rounded-xl px-4 py-2 hover:bg-gray-200 dark:hover:bg-gray-900 transition"
  122. href="/"
  123. on:click={async () => {
  124. selectedChatId = null;
  125. await goto('/');
  126. const newChatButton = document.getElementById('new-chat-button');
  127. setTimeout(() => {
  128. newChatButton?.click();
  129. }, 0);
  130. }}
  131. >
  132. <div class="flex self-center">
  133. <div class="self-center mr-1.5">
  134. <img
  135. src="{WEBUI_BASE_URL}/static/favicon.png"
  136. class=" size-6 -translate-x-1.5 rounded-full"
  137. alt="logo"
  138. />
  139. </div>
  140. <div class=" self-center font-medium text-sm">{$i18n.t('New Chat')}</div>
  141. </div>
  142. <div class="self-center">
  143. <svg
  144. xmlns="http://www.w3.org/2000/svg"
  145. viewBox="0 0 20 20"
  146. fill="currentColor"
  147. class="w-4 h-4"
  148. >
  149. <path
  150. 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"
  151. />
  152. <path
  153. 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"
  154. />
  155. </svg>
  156. </div>
  157. </a>
  158. </div>
  159. {#if $user?.role === 'admin'}
  160. <div class="px-2 flex justify-center mt-0.5">
  161. <a
  162. class="flex-grow flex space-x-3 rounded-xl px-3.5 py-2 hover:bg-gray-200 dark:hover:bg-gray-900 transition"
  163. href="/modelfiles"
  164. on:click={() => {
  165. selectedChatId = null;
  166. chatId.set('');
  167. }}
  168. >
  169. <div class="self-center">
  170. <svg
  171. xmlns="http://www.w3.org/2000/svg"
  172. fill="none"
  173. viewBox="0 0 24 24"
  174. stroke-width="2"
  175. stroke="currentColor"
  176. class="w-4 h-4"
  177. >
  178. <path
  179. stroke-linecap="round"
  180. stroke-linejoin="round"
  181. 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"
  182. />
  183. </svg>
  184. </div>
  185. <div class="flex self-center">
  186. <div class=" self-center font-medium text-sm">{$i18n.t('Modelfiles')}</div>
  187. </div>
  188. </a>
  189. </div>
  190. <div class="px-2 flex justify-center">
  191. <a
  192. class="flex-grow flex space-x-3 rounded-xl px-3.5 py-2 hover:bg-gray-200 dark:hover:bg-gray-900 transition"
  193. href="/prompts"
  194. on:click={() => {
  195. selectedChatId = null;
  196. chatId.set('');
  197. }}
  198. >
  199. <div class="self-center">
  200. <svg
  201. xmlns="http://www.w3.org/2000/svg"
  202. fill="none"
  203. viewBox="0 0 24 24"
  204. stroke-width="2"
  205. stroke="currentColor"
  206. class="w-4 h-4"
  207. >
  208. <path
  209. stroke-linecap="round"
  210. stroke-linejoin="round"
  211. d="m16.862 4.487 1.687-1.688a1.875 1.875 0 1 1 2.652 2.652L6.832 19.82a4.5 4.5 0 0 1-1.897 1.13l-2.685.8.8-2.685a4.5 4.5 0 0 1 1.13-1.897L16.863 4.487Zm0 0L19.5 7.125"
  212. />
  213. </svg>
  214. </div>
  215. <div class="flex self-center">
  216. <div class=" self-center font-medium text-sm">{$i18n.t('Prompts')}</div>
  217. </div>
  218. </a>
  219. </div>
  220. <div class="px-2 flex justify-center mb-1">
  221. <a
  222. class="flex-grow flex space-x-3 rounded-xl px-3.5 py-2 hover:bg-gray-200 dark:hover:bg-gray-900 transition"
  223. href="/documents"
  224. on:click={() => {
  225. selectedChatId = null;
  226. chatId.set('');
  227. }}
  228. >
  229. <div class="self-center">
  230. <svg
  231. xmlns="http://www.w3.org/2000/svg"
  232. fill="none"
  233. viewBox="0 0 24 24"
  234. stroke-width="2"
  235. stroke="currentColor"
  236. class="w-4 h-4"
  237. >
  238. <path
  239. stroke-linecap="round"
  240. stroke-linejoin="round"
  241. d="M15.75 17.25v3.375c0 .621-.504 1.125-1.125 1.125h-9.75a1.125 1.125 0 0 1-1.125-1.125V7.875c0-.621.504-1.125 1.125-1.125H6.75a9.06 9.06 0 0 1 1.5.124m7.5 10.376h3.375c.621 0 1.125-.504 1.125-1.125V11.25c0-4.46-3.243-8.161-7.5-8.876a9.06 9.06 0 0 0-1.5-.124H9.375c-.621 0-1.125.504-1.125 1.125v3.5m7.5 10.375H9.375a1.125 1.125 0 0 1-1.125-1.125v-9.25m12 6.625v-1.875a3.375 3.375 0 0 0-3.375-3.375h-1.5a1.125 1.125 0 0 1-1.125-1.125v-1.5a3.375 3.375 0 0 0-3.375-3.375H9.75"
  242. />
  243. </svg>
  244. </div>
  245. <div class="flex self-center">
  246. <div class=" self-center font-medium text-sm">{$i18n.t('Documents')}</div>
  247. </div>
  248. </a>
  249. </div>
  250. {/if}
  251. <div class="relative flex flex-col flex-1 overflow-y-auto">
  252. {#if !($settings.saveChatHistory ?? true)}
  253. <div class="absolute z-40 w-full h-full bg-gray-50/90 dark:bg-black/90 flex justify-center">
  254. <div class=" text-left px-5 py-2">
  255. <div class=" font-medium">{$i18n.t('Chat History is off for this browser.')}</div>
  256. <div class="text-xs mt-2">
  257. {$i18n.t(
  258. "When history is turned off, new chats on this browser won't appear in your history on any of your devices."
  259. )}
  260. <span class=" font-semibold"
  261. >{$i18n.t('This setting does not sync across browsers or devices.')}</span
  262. >
  263. </div>
  264. <div class="mt-3">
  265. <button
  266. class="flex justify-center items-center space-x-1.5 px-3 py-2.5 rounded-lg text-xs bg-gray-200 hover:bg-gray-300 transition text-gray-800 font-medium w-full"
  267. type="button"
  268. on:click={() => {
  269. saveSettings({
  270. saveChatHistory: true
  271. });
  272. }}
  273. >
  274. <svg
  275. xmlns="http://www.w3.org/2000/svg"
  276. viewBox="0 0 16 16"
  277. fill="currentColor"
  278. class="w-3 h-3"
  279. >
  280. <path
  281. fill-rule="evenodd"
  282. d="M8 1a.75.75 0 0 1 .75.75v6.5a.75.75 0 0 1-1.5 0v-6.5A.75.75 0 0 1 8 1ZM4.11 3.05a.75.75 0 0 1 0 1.06 5.5 5.5 0 1 0 7.78 0 .75.75 0 0 1 1.06-1.06 7 7 0 1 1-9.9 0 .75.75 0 0 1 1.06 0Z"
  283. clip-rule="evenodd"
  284. />
  285. </svg>
  286. <div>{$i18n.t('Enable Chat History')}</div>
  287. </button>
  288. </div>
  289. </div>
  290. </div>
  291. {/if}
  292. <div class="px-2 mt-1 mb-2 flex justify-center space-x-2">
  293. <div class="flex w-full" id="chat-search">
  294. <div class="self-center pl-3 py-2 rounded-l-xl bg-white dark:bg-gray-950">
  295. <svg
  296. xmlns="http://www.w3.org/2000/svg"
  297. viewBox="0 0 20 20"
  298. fill="currentColor"
  299. class="w-4 h-4"
  300. >
  301. <path
  302. fill-rule="evenodd"
  303. d="M9 3.5a5.5 5.5 0 100 11 5.5 5.5 0 000-11zM2 9a7 7 0 1112.452 4.391l3.328 3.329a.75.75 0 11-1.06 1.06l-3.329-3.328A7 7 0 012 9z"
  304. clip-rule="evenodd"
  305. />
  306. </svg>
  307. </div>
  308. <input
  309. class="w-full rounded-r-xl py-1.5 pl-2.5 pr-4 text-sm dark:text-gray-300 dark:bg-gray-950 outline-none"
  310. placeholder={$i18n.t('Search')}
  311. bind:value={search}
  312. on:focus={() => {
  313. enrichChatsWithContent($chats);
  314. }}
  315. />
  316. </div>
  317. </div>
  318. {#if $tags.length > 0}
  319. <div class="px-2.5 mt-0.5 mb-2 flex gap-1 flex-wrap">
  320. <button
  321. class="px-2.5 text-xs font-medium bg-gray-100 dark:bg-gray-900 dark:hover:bg-gray-800 transition rounded-full"
  322. on:click={async () => {
  323. await chats.set(await getChatList(localStorage.token));
  324. }}
  325. >
  326. all
  327. </button>
  328. {#each $tags as tag}
  329. <button
  330. class="px-2.5 text-xs font-medium bg-gray-100 dark:bg-gray-900 dark:hover:bg-gray-800 transition rounded-full"
  331. on:click={async () => {
  332. let chatIds = await getChatListByTagName(localStorage.token, tag.name);
  333. if (chatIds.length === 0) {
  334. await tags.set(await getAllChatTags(localStorage.token));
  335. chatIds = await getChatList(localStorage.token);
  336. }
  337. await chats.set(chatIds);
  338. }}
  339. >
  340. {tag.name}
  341. </button>
  342. {/each}
  343. </div>
  344. {/if}
  345. <div class="pl-2 my-2 flex-1 flex flex-col space-y-1 overflow-y-auto">
  346. {#each $chats.filter((chat) => {
  347. if (search === '') {
  348. return true;
  349. } else {
  350. let title = chat.title.toLowerCase();
  351. const query = search.toLowerCase();
  352. let contentMatches = false;
  353. // Access the messages within chat.chat.messages
  354. if (chat.chat && chat.chat.messages && Array.isArray(chat.chat.messages)) {
  355. contentMatches = chat.chat.messages.some((message) => {
  356. // Check if message.content exists and includes the search query
  357. return message.content && message.content.toLowerCase().includes(query);
  358. });
  359. }
  360. return title.includes(query) || contentMatches;
  361. }
  362. }) as chat, i}
  363. <div class=" w-full pr-2 relative group">
  364. {#if chatTitleEditId === chat.id}
  365. <div
  366. class=" w-full flex justify-between rounded-xl px-3 py-2 {chat.id === $chatId ||
  367. chat.id === chatTitleEditId ||
  368. chat.id === chatDeleteId
  369. ? 'bg-gray-300 dark:bg-gray-900'
  370. : chat.id === selectedChatId
  371. ? 'bg-gray-100 dark:bg-gray-950'
  372. : 'group-hover:bg-gray-100 dark:group-hover:bg-gray-950'} whitespace-nowrap text-ellipsis"
  373. >
  374. <input bind:value={chatTitle} class=" bg-transparent w-full outline-none mr-10" />
  375. </div>
  376. {:else}
  377. <a
  378. class=" w-full flex justify-between rounded-xl px-3 py-2 {chat.id === $chatId ||
  379. chat.id === chatTitleEditId ||
  380. chat.id === chatDeleteId
  381. ? 'bg-gray-300 dark:bg-gray-900'
  382. : chat.id === selectedChatId
  383. ? 'bg-gray-100 dark:bg-gray-950'
  384. : ' group-hover:bg-gray-100 dark:group-hover:bg-gray-950'} whitespace-nowrap text-ellipsis"
  385. href="/c/{chat.id}"
  386. on:click={() => {
  387. selectedChatId = chat.id;
  388. if (window.innerWidth < 1024) {
  389. show = false;
  390. }
  391. }}
  392. draggable="false"
  393. >
  394. <div class=" flex self-center flex-1 w-full">
  395. <div class=" text-left self-center overflow-hidden w-full h-[20px]">
  396. {chat.title}
  397. </div>
  398. </div>
  399. </a>
  400. {/if}
  401. <div
  402. class="
  403. {chat.id === $chatId || chat.id === chatTitleEditId || chat.id === chatDeleteId
  404. ? 'from-gray-300 dark:from-gray-900'
  405. : chat.id === selectedChatId
  406. ? 'from-gray-100 dark:from-gray-950'
  407. : 'invisible group-hover:visible from-gray-100 dark:from-gray-950'}
  408. absolute right-[10px] top-[10px] pr-2 pl-5 bg-gradient-to-l from-80%
  409. to-transparent"
  410. >
  411. {#if chatTitleEditId === chat.id}
  412. <div class="flex self-center space-x-1.5 z-10">
  413. <button
  414. class=" self-center dark:hover:text-white transition"
  415. on:click={() => {
  416. editChatTitle(chat.id, chatTitle);
  417. chatTitleEditId = null;
  418. chatTitle = '';
  419. }}
  420. >
  421. <svg
  422. xmlns="http://www.w3.org/2000/svg"
  423. viewBox="0 0 20 20"
  424. fill="currentColor"
  425. class="w-4 h-4"
  426. >
  427. <path
  428. fill-rule="evenodd"
  429. d="M16.704 4.153a.75.75 0 01.143 1.052l-8 10.5a.75.75 0 01-1.127.075l-4.5-4.5a.75.75 0 011.06-1.06l3.894 3.893 7.48-9.817a.75.75 0 011.05-.143z"
  430. clip-rule="evenodd"
  431. />
  432. </svg>
  433. </button>
  434. <button
  435. class=" self-center dark:hover:text-white transition"
  436. on:click={() => {
  437. chatTitleEditId = null;
  438. chatTitle = '';
  439. }}
  440. >
  441. <svg
  442. xmlns="http://www.w3.org/2000/svg"
  443. viewBox="0 0 20 20"
  444. fill="currentColor"
  445. class="w-4 h-4"
  446. >
  447. <path
  448. d="M6.28 5.22a.75.75 0 00-1.06 1.06L8.94 10l-3.72 3.72a.75.75 0 101.06 1.06L10 11.06l3.72 3.72a.75.75 0 101.06-1.06L11.06 10l3.72-3.72a.75.75 0 00-1.06-1.06L10 8.94 6.28 5.22z"
  449. />
  450. </svg>
  451. </button>
  452. </div>
  453. {:else if chatDeleteId === chat.id}
  454. <div class="flex self-center space-x-1.5 z-10">
  455. <button
  456. class=" self-center dark:hover:text-white transition"
  457. on:click={() => {
  458. deleteChat(chat.id);
  459. }}
  460. >
  461. <svg
  462. xmlns="http://www.w3.org/2000/svg"
  463. viewBox="0 0 20 20"
  464. fill="currentColor"
  465. class="w-4 h-4"
  466. >
  467. <path
  468. fill-rule="evenodd"
  469. d="M16.704 4.153a.75.75 0 01.143 1.052l-8 10.5a.75.75 0 01-1.127.075l-4.5-4.5a.75.75 0 011.06-1.06l3.894 3.893 7.48-9.817a.75.75 0 011.05-.143z"
  470. clip-rule="evenodd"
  471. />
  472. </svg>
  473. </button>
  474. <button
  475. class=" self-center dark:hover:text-white transition"
  476. on:click={() => {
  477. chatDeleteId = null;
  478. }}
  479. >
  480. <svg
  481. xmlns="http://www.w3.org/2000/svg"
  482. viewBox="0 0 20 20"
  483. fill="currentColor"
  484. class="w-4 h-4"
  485. >
  486. <path
  487. d="M6.28 5.22a.75.75 0 00-1.06 1.06L8.94 10l-3.72 3.72a.75.75 0 101.06 1.06L10 11.06l3.72 3.72a.75.75 0 101.06-1.06L11.06 10l3.72-3.72a.75.75 0 00-1.06-1.06L10 8.94 6.28 5.22z"
  488. />
  489. </svg>
  490. </button>
  491. </div>
  492. {:else}
  493. <div class="flex self-center space-x-1.5 z-10">
  494. <ChatMenu
  495. chatId={chat.id}
  496. renameHandler={() => {
  497. chatTitle = chat.title;
  498. chatTitleEditId = chat.id;
  499. }}
  500. deleteHandler={() => {
  501. chatDeleteId = chat.id;
  502. }}
  503. onClose={() => {
  504. selectedChatId = null;
  505. }}
  506. >
  507. <button
  508. aria-label="Chat Menu"
  509. class=" self-center dark:hover:text-white transition"
  510. on:click={() => {
  511. selectedChatId = chat.id;
  512. }}
  513. >
  514. <svg
  515. xmlns="http://www.w3.org/2000/svg"
  516. viewBox="0 0 16 16"
  517. fill="currentColor"
  518. class="w-4 h-4"
  519. >
  520. <path
  521. d="M2 8a1.5 1.5 0 1 1 3 0 1.5 1.5 0 0 1-3 0ZM6.5 8a1.5 1.5 0 1 1 3 0 1.5 1.5 0 0 1-3 0ZM12.5 6.5a1.5 1.5 0 1 0 0 3 1.5 1.5 0 0 0 0-3Z"
  522. />
  523. </svg>
  524. </button>
  525. </ChatMenu>
  526. </div>
  527. {/if}
  528. </div>
  529. </div>
  530. {/each}
  531. </div>
  532. </div>
  533. <div class="px-2.5">
  534. <!-- <hr class=" border-gray-900 mb-1 w-full" /> -->
  535. <div class="flex flex-col">
  536. {#if $user !== undefined}
  537. <button
  538. class=" flex rounded-xl py-3 px-3.5 w-full hover:bg-gray-200 dark:hover:bg-gray-900 transition"
  539. on:click={() => {
  540. showDropdown = !showDropdown;
  541. }}
  542. >
  543. <div class=" self-center mr-3">
  544. <img
  545. src={$user.profile_image_url}
  546. class=" max-w-[30px] object-cover rounded-full"
  547. alt="User profile"
  548. />
  549. </div>
  550. <div class=" self-center font-semibold">{$user.name}</div>
  551. </button>
  552. {#if showDropdown}
  553. <div
  554. id="dropdownDots"
  555. class="absolute z-40 bottom-[70px] 4.5rem rounded-xl shadow w-[240px] bg-white dark:bg-gray-900"
  556. transition:fade|slide={{ duration: 100 }}
  557. >
  558. <div class="py-2 w-full">
  559. {#if $user.role === 'admin'}
  560. <button
  561. class="flex py-2.5 px-3.5 w-full hover:bg-gray-100 dark:hover:bg-gray-800 transition"
  562. on:click={() => {
  563. goto('/admin');
  564. showDropdown = false;
  565. }}
  566. >
  567. <div class=" self-center mr-3">
  568. <svg
  569. xmlns="http://www.w3.org/2000/svg"
  570. fill="none"
  571. viewBox="0 0 24 24"
  572. stroke-width="1.5"
  573. stroke="currentColor"
  574. class="w-5 h-5"
  575. >
  576. <path
  577. stroke-linecap="round"
  578. stroke-linejoin="round"
  579. d="M17.982 18.725A7.488 7.488 0 0012 15.75a7.488 7.488 0 00-5.982 2.975m11.963 0a9 9 0 10-11.963 0m11.963 0A8.966 8.966 0 0112 21a8.966 8.966 0 01-5.982-2.275M15 9.75a3 3 0 11-6 0 3 3 0 016 0z"
  580. />
  581. </svg>
  582. </div>
  583. <div class=" self-center font-medium">{$i18n.t('Admin Panel')}</div>
  584. </button>
  585. <button
  586. class="flex py-2.5 px-3.5 w-full hover:bg-gray-100 dark:hover:bg-gray-800 transition"
  587. on:click={() => {
  588. goto('/playground');
  589. showDropdown = false;
  590. }}
  591. >
  592. <div class=" self-center mr-3">
  593. <svg
  594. xmlns="http://www.w3.org/2000/svg"
  595. fill="none"
  596. viewBox="0 0 24 24"
  597. stroke-width="1.5"
  598. stroke="currentColor"
  599. class="w-5 h-5"
  600. >
  601. <path
  602. stroke-linecap="round"
  603. stroke-linejoin="round"
  604. d="m6.75 7.5 3 2.25-3 2.25m4.5 0h3m-9 8.25h13.5A2.25 2.25 0 0 0 21 18V6a2.25 2.25 0 0 0-2.25-2.25H5.25A2.25 2.25 0 0 0 3 6v12a2.25 2.25 0 0 0 2.25 2.25Z"
  605. />
  606. </svg>
  607. </div>
  608. <div class=" self-center font-medium">{$i18n.t('Playground')}</div>
  609. </button>
  610. {/if}
  611. <button
  612. class="flex py-2.5 px-3.5 w-full hover:bg-gray-100 dark:hover:bg-gray-800 transition"
  613. on:click={async () => {
  614. await showSettings.set(true);
  615. showDropdown = false;
  616. }}
  617. >
  618. <div class=" self-center mr-3">
  619. <svg
  620. xmlns="http://www.w3.org/2000/svg"
  621. fill="none"
  622. viewBox="0 0 24 24"
  623. stroke-width="1.5"
  624. stroke="currentColor"
  625. class="w-5 h-5"
  626. >
  627. <path
  628. stroke-linecap="round"
  629. stroke-linejoin="round"
  630. d="M10.343 3.94c.09-.542.56-.94 1.11-.94h1.093c.55 0 1.02.398 1.11.94l.149.894c.07.424.384.764.78.93.398.164.855.142 1.205-.108l.737-.527a1.125 1.125 0 011.45.12l.773.774c.39.389.44 1.002.12 1.45l-.527.737c-.25.35-.272.806-.107 1.204.165.397.505.71.93.78l.893.15c.543.09.94.56.94 1.109v1.094c0 .55-.397 1.02-.94 1.11l-.893.149c-.425.07-.765.383-.93.78-.165.398-.143.854.107 1.204l.527.738c.32.447.269 1.06-.12 1.45l-.774.773a1.125 1.125 0 01-1.449.12l-.738-.527c-.35-.25-.806-.272-1.203-.107-.397.165-.71.505-.781.929l-.149.894c-.09.542-.56.94-1.11.94h-1.094c-.55 0-1.019-.398-1.11-.94l-.148-.894c-.071-.424-.384-.764-.781-.93-.398-.164-.854-.142-1.204.108l-.738.527c-.447.32-1.06.269-1.45-.12l-.773-.774a1.125 1.125 0 01-.12-1.45l.527-.737c.25-.35.273-.806.108-1.204-.165-.397-.505-.71-.93-.78l-.894-.15c-.542-.09-.94-.56-.94-1.109v-1.094c0-.55.398-1.02.94-1.11l.894-.149c.424-.07.765-.383.93-.78.165-.398.143-.854-.107-1.204l-.527-.738a1.125 1.125 0 01.12-1.45l.773-.773a1.125 1.125 0 011.45-.12l.737.527c.35.25.807.272 1.204.107.397-.165.71-.505.78-.929l.15-.894z"
  631. />
  632. <path
  633. stroke-linecap="round"
  634. stroke-linejoin="round"
  635. d="M15 12a3 3 0 11-6 0 3 3 0 016 0z"
  636. />
  637. </svg>
  638. </div>
  639. <div class=" self-center font-medium">{$i18n.t('Settings')}</div>
  640. </button>
  641. </div>
  642. <hr class=" dark:border-gray-700 m-0 p-0" />
  643. <div class="py-2 w-full">
  644. <button
  645. class="flex py-2.5 px-3.5 w-full hover:bg-gray-100 dark:hover:bg-gray-800 transition"
  646. on:click={() => {
  647. localStorage.removeItem('token');
  648. location.href = '/auth';
  649. showDropdown = false;
  650. }}
  651. >
  652. <div class=" self-center mr-3">
  653. <svg
  654. xmlns="http://www.w3.org/2000/svg"
  655. viewBox="0 0 20 20"
  656. fill="currentColor"
  657. class="w-5 h-5"
  658. >
  659. <path
  660. fill-rule="evenodd"
  661. d="M3 4.25A2.25 2.25 0 015.25 2h5.5A2.25 2.25 0 0113 4.25v2a.75.75 0 01-1.5 0v-2a.75.75 0 00-.75-.75h-5.5a.75.75 0 00-.75.75v11.5c0 .414.336.75.75.75h5.5a.75.75 0 00.75-.75v-2a.75.75 0 011.5 0v2A2.25 2.25 0 0110.75 18h-5.5A2.25 2.25 0 013 15.75V4.25z"
  662. clip-rule="evenodd"
  663. />
  664. <path
  665. fill-rule="evenodd"
  666. d="M6 10a.75.75 0 01.75-.75h9.546l-1.048-.943a.75.75 0 111.004-1.114l2.5 2.25a.75.75 0 010 1.114l-2.5 2.25a.75.75 0 11-1.004-1.114l1.048-.943H6.75A.75.75 0 016 10z"
  667. clip-rule="evenodd"
  668. />
  669. </svg>
  670. </div>
  671. <div class=" self-center font-medium">{$i18n.t('Sign Out')}</div>
  672. </button>
  673. </div>
  674. </div>
  675. {/if}
  676. {/if}
  677. </div>
  678. </div>
  679. </div>
  680. <div
  681. id="sidebar-handle"
  682. class="fixed left-0 top-[50dvh] -translate-y-1/2 transition-transform translate-x-[255px] md:translate-x-[260px] rotate-0"
  683. >
  684. <Tooltip
  685. placement="right"
  686. content={`${show ? $i18n.t('Close') : $i18n.t('Open')} ${$i18n.t('sidebar')}`}
  687. touch={false}
  688. >
  689. <button
  690. id="sidebar-toggle-button"
  691. class=" group"
  692. on:click={() => {
  693. show = !show;
  694. }}
  695. ><span class="" data-state="closed"
  696. ><div
  697. class="flex h-[72px] w-8 items-center justify-center opacity-50 group-hover:opacity-100 transition"
  698. >
  699. <div class="flex h-6 w-6 flex-col items-center">
  700. <div
  701. class="h-3 w-1 rounded-full bg-[#0f0f0f] dark:bg-white rotate-0 translate-y-[0.15rem] {show
  702. ? 'group-hover:rotate-[15deg]'
  703. : 'group-hover:rotate-[-15deg]'}"
  704. />
  705. <div
  706. class="h-3 w-1 rounded-full bg-[#0f0f0f] dark:bg-white rotate-0 translate-y-[-0.15rem] {show
  707. ? 'group-hover:rotate-[-15deg]'
  708. : 'group-hover:rotate-[15deg]'}"
  709. />
  710. </div>
  711. </div>
  712. </span>
  713. </button>
  714. </Tooltip>
  715. </div>
  716. </div>