Sidebar.svelte 24 KB

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