Sidebar.svelte 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743
  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. });
  39. // Helper function to fetch and add chat content to each chat
  40. const enrichChatsWithContent = async (chatList) => {
  41. const enrichedChats = await Promise.all(
  42. chatList.map(async (chat) => {
  43. const chatDetails = await getChatById(localStorage.token, chat.id).catch((error) => null); // Handle error or non-existent chat gracefully
  44. if (chatDetails) {
  45. chat.chat = chatDetails.chat; // Assuming chatDetails.chat contains the chat content
  46. }
  47. return chat;
  48. })
  49. );
  50. await chats.set(enrichedChats);
  51. };
  52. const loadChat = async (id) => {
  53. goto(`/c/${id}`);
  54. };
  55. const editChatTitle = async (id, _title) => {
  56. if (_title === '') {
  57. toast.error('Title cannot be an empty string.');
  58. } else {
  59. title = _title;
  60. await updateChatById(localStorage.token, id, {
  61. title: _title
  62. });
  63. await chats.set(await getChatList(localStorage.token));
  64. }
  65. };
  66. const deleteChat = async (id) => {
  67. const res = await deleteChatById(localStorage.token, id).catch((error) => {
  68. toast.error(error);
  69. chatDeleteId = null;
  70. return null;
  71. });
  72. if (res) {
  73. if ($chatId === id) {
  74. goto('/');
  75. }
  76. await chats.set(await getChatList(localStorage.token));
  77. }
  78. };
  79. const saveSettings = async (updated) => {
  80. await settings.set({ ...$settings, ...updated });
  81. localStorage.setItem('settings', JSON.stringify($settings));
  82. location.href = '/';
  83. };
  84. </script>
  85. <div
  86. bind:this={navElement}
  87. class="h-screen max-h-[100dvh] min-h-screen {show
  88. ? 'lg:relative w-[260px]'
  89. : '-translate-x-[260px] w-[0px]'} bg-gray-50 text-gray-900 dark:bg-gray-950 dark:text-gray-200 text-sm transition z-40 fixed top-0 left-0
  90. "
  91. >
  92. <div
  93. class="py-2.5 my-auto flex flex-col justify-between h-screen max-h-[100dvh] w-[260px] {show
  94. ? ''
  95. : 'invisible'}"
  96. >
  97. <div class="px-2 flex justify-center space-x-2">
  98. <a
  99. id="sidebar-new-chat-button"
  100. class="flex-grow flex justify-between rounded-xl px-4 py-2 hover:bg-gray-200 dark:hover:bg-gray-900 transition"
  101. href="/"
  102. on:click={async () => {
  103. selectedChatId = null;
  104. await goto('/');
  105. const newChatButton = document.getElementById('new-chat-button');
  106. setTimeout(() => {
  107. newChatButton?.click();
  108. }, 0);
  109. }}
  110. >
  111. <div class="flex self-center">
  112. <div class="self-center mr-1.5">
  113. <img
  114. src="{WEBUI_BASE_URL}/static/favicon.png"
  115. class=" size-6 -translate-x-1.5 rounded-full"
  116. alt="logo"
  117. />
  118. </div>
  119. <div class=" self-center font-medium text-sm">{$i18n.t('New Chat')}</div>
  120. </div>
  121. <div class="self-center">
  122. <svg
  123. xmlns="http://www.w3.org/2000/svg"
  124. viewBox="0 0 20 20"
  125. fill="currentColor"
  126. class="w-4 h-4"
  127. >
  128. <path
  129. 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"
  130. />
  131. <path
  132. 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"
  133. />
  134. </svg>
  135. </div>
  136. </a>
  137. </div>
  138. {#if $user?.role === 'admin'}
  139. <div class="px-2 flex justify-center mt-0.5">
  140. <a
  141. class="flex-grow flex space-x-3 rounded-xl px-3.5 py-2 hover:bg-gray-200 dark:hover:bg-gray-900 transition"
  142. href="/modelfiles"
  143. on:click={() => {
  144. selectedChatId = null;
  145. chatId.set('');
  146. }}
  147. >
  148. <div class="self-center">
  149. <svg
  150. xmlns="http://www.w3.org/2000/svg"
  151. fill="none"
  152. viewBox="0 0 24 24"
  153. stroke-width="2"
  154. stroke="currentColor"
  155. class="w-4 h-4"
  156. >
  157. <path
  158. stroke-linecap="round"
  159. stroke-linejoin="round"
  160. 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"
  161. />
  162. </svg>
  163. </div>
  164. <div class="flex self-center">
  165. <div class=" self-center font-medium text-sm">{$i18n.t('Modelfiles')}</div>
  166. </div>
  167. </a>
  168. </div>
  169. <div class="px-2 flex justify-center">
  170. <a
  171. class="flex-grow flex space-x-3 rounded-xl px-3.5 py-2 hover:bg-gray-200 dark:hover:bg-gray-900 transition"
  172. href="/prompts"
  173. on:click={() => {
  174. selectedChatId = null;
  175. chatId.set('');
  176. }}
  177. >
  178. <div class="self-center">
  179. <svg
  180. xmlns="http://www.w3.org/2000/svg"
  181. fill="none"
  182. viewBox="0 0 24 24"
  183. stroke-width="2"
  184. stroke="currentColor"
  185. class="w-4 h-4"
  186. >
  187. <path
  188. stroke-linecap="round"
  189. stroke-linejoin="round"
  190. 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"
  191. />
  192. </svg>
  193. </div>
  194. <div class="flex self-center">
  195. <div class=" self-center font-medium text-sm">{$i18n.t('Prompts')}</div>
  196. </div>
  197. </a>
  198. </div>
  199. <div class="px-2 flex justify-center mb-1">
  200. <a
  201. class="flex-grow flex space-x-3 rounded-xl px-3.5 py-2 hover:bg-gray-200 dark:hover:bg-gray-900 transition"
  202. href="/documents"
  203. on:click={() => {
  204. selectedChatId = null;
  205. chatId.set('');
  206. }}
  207. >
  208. <div class="self-center">
  209. <svg
  210. xmlns="http://www.w3.org/2000/svg"
  211. fill="none"
  212. viewBox="0 0 24 24"
  213. stroke-width="2"
  214. stroke="currentColor"
  215. class="w-4 h-4"
  216. >
  217. <path
  218. stroke-linecap="round"
  219. stroke-linejoin="round"
  220. 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"
  221. />
  222. </svg>
  223. </div>
  224. <div class="flex self-center">
  225. <div class=" self-center font-medium text-sm">{$i18n.t('Documents')}</div>
  226. </div>
  227. </a>
  228. </div>
  229. {/if}
  230. <div class="relative flex flex-col flex-1 overflow-y-auto">
  231. {#if !($settings.saveChatHistory ?? true)}
  232. <div class="absolute z-40 w-full h-full bg-gray-50/90 dark:bg-black/90 flex justify-center">
  233. <div class=" text-left px-5 py-2">
  234. <div class=" font-medium">{$i18n.t('Chat History is off for this browser.')}</div>
  235. <div class="text-xs mt-2">
  236. {$i18n.t(
  237. "When history is turned off, new chats on this browser won't appear in your history on any of your devices."
  238. )}
  239. <span class=" font-semibold"
  240. >{$i18n.t('This setting does not sync across browsers or devices.')}</span
  241. >
  242. </div>
  243. <div class="mt-3">
  244. <button
  245. 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"
  246. type="button"
  247. on:click={() => {
  248. saveSettings({
  249. saveChatHistory: true
  250. });
  251. }}
  252. >
  253. <svg
  254. xmlns="http://www.w3.org/2000/svg"
  255. viewBox="0 0 16 16"
  256. fill="currentColor"
  257. class="w-3 h-3"
  258. >
  259. <path
  260. fill-rule="evenodd"
  261. 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"
  262. clip-rule="evenodd"
  263. />
  264. </svg>
  265. <div>{$i18n.t('Enable Chat History')}</div>
  266. </button>
  267. </div>
  268. </div>
  269. </div>
  270. {/if}
  271. <div class="px-2 mt-1 mb-2 flex justify-center space-x-2">
  272. <div class="flex w-full" id="chat-search">
  273. <div class="self-center pl-3 py-2 rounded-l-xl bg-white dark:bg-gray-950">
  274. <svg
  275. xmlns="http://www.w3.org/2000/svg"
  276. viewBox="0 0 20 20"
  277. fill="currentColor"
  278. class="w-4 h-4"
  279. >
  280. <path
  281. fill-rule="evenodd"
  282. 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"
  283. clip-rule="evenodd"
  284. />
  285. </svg>
  286. </div>
  287. <input
  288. 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"
  289. placeholder={$i18n.t('Search')}
  290. bind:value={search}
  291. on:focus={() => {
  292. enrichChatsWithContent($chats);
  293. }}
  294. />
  295. </div>
  296. </div>
  297. {#if $tags.length > 0}
  298. <div class="px-2.5 mt-0.5 mb-2 flex gap-1 flex-wrap">
  299. <button
  300. class="px-2.5 text-xs font-medium bg-gray-100 dark:bg-gray-900 dark:hover:bg-gray-800 transition rounded-full"
  301. on:click={async () => {
  302. await chats.set(await getChatList(localStorage.token));
  303. }}
  304. >
  305. all
  306. </button>
  307. {#each $tags as tag}
  308. <button
  309. class="px-2.5 text-xs font-medium bg-gray-100 dark:bg-gray-900 dark:hover:bg-gray-800 transition rounded-full"
  310. on:click={async () => {
  311. let chatIds = await getChatListByTagName(localStorage.token, tag.name);
  312. if (chatIds.length === 0) {
  313. await tags.set(await getAllChatTags(localStorage.token));
  314. chatIds = await getChatList(localStorage.token);
  315. }
  316. await chats.set(chatIds);
  317. }}
  318. >
  319. {tag.name}
  320. </button>
  321. {/each}
  322. </div>
  323. {/if}
  324. <div class="pl-2 my-2 flex-1 flex flex-col space-y-1 overflow-y-auto">
  325. {#each $chats.filter((chat) => {
  326. if (search === '') {
  327. return true;
  328. } else {
  329. let title = chat.title.toLowerCase();
  330. const query = search.toLowerCase();
  331. let contentMatches = false;
  332. // Access the messages within chat.chat.messages
  333. if (chat.chat && chat.chat.messages && Array.isArray(chat.chat.messages)) {
  334. contentMatches = chat.chat.messages.some((message) => {
  335. // Check if message.content exists and includes the search query
  336. return message.content && message.content.toLowerCase().includes(query);
  337. });
  338. }
  339. return title.includes(query) || contentMatches;
  340. }
  341. }) as chat, i}
  342. <div class=" w-full pr-2 relative group">
  343. {#if chatTitleEditId === chat.id}
  344. <div
  345. class=" w-full flex justify-between rounded-xl px-3 py-2 {chat.id === $chatId ||
  346. chat.id === chatTitleEditId ||
  347. chat.id === chatDeleteId
  348. ? 'bg-gray-300 dark:bg-gray-900'
  349. : chat.id === selectedChatId
  350. ? 'bg-gray-100 dark:bg-gray-950'
  351. : 'group-hover:bg-gray-100 dark:group-hover:bg-gray-950'} whitespace-nowrap text-ellipsis"
  352. >
  353. <input bind:value={chatTitle} class=" bg-transparent w-full outline-none mr-10" />
  354. </div>
  355. {:else}
  356. <a
  357. class=" w-full flex justify-between rounded-xl px-3 py-2 {chat.id === $chatId ||
  358. chat.id === chatTitleEditId ||
  359. chat.id === chatDeleteId
  360. ? 'bg-gray-300 dark:bg-gray-900'
  361. : chat.id === selectedChatId
  362. ? 'bg-gray-100 dark:bg-gray-950'
  363. : ' group-hover:bg-gray-100 dark:group-hover:bg-gray-950'} whitespace-nowrap text-ellipsis"
  364. href="/c/{chat.id}"
  365. on:click={() => {
  366. selectedChatId = chat.id;
  367. if (window.innerWidth < 1024) {
  368. show = false;
  369. }
  370. }}
  371. draggable="false"
  372. >
  373. <div class=" flex self-center flex-1 w-full">
  374. <div class=" text-left self-center overflow-hidden w-full h-[20px]">
  375. {chat.title}
  376. </div>
  377. </div>
  378. </a>
  379. {/if}
  380. <div
  381. class="
  382. {chat.id === $chatId || chat.id === chatTitleEditId || chat.id === chatDeleteId
  383. ? 'from-gray-300 dark:from-gray-900'
  384. : chat.id === selectedChatId
  385. ? 'from-gray-100 dark:from-gray-950'
  386. : 'invisible group-hover:visible from-gray-100 dark:from-gray-950'}
  387. absolute right-[10px] top-[10px] pr-2 pl-5 bg-gradient-to-l from-80%
  388. to-transparent"
  389. >
  390. {#if chatTitleEditId === chat.id}
  391. <div class="flex self-center space-x-1.5 z-10">
  392. <button
  393. class=" self-center dark:hover:text-white transition"
  394. on:click={() => {
  395. editChatTitle(chat.id, chatTitle);
  396. chatTitleEditId = null;
  397. chatTitle = '';
  398. }}
  399. >
  400. <svg
  401. xmlns="http://www.w3.org/2000/svg"
  402. viewBox="0 0 20 20"
  403. fill="currentColor"
  404. class="w-4 h-4"
  405. >
  406. <path
  407. fill-rule="evenodd"
  408. 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"
  409. clip-rule="evenodd"
  410. />
  411. </svg>
  412. </button>
  413. <button
  414. class=" self-center dark:hover:text-white transition"
  415. on:click={() => {
  416. chatTitleEditId = null;
  417. chatTitle = '';
  418. }}
  419. >
  420. <svg
  421. xmlns="http://www.w3.org/2000/svg"
  422. viewBox="0 0 20 20"
  423. fill="currentColor"
  424. class="w-4 h-4"
  425. >
  426. <path
  427. 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"
  428. />
  429. </svg>
  430. </button>
  431. </div>
  432. {:else if chatDeleteId === chat.id}
  433. <div class="flex self-center space-x-1.5 z-10">
  434. <button
  435. class=" self-center dark:hover:text-white transition"
  436. on:click={() => {
  437. deleteChat(chat.id);
  438. }}
  439. >
  440. <svg
  441. xmlns="http://www.w3.org/2000/svg"
  442. viewBox="0 0 20 20"
  443. fill="currentColor"
  444. class="w-4 h-4"
  445. >
  446. <path
  447. fill-rule="evenodd"
  448. 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"
  449. clip-rule="evenodd"
  450. />
  451. </svg>
  452. </button>
  453. <button
  454. class=" self-center dark:hover:text-white transition"
  455. on:click={() => {
  456. chatDeleteId = null;
  457. }}
  458. >
  459. <svg
  460. xmlns="http://www.w3.org/2000/svg"
  461. viewBox="0 0 20 20"
  462. fill="currentColor"
  463. class="w-4 h-4"
  464. >
  465. <path
  466. 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"
  467. />
  468. </svg>
  469. </button>
  470. </div>
  471. {:else}
  472. <div class="flex self-center space-x-1.5 z-10">
  473. <ChatMenu
  474. renameHandler={() => {
  475. chatTitle = chat.title;
  476. chatTitleEditId = chat.id;
  477. }}
  478. deleteHandler={() => {
  479. chatDeleteId = chat.id;
  480. }}
  481. onClose={() => {
  482. selectedChatId = null;
  483. }}
  484. >
  485. <button
  486. aria-label="Chat Menu"
  487. class=" self-center dark:hover:text-white transition"
  488. on:click={() => {
  489. selectedChatId = chat.id;
  490. }}
  491. >
  492. <svg
  493. xmlns="http://www.w3.org/2000/svg"
  494. viewBox="0 0 16 16"
  495. fill="currentColor"
  496. class="w-4 h-4"
  497. >
  498. <path
  499. 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"
  500. />
  501. </svg>
  502. </button>
  503. </ChatMenu>
  504. </div>
  505. {/if}
  506. </div>
  507. </div>
  508. {/each}
  509. </div>
  510. </div>
  511. <div class="px-2.5">
  512. <!-- <hr class=" border-gray-900 mb-1 w-full" /> -->
  513. <div class="flex flex-col">
  514. {#if $user !== undefined}
  515. <button
  516. class=" flex rounded-xl py-3 px-3.5 w-full hover:bg-gray-200 dark:hover:bg-gray-900 transition"
  517. on:click={() => {
  518. showDropdown = !showDropdown;
  519. }}
  520. >
  521. <div class=" self-center mr-3">
  522. <img
  523. src={$user.profile_image_url}
  524. class=" max-w-[30px] object-cover rounded-full"
  525. alt="User profile"
  526. />
  527. </div>
  528. <div class=" self-center font-semibold">{$user.name}</div>
  529. </button>
  530. {#if showDropdown}
  531. <div
  532. id="dropdownDots"
  533. class="absolute z-40 bottom-[70px] 4.5rem rounded-xl shadow w-[240px] bg-white dark:bg-gray-900"
  534. transition:fade|slide={{ duration: 100 }}
  535. >
  536. <div class="py-2 w-full">
  537. {#if $user.role === 'admin'}
  538. <button
  539. class="flex py-2.5 px-3.5 w-full dark:hover:bg-gray-800 transition"
  540. on:click={() => {
  541. goto('/admin');
  542. showDropdown = false;
  543. }}
  544. >
  545. <div class=" self-center mr-3">
  546. <svg
  547. xmlns="http://www.w3.org/2000/svg"
  548. fill="none"
  549. viewBox="0 0 24 24"
  550. stroke-width="1.5"
  551. stroke="currentColor"
  552. class="w-5 h-5"
  553. >
  554. <path
  555. stroke-linecap="round"
  556. stroke-linejoin="round"
  557. 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"
  558. />
  559. </svg>
  560. </div>
  561. <div class=" self-center font-medium">{$i18n.t('Admin Panel')}</div>
  562. </button>
  563. <button
  564. class="flex py-2.5 px-3.5 w-full dark:hover:bg-gray-800 transition"
  565. on:click={() => {
  566. goto('/playground');
  567. showDropdown = false;
  568. }}
  569. >
  570. <div class=" self-center mr-3">
  571. <svg
  572. xmlns="http://www.w3.org/2000/svg"
  573. fill="none"
  574. viewBox="0 0 24 24"
  575. stroke-width="1.5"
  576. stroke="currentColor"
  577. class="w-5 h-5"
  578. >
  579. <path
  580. stroke-linecap="round"
  581. stroke-linejoin="round"
  582. 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"
  583. />
  584. </svg>
  585. </div>
  586. <div class=" self-center font-medium">{$i18n.t('Playground')}</div>
  587. </button>
  588. {/if}
  589. <button
  590. class="flex py-2.5 px-3.5 w-full dark:hover:bg-gray-800 transition"
  591. on:click={async () => {
  592. await showSettings.set(true);
  593. showDropdown = false;
  594. }}
  595. >
  596. <div class=" self-center mr-3">
  597. <svg
  598. xmlns="http://www.w3.org/2000/svg"
  599. fill="none"
  600. viewBox="0 0 24 24"
  601. stroke-width="1.5"
  602. stroke="currentColor"
  603. class="w-5 h-5"
  604. >
  605. <path
  606. stroke-linecap="round"
  607. stroke-linejoin="round"
  608. 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"
  609. />
  610. <path
  611. stroke-linecap="round"
  612. stroke-linejoin="round"
  613. d="M15 12a3 3 0 11-6 0 3 3 0 016 0z"
  614. />
  615. </svg>
  616. </div>
  617. <div class=" self-center font-medium">{$i18n.t('Settings')}</div>
  618. </button>
  619. </div>
  620. <hr class=" dark:border-gray-700 m-0 p-0" />
  621. <div class="py-2 w-full">
  622. <button
  623. class="flex py-2.5 px-3.5 w-full dark:hover:bg-gray-800 transition"
  624. on:click={() => {
  625. localStorage.removeItem('token');
  626. location.href = '/auth';
  627. showDropdown = false;
  628. }}
  629. >
  630. <div class=" self-center mr-3">
  631. <svg
  632. xmlns="http://www.w3.org/2000/svg"
  633. viewBox="0 0 20 20"
  634. fill="currentColor"
  635. class="w-5 h-5"
  636. >
  637. <path
  638. fill-rule="evenodd"
  639. 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"
  640. clip-rule="evenodd"
  641. />
  642. <path
  643. fill-rule="evenodd"
  644. 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"
  645. clip-rule="evenodd"
  646. />
  647. </svg>
  648. </div>
  649. <div class=" self-center font-medium">{$i18n.t('Sign Out')}</div>
  650. </button>
  651. </div>
  652. </div>
  653. {/if}
  654. {/if}
  655. </div>
  656. </div>
  657. </div>
  658. <div
  659. class="fixed left-0 top-[50dvh] z-40 -translate-y-1/2 transition-transform translate-x-[255px] md:translate-x-[260px] rotate-0"
  660. >
  661. <Tooltip
  662. placement="right"
  663. content={`${show ? $i18n.t('Close') : $i18n.t('Open')} ${$i18n.t('sidebar')}`}
  664. touch={false}
  665. >
  666. <button
  667. id="sidebar-toggle-button"
  668. class=" group"
  669. on:click={() => {
  670. show = !show;
  671. }}
  672. ><span class="" data-state="closed"
  673. ><div
  674. class="flex h-[72px] w-8 items-center justify-center opacity-50 group-hover:opacity-100 transition"
  675. >
  676. <div class="flex h-6 w-6 flex-col items-center">
  677. <div
  678. class="h-3 w-1 rounded-full bg-[#0f0f0f] dark:bg-white rotate-0 translate-y-[0.15rem] {show
  679. ? 'group-hover:rotate-[15deg]'
  680. : 'group-hover:rotate-[-15deg]'}"
  681. />
  682. <div
  683. class="h-3 w-1 rounded-full bg-[#0f0f0f] dark:bg-white rotate-0 translate-y-[-0.15rem] {show
  684. ? 'group-hover:rotate-[-15deg]'
  685. : 'group-hover:rotate-[15deg]'}"
  686. />
  687. </div>
  688. </div>
  689. </span>
  690. </button>
  691. </Tooltip>
  692. </div>
  693. </div>