Sidebar.svelte 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646
  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 } from '$lib/stores';
  8. import { onMount } from 'svelte';
  9. import { deleteChatById, getChatList, updateChatById } from '$lib/apis/chats';
  10. let show = false;
  11. let navElement;
  12. let title: string = 'Ollama Web UI';
  13. let search = '';
  14. let chatDeleteId = null;
  15. let chatTitleEditId = null;
  16. let chatTitle = '';
  17. let showDropdown = false;
  18. onMount(async () => {
  19. if (window.innerWidth > 1280) {
  20. show = true;
  21. }
  22. await chats.set(await getChatList(localStorage.token));
  23. });
  24. const loadChat = async (id) => {
  25. goto(`/c/${id}`);
  26. };
  27. const editChatTitle = async (id, _title) => {
  28. title = _title;
  29. await updateChatById(localStorage.token, id, {
  30. title: _title
  31. });
  32. await chats.set(await getChatList(localStorage.token));
  33. };
  34. const deleteChat = async (id) => {
  35. goto('/');
  36. await deleteChatById(localStorage.token, id);
  37. await chats.set(await getChatList(localStorage.token));
  38. };
  39. const saveSettings = async (updated) => {
  40. await settings.set({ ...$settings, ...updated });
  41. localStorage.setItem('settings', JSON.stringify($settings));
  42. location.href = '/';
  43. };
  44. </script>
  45. <div
  46. bind:this={navElement}
  47. class="h-screen {show
  48. ? ''
  49. : '-translate-x-[260px]'} w-[260px] fixed top-0 left-0 z-40 transition bg-black text-gray-200 shadow-2xl text-sm
  50. "
  51. >
  52. <div class="py-2.5 my-auto flex flex-col justify-between h-screen">
  53. <div class="px-2.5 flex justify-center space-x-2">
  54. <button
  55. id="sidebar-new-chat-button"
  56. class="flex-grow flex justify-between rounded-md px-3 py-1.5 mt-2 hover:bg-gray-900 transition"
  57. on:click={async () => {
  58. goto('/');
  59. const newChatButton = document.getElementById('new-chat-button');
  60. if (newChatButton) {
  61. newChatButton.click();
  62. }
  63. }}
  64. >
  65. <div class="flex self-center">
  66. <div class="self-center mr-3.5">
  67. <img src="/ollama.png" class=" w-5 invert-[100%] rounded-full" />
  68. </div>
  69. <div class=" self-center font-medium text-sm">New Chat</div>
  70. </div>
  71. <div class="self-center">
  72. <svg
  73. xmlns="http://www.w3.org/2000/svg"
  74. viewBox="0 0 20 20"
  75. fill="currentColor"
  76. class="w-4 h-4"
  77. >
  78. <path
  79. 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"
  80. />
  81. <path
  82. 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"
  83. />
  84. </svg>
  85. </div>
  86. </button>
  87. </div>
  88. {#if $user?.role === 'admin'}
  89. <div class="px-2.5 flex justify-center mt-1">
  90. <button
  91. class="flex-grow flex space-x-3 rounded-md px-3 py-2 hover:bg-gray-900 transition"
  92. on:click={async () => {
  93. goto('/modelfiles');
  94. }}
  95. >
  96. <div class="self-center">
  97. <svg
  98. xmlns="http://www.w3.org/2000/svg"
  99. fill="none"
  100. viewBox="0 0 24 24"
  101. stroke-width="1.5"
  102. stroke="currentColor"
  103. class="w-4 h-4"
  104. >
  105. <path
  106. stroke-linecap="round"
  107. stroke-linejoin="round"
  108. d="M13.5 16.875h3.375m0 0h3.375m-3.375 0V13.5m0 3.375v3.375M6 10.5h2.25a2.25 2.25 0 002.25-2.25V6a2.25 2.25 0 00-2.25-2.25H6A2.25 2.25 0 003.75 6v2.25A2.25 2.25 0 006 10.5zm0 9.75h2.25A2.25 2.25 0 0010.5 18v-2.25a2.25 2.25 0 00-2.25-2.25H6a2.25 2.25 0 00-2.25 2.25V18A2.25 2.25 0 006 20.25zm9.75-9.75H18a2.25 2.25 0 002.25-2.25V6A2.25 2.25 0 0018 3.75h-2.25A2.25 2.25 0 0013.5 6v2.25a2.25 2.25 0 002.25 2.25z"
  109. />
  110. </svg>
  111. </div>
  112. <div class="flex self-center">
  113. <div class=" self-center font-medium text-sm">Modelfiles</div>
  114. </div>
  115. </button>
  116. </div>
  117. <div class="px-2.5 flex justify-center mb-1">
  118. <button
  119. class="flex-grow flex space-x-3 rounded-md px-3 py-2 hover:bg-gray-900 transition"
  120. on:click={async () => {
  121. goto('/prompts');
  122. }}
  123. >
  124. <div class="self-center">
  125. <svg
  126. xmlns="http://www.w3.org/2000/svg"
  127. viewBox="0 0 16 16"
  128. fill="currentColor"
  129. class="w-4 h-4"
  130. >
  131. <path
  132. fill-rule="evenodd"
  133. d="M11.013 2.513a1.75 1.75 0 0 1 2.475 2.474L6.226 12.25a2.751 2.751 0 0 1-.892.596l-2.047.848a.75.75 0 0 1-.98-.98l.848-2.047a2.75 2.75 0 0 1 .596-.892l7.262-7.261Z"
  134. clip-rule="evenodd"
  135. />
  136. </svg>
  137. </div>
  138. <div class="flex self-center">
  139. <div class=" self-center font-medium text-sm">Prompts</div>
  140. </div>
  141. </button>
  142. </div>
  143. {/if}
  144. <div class="relative flex flex-col flex-1 overflow-y-auto">
  145. {#if !($settings.saveChatHistory ?? true)}
  146. <div class="absolute z-40 w-full h-full bg-black/90 flex justify-center">
  147. <div class=" text-left px-5 py-2">
  148. <div class=" font-medium">Chat History is off for this browser.</div>
  149. <div class="text-xs mt-2">
  150. When history is turned off, new chats on this browser won't appear in your history on
  151. any of your devices. <span class=" font-semibold"
  152. >This setting does not sync across browsers or devices.</span
  153. >
  154. </div>
  155. <div class="mt-3">
  156. <button
  157. 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"
  158. type="button"
  159. on:click={() => {
  160. saveSettings({
  161. saveChatHistory: true
  162. });
  163. }}
  164. >
  165. <svg
  166. xmlns="http://www.w3.org/2000/svg"
  167. viewBox="0 0 16 16"
  168. fill="currentColor"
  169. class="w-3 h-3"
  170. >
  171. <path
  172. fill-rule="evenodd"
  173. 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"
  174. clip-rule="evenodd"
  175. />
  176. </svg>
  177. <div>Enable Chat History</div>
  178. </button>
  179. </div>
  180. </div>
  181. </div>
  182. {/if}
  183. <div class="px-2.5 mt-1 mb-2 flex justify-center space-x-2">
  184. <div class="flex w-full" id="chat-search">
  185. <div class="self-center pl-3 py-2 rounded-l bg-gray-950">
  186. <svg
  187. xmlns="http://www.w3.org/2000/svg"
  188. viewBox="0 0 20 20"
  189. fill="currentColor"
  190. class="w-4 h-4"
  191. >
  192. <path
  193. fill-rule="evenodd"
  194. 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"
  195. clip-rule="evenodd"
  196. />
  197. </svg>
  198. </div>
  199. <input
  200. class="w-full rounded-r py-1.5 pl-2.5 pr-4 text-sm text-gray-300 bg-gray-950 outline-none"
  201. placeholder="Search"
  202. bind:value={search}
  203. />
  204. <!-- <div class="self-center pr-3 py-2 bg-gray-900">
  205. <svg
  206. xmlns="http://www.w3.org/2000/svg"
  207. fill="none"
  208. viewBox="0 0 24 24"
  209. stroke-width="1.5"
  210. stroke="currentColor"
  211. class="w-4 h-4"
  212. >
  213. <path
  214. stroke-linecap="round"
  215. stroke-linejoin="round"
  216. d="M12 3c2.755 0 5.455.232 8.083.678.533.09.917.556.917 1.096v1.044a2.25 2.25 0 01-.659 1.591l-5.432 5.432a2.25 2.25 0 00-.659 1.591v2.927a2.25 2.25 0 01-1.244 2.013L9.75 21v-6.568a2.25 2.25 0 00-.659-1.591L3.659 7.409A2.25 2.25 0 013 5.818V4.774c0-.54.384-1.006.917-1.096A48.32 48.32 0 0112 3z"
  217. />
  218. </svg>
  219. </div> -->
  220. </div>
  221. </div>
  222. <div class="pl-2.5 my-2 flex-1 flex flex-col space-y-1 overflow-y-auto">
  223. {#each $chats.filter((chat) => {
  224. if (search === '') {
  225. return true;
  226. } else {
  227. let title = chat.title.toLowerCase();
  228. if (title.includes(search)) {
  229. return true;
  230. } else {
  231. return false;
  232. }
  233. }
  234. }) as chat, i}
  235. <div class=" w-full pr-2 relative">
  236. <button
  237. class=" w-full flex justify-between rounded-md px-3 py-2 hover:bg-gray-900 {chat.id ===
  238. $chatId
  239. ? 'bg-gray-900'
  240. : ''} transition whitespace-nowrap text-ellipsis"
  241. on:click={() => {
  242. // goto(`/c/${chat.id}`);
  243. if (chat.id !== chatTitleEditId) {
  244. chatTitleEditId = null;
  245. chatTitle = '';
  246. }
  247. if (chat.id !== $chatId) {
  248. loadChat(chat.id);
  249. }
  250. }}
  251. >
  252. <div class=" flex self-center flex-1">
  253. <div class=" self-center mr-3">
  254. <svg
  255. xmlns="http://www.w3.org/2000/svg"
  256. fill="none"
  257. viewBox="0 0 24 24"
  258. stroke-width="1.5"
  259. stroke="currentColor"
  260. class="w-4 h-4"
  261. >
  262. <path
  263. stroke-linecap="round"
  264. stroke-linejoin="round"
  265. d="M2.25 12.76c0 1.6 1.123 2.994 2.707 3.227 1.087.16 2.185.283 3.293.369V21l4.076-4.076a1.526 1.526 0 011.037-.443 48.282 48.282 0 005.68-.494c1.584-.233 2.707-1.626 2.707-3.228V6.741c0-1.602-1.123-2.995-2.707-3.228A48.394 48.394 0 0012 3c-2.392 0-4.744.175-7.043.513C3.373 3.746 2.25 5.14 2.25 6.741v6.018z"
  266. />
  267. </svg>
  268. </div>
  269. <div
  270. class=" text-left self-center overflow-hidden {chat.id === $chatId
  271. ? 'w-[120px]'
  272. : 'w-[180px]'} "
  273. >
  274. {#if chatTitleEditId === chat.id}
  275. <input bind:value={chatTitle} class=" bg-transparent w-full" />
  276. {:else}
  277. {chat.title}
  278. {/if}
  279. </div>
  280. </div>
  281. </button>
  282. {#if chat.id === $chatId}
  283. <div class=" absolute right-[22px] top-[10px]">
  284. {#if chatTitleEditId === chat.id}
  285. <div class="flex self-center space-x-1.5">
  286. <button
  287. class=" self-center hover:text-white transition"
  288. on:click={() => {
  289. editChatTitle(chat.id, chatTitle);
  290. chatTitleEditId = null;
  291. chatTitle = '';
  292. }}
  293. >
  294. <svg
  295. xmlns="http://www.w3.org/2000/svg"
  296. viewBox="0 0 20 20"
  297. fill="currentColor"
  298. class="w-4 h-4"
  299. >
  300. <path
  301. fill-rule="evenodd"
  302. 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"
  303. clip-rule="evenodd"
  304. />
  305. </svg>
  306. </button>
  307. <button
  308. class=" self-center hover:text-white transition"
  309. on:click={() => {
  310. chatTitleEditId = null;
  311. chatTitle = '';
  312. }}
  313. >
  314. <svg
  315. xmlns="http://www.w3.org/2000/svg"
  316. viewBox="0 0 20 20"
  317. fill="currentColor"
  318. class="w-4 h-4"
  319. >
  320. <path
  321. 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"
  322. />
  323. </svg>
  324. </button>
  325. </div>
  326. {:else if chatDeleteId === chat.id}
  327. <div class="flex self-center space-x-1.5">
  328. <button
  329. class=" self-center hover:text-white transition"
  330. on:click={() => {
  331. deleteChat(chat.id);
  332. }}
  333. >
  334. <svg
  335. xmlns="http://www.w3.org/2000/svg"
  336. viewBox="0 0 20 20"
  337. fill="currentColor"
  338. class="w-4 h-4"
  339. >
  340. <path
  341. fill-rule="evenodd"
  342. 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"
  343. clip-rule="evenodd"
  344. />
  345. </svg>
  346. </button>
  347. <button
  348. class=" self-center hover:text-white transition"
  349. on:click={() => {
  350. chatDeleteId = null;
  351. }}
  352. >
  353. <svg
  354. xmlns="http://www.w3.org/2000/svg"
  355. viewBox="0 0 20 20"
  356. fill="currentColor"
  357. class="w-4 h-4"
  358. >
  359. <path
  360. 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"
  361. />
  362. </svg>
  363. </button>
  364. </div>
  365. {:else}
  366. <div class="flex self-center space-x-1.5">
  367. <button
  368. id="delete-chat-button"
  369. class=" hidden"
  370. on:click={() => {
  371. deleteChat(chat.id);
  372. }}
  373. />
  374. <button
  375. class=" self-center hover:text-white transition"
  376. on:click={() => {
  377. chatTitle = chat.title;
  378. chatTitleEditId = chat.id;
  379. // editChatTitle(chat.id, 'a');
  380. }}
  381. >
  382. <svg
  383. xmlns="http://www.w3.org/2000/svg"
  384. fill="none"
  385. viewBox="0 0 24 24"
  386. stroke-width="1.5"
  387. stroke="currentColor"
  388. class="w-4 h-4"
  389. >
  390. <path
  391. stroke-linecap="round"
  392. stroke-linejoin="round"
  393. d="M16.862 4.487l1.687-1.688a1.875 1.875 0 112.652 2.652L6.832 19.82a4.5 4.5 0 01-1.897 1.13l-2.685.8.8-2.685a4.5 4.5 0 011.13-1.897L16.863 4.487zm0 0L19.5 7.125"
  394. />
  395. </svg>
  396. </button>
  397. <button
  398. class=" self-center hover:text-white transition"
  399. on:click={() => {
  400. chatDeleteId = chat.id;
  401. }}
  402. >
  403. <svg
  404. xmlns="http://www.w3.org/2000/svg"
  405. fill="none"
  406. viewBox="0 0 24 24"
  407. stroke-width="1.5"
  408. stroke="currentColor"
  409. class="w-4 h-4"
  410. >
  411. <path
  412. stroke-linecap="round"
  413. stroke-linejoin="round"
  414. d="M14.74 9l-.346 9m-4.788 0L9.26 9m9.968-3.21c.342.052.682.107 1.022.166m-1.022-.165L18.16 19.673a2.25 2.25 0 01-2.244 2.077H8.084a2.25 2.25 0 01-2.244-2.077L4.772 5.79m14.456 0a48.108 48.108 0 00-3.478-.397m-12 .562c.34-.059.68-.114 1.022-.165m0 0a48.11 48.11 0 013.478-.397m7.5 0v-.916c0-1.18-.91-2.164-2.09-2.201a51.964 51.964 0 00-3.32 0c-1.18.037-2.09 1.022-2.09 2.201v.916m7.5 0a48.667 48.667 0 00-7.5 0"
  415. />
  416. </svg>
  417. </button>
  418. </div>
  419. {/if}
  420. </div>
  421. {/if}
  422. </div>
  423. {/each}
  424. </div>
  425. </div>
  426. <div class="px-2.5">
  427. <hr class=" border-gray-900 mb-1 w-full" />
  428. <div class="flex flex-col">
  429. {#if $user !== undefined}
  430. <button
  431. class=" flex rounded-md py-3 px-3.5 w-full hover:bg-gray-900 transition"
  432. on:click={() => {
  433. showDropdown = !showDropdown;
  434. }}
  435. >
  436. <div class=" self-center mr-3">
  437. <img
  438. src={$user.profile_image_url}
  439. class=" max-w-[30px] object-cover rounded-full"
  440. alt="User profile"
  441. />
  442. </div>
  443. <div class=" self-center font-semibold">{$user.name}</div>
  444. </button>
  445. {#if showDropdown}
  446. <div
  447. id="dropdownDots"
  448. class="absolute z-10 bottom-[70px] 4.5rem rounded-lg shadow w-[240px] bg-gray-900"
  449. >
  450. <div class="py-2 w-full">
  451. {#if $user.role === 'admin'}
  452. <button
  453. class="flex py-2.5 px-3.5 w-full hover:bg-gray-800 transition"
  454. on:click={() => {
  455. goto('/admin');
  456. showDropdown = false;
  457. }}
  458. >
  459. <div class=" self-center mr-3">
  460. <svg
  461. xmlns="http://www.w3.org/2000/svg"
  462. fill="none"
  463. viewBox="0 0 24 24"
  464. stroke-width="1.5"
  465. stroke="currentColor"
  466. class="w-5 h-5"
  467. >
  468. <path
  469. stroke-linecap="round"
  470. stroke-linejoin="round"
  471. 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"
  472. />
  473. </svg>
  474. </div>
  475. <div class=" self-center font-medium">Admin Panel</div>
  476. </button>
  477. {/if}
  478. <button
  479. class="flex py-2.5 px-3.5 w-full hover:bg-gray-800 transition"
  480. on:click={async () => {
  481. await showSettings.set(true);
  482. showDropdown = false;
  483. }}
  484. >
  485. <div class=" self-center mr-3">
  486. <svg
  487. xmlns="http://www.w3.org/2000/svg"
  488. fill="none"
  489. viewBox="0 0 24 24"
  490. stroke-width="1.5"
  491. stroke="currentColor"
  492. class="w-5 h-5"
  493. >
  494. <path
  495. stroke-linecap="round"
  496. stroke-linejoin="round"
  497. 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"
  498. />
  499. <path
  500. stroke-linecap="round"
  501. stroke-linejoin="round"
  502. d="M15 12a3 3 0 11-6 0 3 3 0 016 0z"
  503. />
  504. </svg>
  505. </div>
  506. <div class=" self-center font-medium">Settings</div>
  507. </button>
  508. </div>
  509. <hr class=" border-gray-700 m-0 p-0" />
  510. <div class="py-2 w-full">
  511. <button
  512. class="flex py-2.5 px-3.5 w-full hover:bg-gray-800 transition"
  513. on:click={() => {
  514. localStorage.removeItem('token');
  515. location.href = '/auth';
  516. showDropdown = false;
  517. }}
  518. >
  519. <div class=" self-center mr-3">
  520. <svg
  521. xmlns="http://www.w3.org/2000/svg"
  522. viewBox="0 0 20 20"
  523. fill="currentColor"
  524. class="w-5 h-5"
  525. >
  526. <path
  527. fill-rule="evenodd"
  528. 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"
  529. clip-rule="evenodd"
  530. />
  531. <path
  532. fill-rule="evenodd"
  533. 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"
  534. clip-rule="evenodd"
  535. />
  536. </svg>
  537. </div>
  538. <div class=" self-center font-medium">Sign Out</div>
  539. </button>
  540. </div>
  541. </div>
  542. {/if}
  543. {:else}
  544. <button
  545. class=" flex rounded-md py-3 px-3.5 w-full hover:bg-gray-900 transition"
  546. on:click={async () => {
  547. await showSettings.set(true);
  548. }}
  549. >
  550. <div class=" self-center mr-3">
  551. <svg
  552. xmlns="http://www.w3.org/2000/svg"
  553. fill="none"
  554. viewBox="0 0 24 24"
  555. stroke-width="1.5"
  556. stroke="currentColor"
  557. class="w-5 h-5"
  558. >
  559. <path
  560. stroke-linecap="round"
  561. stroke-linejoin="round"
  562. 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"
  563. />
  564. <path
  565. stroke-linecap="round"
  566. stroke-linejoin="round"
  567. d="M15 12a3 3 0 11-6 0 3 3 0 016 0z"
  568. />
  569. </svg>
  570. </div>
  571. <div class=" self-center font-medium">Settings</div>
  572. </button>
  573. {/if}
  574. </div>
  575. </div>
  576. </div>
  577. <div
  578. class="fixed left-0 top-[50dvh] z-40 -translate-y-1/2 transition-transform translate-x-[255px] md:translate-x-[260px] rotate-0"
  579. >
  580. <button
  581. id="sidebar-toggle-button"
  582. class=" group"
  583. on:click={() => {
  584. show = !show;
  585. }}
  586. ><span class="" data-state="closed"
  587. ><div
  588. class="flex h-[72px] w-8 items-center justify-center opacity-20 group-hover:opacity-100 transition"
  589. >
  590. <div class="flex h-6 w-6 flex-col items-center">
  591. <div
  592. class="h-3 w-1 rounded-full bg-[#0f0f0f] dark:bg-white rotate-0 translate-y-[0.15rem] {show
  593. ? 'group-hover:rotate-[15deg]'
  594. : 'group-hover:rotate-[-15deg]'}"
  595. />
  596. <div
  597. class="h-3 w-1 rounded-full bg-[#0f0f0f] dark:bg-white rotate-0 translate-y-[-0.15rem] {show
  598. ? 'group-hover:rotate-[-15deg]'
  599. : 'group-hover:rotate-[15deg]'}"
  600. />
  601. </div>
  602. </div>
  603. </span>
  604. </button>
  605. </div>
  606. </div>