Sidebar.svelte 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653
  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, db, chats, showSettings, chatId } from '$lib/stores';
  8. import { onMount } from 'svelte';
  9. let show = false;
  10. let navElement;
  11. let importFileInputElement;
  12. let importFiles;
  13. let title: string = 'Ollama Web UI';
  14. let chatTitleEditIdx = null;
  15. let chatTitle = '';
  16. let showDropdown = false;
  17. let _chats = $chats.map((item, idx) => $chats[$chats.length - 1 - idx]);
  18. $: if ($chats) {
  19. // Reverse Order
  20. _chats = $chats.map((item, idx) => $chats[$chats.length - 1 - idx]);
  21. }
  22. onMount(async () => {
  23. if (window.innerWidth > 1280) {
  24. show = true;
  25. }
  26. await chats.set(await $db.getAllFromIndex('chats', 'timestamp'));
  27. });
  28. const loadChat = async (id) => {
  29. goto(`/c/${id}`);
  30. // const chat = await db.get('chats', id);
  31. // console.log(chat);
  32. // if (chatId !== chat.id) {
  33. // if ('history' in chat && chat.history !== undefined) {
  34. // history = chat.history;
  35. // } else {
  36. // let _history = {
  37. // messages: {},
  38. // currentId: null
  39. // };
  40. // let parentMessageId = null;
  41. // let messageId = null;
  42. // for (const message of chat.messages) {
  43. // messageId = uuidv4();
  44. // if (parentMessageId !== null) {
  45. // _history.messages[parentMessageId].childrenIds = [
  46. // ..._history.messages[parentMessageId].childrenIds,
  47. // messageId
  48. // ];
  49. // }
  50. // _history.messages[messageId] = {
  51. // ...message,
  52. // id: messageId,
  53. // parentId: parentMessageId,
  54. // childrenIds: []
  55. // };
  56. // parentMessageId = messageId;
  57. // }
  58. // _history.currentId = messageId;
  59. // history = _history;
  60. // }
  61. // if ('models' in chat && chat.models !== undefined) {
  62. // selectedModels = chat.models ?? selectedModels;
  63. // } else {
  64. // selectedModels = [chat.model ?? ''];
  65. // }
  66. // console.log(history);
  67. // title = chat.title;
  68. // chatId = chat.id;
  69. // settings.system = chat.system ?? settings.system;
  70. // settings.temperature = chat.temperature ?? settings.temperature;
  71. // autoScroll = true;
  72. // await tick();
  73. // if (messages.length > 0) {
  74. // history.messages[messages.at(-1).id].done = true;
  75. // }
  76. // }
  77. };
  78. const editChatTitle = async (id, _title) => {
  79. const chat = await $db.get('chats', id);
  80. console.log(chat);
  81. await $db.put('chats', {
  82. ...chat,
  83. title: _title
  84. });
  85. title = _title;
  86. await chats.set(await $db.getAllFromIndex('chats', 'timestamp'));
  87. };
  88. const deleteChat = async (id) => {
  89. goto('/');
  90. const chat = await $db.delete('chats', id);
  91. console.log(chat);
  92. await chats.set(await $db.getAllFromIndex('chats', 'timestamp'));
  93. };
  94. const deleteChatHistory = async () => {
  95. const tx = $db.transaction('chats', 'readwrite');
  96. await Promise.all([tx.store.clear(), tx.done]);
  97. await chats.set(await $db.getAllFromIndex('chats', 'timestamp'));
  98. };
  99. const importChatHistory = async (chatHistory) => {
  100. for (const chat of chatHistory) {
  101. console.log(chat);
  102. await $db.put('chats', {
  103. id: chat.id,
  104. model: chat.model,
  105. models: chat.models,
  106. system: chat.system,
  107. options: chat.options,
  108. title: chat.title,
  109. timestamp: chat.timestamp,
  110. messages: chat.messages,
  111. history: chat.history
  112. });
  113. }
  114. await chats.set(await $db.getAllFromIndex('chats', 'timestamp'));
  115. console.log(chats);
  116. };
  117. const exportChatHistory = async () => {
  118. await chats.set(await $db.getAllFromIndex('chats', 'timestamp'));
  119. let blob = new Blob([JSON.stringify($chats)], { type: 'application/json' });
  120. saveAs(blob, `chat-export-${Date.now()}.json`);
  121. };
  122. $: if (importFiles) {
  123. console.log(importFiles);
  124. let reader = new FileReader();
  125. reader.onload = (event) => {
  126. let chats = JSON.parse(event.target.result);
  127. console.log(chats);
  128. importChatHistory(chats);
  129. };
  130. reader.readAsText(importFiles[0]);
  131. }
  132. </script>
  133. <div
  134. bind:this={navElement}
  135. class="h-screen {show
  136. ? ''
  137. : '-translate-x-[260px]'} w-[260px] fixed top-0 left-0 z-40 transition bg-[#0a0a0a] text-gray-200 shadow-2xl text-sm
  138. "
  139. >
  140. <div class="py-2.5 my-auto flex flex-col justify-between h-screen">
  141. <div class="px-2.5 flex justify-center space-x-2">
  142. <button
  143. class="flex-grow flex justify-between rounded-md px-3 py-1.5 my-2 hover:bg-gray-900 transition"
  144. on:click={async () => {
  145. goto('/');
  146. await chatId.set(uuidv4());
  147. // createNewChat();
  148. }}
  149. >
  150. <div class="flex self-center">
  151. <div class="self-center mr-3.5">
  152. <img src="/ollama.png" class=" w-5 invert-[100%] rounded-full" />
  153. </div>
  154. <div class=" self-center font-medium text-sm">New Chat</div>
  155. </div>
  156. <div class="self-center">
  157. <svg
  158. xmlns="http://www.w3.org/2000/svg"
  159. viewBox="0 0 20 20"
  160. fill="currentColor"
  161. class="w-4 h-4"
  162. >
  163. <path
  164. 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"
  165. />
  166. <path
  167. 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"
  168. />
  169. </svg>
  170. </div>
  171. </button>
  172. <!-- <button
  173. class=" cursor-pointer w-12 rounded-md flex"
  174. on:click={() => {
  175. show = !show;
  176. }}
  177. >
  178. <div class=" m-auto self-center">
  179. <svg
  180. xmlns="http://www.w3.org/2000/svg"
  181. viewBox="0 0 20 20"
  182. fill="currentColor"
  183. class="w-5 h-5"
  184. >
  185. <path
  186. fill-rule="evenodd"
  187. 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"
  188. clip-rule="evenodd"
  189. />
  190. <path
  191. fill-rule="evenodd"
  192. d="M19 10a.75.75 0 00-.75-.75H8.704l1.048-.943a.75.75 0 10-1.004-1.114l-2.5 2.25a.75.75 0 000 1.114l2.5 2.25a.75.75 0 101.004-1.114l-1.048-.943h9.546A.75.75 0 0019 10z"
  193. clip-rule="evenodd"
  194. />
  195. </svg>
  196. </div>
  197. </button> -->
  198. </div>
  199. <div class="pl-2.5 my-3 flex-1 flex flex-col space-y-1 overflow-y-auto">
  200. {#each _chats as chat, i}
  201. <div class=" w-full pr-2 relative">
  202. <button
  203. class=" w-full flex justify-between rounded-md px-3 py-2 hover:bg-gray-900 {chat.id ===
  204. $chatId
  205. ? 'bg-gray-900'
  206. : ''} transition whitespace-nowrap text-ellipsis"
  207. on:click={() => {
  208. // goto(`/c/${chat.id}`);
  209. if (chat.id !== chatTitleEditIdx) {
  210. chatTitleEditIdx = null;
  211. chatTitle = '';
  212. }
  213. if (chat.id !== $chatId) {
  214. loadChat(chat.id);
  215. }
  216. }}
  217. >
  218. <div class=" flex self-center flex-1">
  219. <div class=" self-center mr-3">
  220. <svg
  221. xmlns="http://www.w3.org/2000/svg"
  222. fill="none"
  223. viewBox="0 0 24 24"
  224. stroke-width="1.5"
  225. stroke="currentColor"
  226. class="w-4 h-4"
  227. >
  228. <path
  229. stroke-linecap="round"
  230. stroke-linejoin="round"
  231. 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"
  232. />
  233. </svg>
  234. </div>
  235. <div
  236. class=" text-left self-center overflow-hidden {chat.id === $chatId
  237. ? 'w-[120px]'
  238. : 'w-[180px]'} "
  239. >
  240. {#if chatTitleEditIdx === chat.id}
  241. <input bind:value={chatTitle} class=" bg-transparent w-full" />
  242. {:else}
  243. {chat.title}
  244. {/if}
  245. </div>
  246. </div>
  247. </button>
  248. {#if chat.id === $chatId}
  249. <div class=" absolute right-[22px] top-[10px]">
  250. {#if chatTitleEditIdx === chat.id}
  251. <div class="flex self-center space-x-1.5">
  252. <button
  253. class=" self-center hover:text-white transition"
  254. on:click={() => {
  255. editChatTitle(chat.id, chatTitle);
  256. chatTitleEditIdx = null;
  257. chatTitle = '';
  258. }}
  259. >
  260. <svg
  261. xmlns="http://www.w3.org/2000/svg"
  262. viewBox="0 0 20 20"
  263. fill="currentColor"
  264. class="w-4 h-4"
  265. >
  266. <path
  267. fill-rule="evenodd"
  268. 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"
  269. clip-rule="evenodd"
  270. />
  271. </svg>
  272. </button>
  273. <button
  274. class=" self-center hover:text-white transition"
  275. on:click={() => {
  276. chatTitleEditIdx = null;
  277. chatTitle = '';
  278. }}
  279. >
  280. <svg
  281. xmlns="http://www.w3.org/2000/svg"
  282. viewBox="0 0 20 20"
  283. fill="currentColor"
  284. class="w-4 h-4"
  285. >
  286. <path
  287. 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"
  288. />
  289. </svg>
  290. </button>
  291. </div>
  292. {:else}
  293. <div class="flex self-center space-x-1.5">
  294. <button
  295. class=" self-center hover:text-white transition"
  296. on:click={() => {
  297. chatTitle = chat.title;
  298. chatTitleEditIdx = chat.id;
  299. // editChatTitle(chat.id, 'a');
  300. }}
  301. >
  302. <svg
  303. xmlns="http://www.w3.org/2000/svg"
  304. fill="none"
  305. viewBox="0 0 24 24"
  306. stroke-width="1.5"
  307. stroke="currentColor"
  308. class="w-4 h-4"
  309. >
  310. <path
  311. stroke-linecap="round"
  312. stroke-linejoin="round"
  313. 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"
  314. />
  315. </svg>
  316. </button>
  317. <button
  318. class=" self-center hover:text-white transition"
  319. on:click={() => {
  320. deleteChat(chat.id);
  321. }}
  322. >
  323. <svg
  324. xmlns="http://www.w3.org/2000/svg"
  325. fill="none"
  326. viewBox="0 0 24 24"
  327. stroke-width="1.5"
  328. stroke="currentColor"
  329. class="w-4 h-4"
  330. >
  331. <path
  332. stroke-linecap="round"
  333. stroke-linejoin="round"
  334. 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"
  335. />
  336. </svg>
  337. </button>
  338. </div>
  339. {/if}
  340. </div>
  341. {/if}
  342. </div>
  343. {/each}
  344. </div>
  345. <div class="px-2.5">
  346. <hr class=" border-gray-800 mb-2 w-full" />
  347. <div class="flex flex-col">
  348. <div class="flex">
  349. <input bind:this={importFileInputElement} bind:files={importFiles} type="file" hidden />
  350. <button
  351. class=" flex rounded-md py-3 px-3.5 w-full hover:bg-gray-900 transition"
  352. on:click={() => {
  353. importFileInputElement.click();
  354. // importChatHistory();
  355. }}
  356. >
  357. <div class=" self-center mr-3">
  358. <svg
  359. xmlns="http://www.w3.org/2000/svg"
  360. fill="none"
  361. viewBox="0 0 24 24"
  362. stroke-width="1.5"
  363. stroke="currentColor"
  364. class="w-5 h-5"
  365. >
  366. <path
  367. stroke-linecap="round"
  368. stroke-linejoin="round"
  369. d="M19.5 14.25v-2.625a3.375 3.375 0 00-3.375-3.375h-1.5A1.125 1.125 0 0113.5 7.125v-1.5a3.375 3.375 0 00-3.375-3.375H8.25m6.75 12l-3-3m0 0l-3 3m3-3v6m-1.5-15H5.625c-.621 0-1.125.504-1.125 1.125v17.25c0 .621.504 1.125 1.125 1.125h12.75c.621 0 1.125-.504 1.125-1.125V11.25a9 9 0 00-9-9z"
  370. />
  371. </svg>
  372. </div>
  373. <div class=" self-center">Import</div>
  374. </button>
  375. <button
  376. class=" flex rounded-md py-3 px-3.5 w-full hover:bg-gray-900 transition"
  377. on:click={() => {
  378. exportChatHistory();
  379. }}
  380. >
  381. <div class=" self-center mr-3">
  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-5 h-5"
  389. >
  390. <path
  391. stroke-linecap="round"
  392. stroke-linejoin="round"
  393. d="M19.5 14.25v-2.625a3.375 3.375 0 00-3.375-3.375h-1.5A1.125 1.125 0 0113.5 7.125v-1.5a3.375 3.375 0 00-3.375-3.375H8.25m.75 12l3 3m0 0l3-3m-3 3v-6m-1.5-9H5.625c-.621 0-1.125.504-1.125 1.125v17.25c0 .621.504 1.125 1.125 1.125h12.75c.621 0 1.125-.504 1.125-1.125V11.25a9 9 0 00-9-9z"
  394. />
  395. </svg>
  396. </div>
  397. <div class=" self-center">Export</div>
  398. </button>
  399. </div>
  400. <button
  401. class=" flex rounded-md py-3 px-3.5 w-full hover:bg-gray-900 transition"
  402. on:click={() => {
  403. deleteChatHistory();
  404. }}
  405. >
  406. <div class=" self-center mr-3">
  407. <svg
  408. xmlns="http://www.w3.org/2000/svg"
  409. fill="none"
  410. viewBox="0 0 24 24"
  411. stroke-width="1.5"
  412. stroke="currentColor"
  413. class="w-5 h-5"
  414. >
  415. <path
  416. stroke-linecap="round"
  417. stroke-linejoin="round"
  418. 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"
  419. />
  420. </svg>
  421. </div>
  422. <div class=" self-center">Clear conversations</div>
  423. </button>
  424. {#if $user !== undefined}
  425. <button
  426. class=" flex rounded-md py-3 px-3.5 w-full hover:bg-gray-900 transition"
  427. on:click={() => {
  428. showDropdown = !showDropdown;
  429. }}
  430. on:focusout={() => {
  431. setTimeout(() => {
  432. showDropdown = false;
  433. }, 150);
  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. }}
  457. >
  458. <div class=" self-center mr-3">
  459. <svg
  460. xmlns="http://www.w3.org/2000/svg"
  461. fill="none"
  462. viewBox="0 0 24 24"
  463. stroke-width="1.5"
  464. stroke="currentColor"
  465. class="w-5 h-5"
  466. >
  467. <path
  468. stroke-linecap="round"
  469. stroke-linejoin="round"
  470. 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"
  471. />
  472. </svg>
  473. </div>
  474. <div class=" self-center font-medium">Admin Panel</div>
  475. </button>
  476. {/if}
  477. <button
  478. class="flex py-2.5 px-3.5 w-full hover:bg-gray-800 transition"
  479. on:click={async () => {
  480. await showSettings.set(true);
  481. }}
  482. >
  483. <div class=" self-center mr-3">
  484. <svg
  485. xmlns="http://www.w3.org/2000/svg"
  486. fill="none"
  487. viewBox="0 0 24 24"
  488. stroke-width="1.5"
  489. stroke="currentColor"
  490. class="w-5 h-5"
  491. >
  492. <path
  493. stroke-linecap="round"
  494. stroke-linejoin="round"
  495. 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"
  496. />
  497. <path
  498. stroke-linecap="round"
  499. stroke-linejoin="round"
  500. d="M15 12a3 3 0 11-6 0 3 3 0 016 0z"
  501. />
  502. </svg>
  503. </div>
  504. <div class=" self-center font-medium">Settings</div>
  505. </button>
  506. </div>
  507. <hr class=" border-gray-700 m-0 p-0" />
  508. <div class="py-2 w-full">
  509. <button
  510. class="flex py-2.5 px-3.5 w-full hover:bg-gray-800 transition"
  511. on:click={() => {
  512. localStorage.removeItem('token');
  513. location.href = '/auth';
  514. }}
  515. >
  516. <div class=" self-center mr-3">
  517. <svg
  518. xmlns="http://www.w3.org/2000/svg"
  519. viewBox="0 0 20 20"
  520. fill="currentColor"
  521. class="w-5 h-5"
  522. >
  523. <path
  524. fill-rule="evenodd"
  525. 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"
  526. clip-rule="evenodd"
  527. />
  528. <path
  529. fill-rule="evenodd"
  530. 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"
  531. clip-rule="evenodd"
  532. />
  533. </svg>
  534. </div>
  535. <div class=" self-center font-medium">Sign Out</div>
  536. </button>
  537. </div>
  538. </div>
  539. {/if}
  540. {:else}
  541. <button
  542. class=" flex rounded-md py-3 px-3.5 w-full hover:bg-gray-900 transition"
  543. on:click={async () => {
  544. await showSettings.set(true);
  545. }}
  546. >
  547. <div class=" self-center mr-3">
  548. <svg
  549. xmlns="http://www.w3.org/2000/svg"
  550. fill="none"
  551. viewBox="0 0 24 24"
  552. stroke-width="1.5"
  553. stroke="currentColor"
  554. class="w-5 h-5"
  555. >
  556. <path
  557. stroke-linecap="round"
  558. stroke-linejoin="round"
  559. 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"
  560. />
  561. <path
  562. stroke-linecap="round"
  563. stroke-linejoin="round"
  564. d="M15 12a3 3 0 11-6 0 3 3 0 016 0z"
  565. />
  566. </svg>
  567. </div>
  568. <div class=" self-center font-medium">Settings</div>
  569. </button>
  570. {/if}
  571. </div>
  572. </div>
  573. </div>
  574. <div
  575. class="fixed left-0 top-[50dvh] z-40 -translate-y-1/2 transition-transform translate-x-[255px] md:translate-x-[260px] rotate-0"
  576. >
  577. <button
  578. class=" group"
  579. on:click={() => {
  580. show = !show;
  581. }}
  582. ><span class="" data-state="closed"
  583. ><div
  584. class="flex h-[72px] w-8 items-center justify-center opacity-20 group-hover:opacity-100 transition"
  585. >
  586. <div class="flex h-6 w-6 flex-col items-center">
  587. <div
  588. class="h-3 w-1 rounded-full bg-[#0f0f0f] dark:bg-white rotate-0 translate-y-[0.15rem] {show
  589. ? 'group-hover:rotate-[15deg]'
  590. : 'group-hover:rotate-[-15deg]'}"
  591. />
  592. <div
  593. class="h-3 w-1 rounded-full bg-[#0f0f0f] dark:bg-white rotate-0 translate-y-[-0.15rem] {show
  594. ? 'group-hover:rotate-[-15deg]'
  595. : 'group-hover:rotate-[15deg]'}"
  596. />
  597. </div>
  598. </div>
  599. </span>
  600. </button>
  601. </div>
  602. </div>