Navbar.svelte 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424
  1. <script lang="ts">
  2. import { onMount } from 'svelte';
  3. let show = false;
  4. let navElement;
  5. let importFileInputElement;
  6. let importFiles;
  7. export let selectedChatId = '';
  8. export let title: string = 'Ollama Web UI';
  9. export let chats = [];
  10. export let createNewChat: Function;
  11. export let loadChat: Function;
  12. export let deleteChat: Function;
  13. export let editChatTitle: Function;
  14. export let importChatHistory: Function;
  15. export let exportChatHistory: Function;
  16. export let deleteChatHistory: Function;
  17. export let openSettings: Function;
  18. let chatTitleEditIdx = null;
  19. let chatTitle = '';
  20. let _chats = chats.map((item, idx) => chats[chats.length - 1 - idx]);
  21. onMount(() => {});
  22. $: if (chats) {
  23. _chats = chats.map((item, idx) => chats[chats.length - 1 - idx]);
  24. }
  25. $: if (importFiles) {
  26. console.log(importFiles);
  27. let reader = new FileReader();
  28. reader.onload = (event) => {
  29. let chats = JSON.parse(event.target.result);
  30. console.log(chats);
  31. importChatHistory(chats);
  32. };
  33. reader.readAsText(importFiles[0]);
  34. }
  35. </script>
  36. <div
  37. class=" fixed top-0 flex flex-row justify-center bg-stone-100/5 text-gray-200 backdrop-blur-xl w-full z-30"
  38. >
  39. <div class="basis-full px-5">
  40. <nav class="py-3" id="nav">
  41. <div class="flex flex-row justify-between">
  42. <div class="pl-2">
  43. <button
  44. class=" cursor-pointer p-1 flex hover:bg-gray-700 rounded-lg transition"
  45. on:click={() => {
  46. show = !show;
  47. }}
  48. >
  49. <div class=" m-auto self-center">
  50. <svg
  51. xmlns="http://www.w3.org/2000/svg"
  52. viewBox="0 0 20 20"
  53. fill="currentColor"
  54. class="w-5 h-5"
  55. >
  56. <path
  57. fill-rule="evenodd"
  58. d="M2 4.75A.75.75 0 012.75 4h14.5a.75.75 0 010 1.5H2.75A.75.75 0 012 4.75zM2 10a.75.75 0 01.75-.75h14.5a.75.75 0 010 1.5H2.75A.75.75 0 012 10zm0 5.25a.75.75 0 01.75-.75h14.5a.75.75 0 010 1.5H2.75a.75.75 0 01-.75-.75z"
  59. clip-rule="evenodd"
  60. />
  61. </svg>
  62. </div>
  63. </button>
  64. </div>
  65. <div class=" self-center">
  66. {title != '' ? title.split(' ').slice(0, 7).join(' ') : 'Ollama Web UI'}
  67. </div>
  68. <div class="pr-2">
  69. <button
  70. class=" cursor-pointer p-1 flex hover:bg-gray-700 rounded-lg transition"
  71. on:click={() => {
  72. createNewChat();
  73. }}
  74. >
  75. <div class=" m-auto self-center">
  76. <svg
  77. xmlns="http://www.w3.org/2000/svg"
  78. viewBox="0 0 20 20"
  79. fill="currentColor"
  80. class="w-5 h-5"
  81. >
  82. <path
  83. d="M10.75 4.75a.75.75 0 00-1.5 0v4.5h-4.5a.75.75 0 000 1.5h4.5v4.5a.75.75 0 001.5 0v-4.5h4.5a.75.75 0 000-1.5h-4.5v-4.5z"
  84. />
  85. </svg>
  86. </div>
  87. </button>
  88. </div>
  89. </div>
  90. </nav>
  91. </div>
  92. </div>
  93. <div
  94. bind:this={navElement}
  95. class="h-screen {show
  96. ? ''
  97. : '-translate-x-72'} w-72 fixed top-0 left-0 z-40 transition bg-gray-900 text-gray-200 shadow-2xl text-sm
  98. "
  99. >
  100. <div class="py-2.5 my-auto flex flex-col justify-between h-screen">
  101. <div class="px-2.5 flex justify-center space-x-2">
  102. <button
  103. class=" cursor-pointer flex-grow rounded-md border border-gray-600 p-3 flex"
  104. on:click={() => {
  105. createNewChat();
  106. }}
  107. >
  108. <div class="self-center mr-2">
  109. <svg
  110. xmlns="http://www.w3.org/2000/svg"
  111. viewBox="0 0 20 20"
  112. fill="currentColor"
  113. class="w-5 h-5"
  114. >
  115. <path
  116. d="M10.75 4.75a.75.75 0 00-1.5 0v4.5h-4.5a.75.75 0 000 1.5h4.5v4.5a.75.75 0 001.5 0v-4.5h4.5a.75.75 0 000-1.5h-4.5v-4.5z"
  117. />
  118. </svg>
  119. </div>
  120. <div class=" self-center">New Chat</div>
  121. </button>
  122. <button
  123. class=" cursor-pointer w-12 rounded-md border border-gray-600 flex"
  124. on:click={() => {
  125. show = !show;
  126. }}
  127. >
  128. <div class=" m-auto self-center">
  129. <svg
  130. xmlns="http://www.w3.org/2000/svg"
  131. viewBox="0 0 20 20"
  132. fill="currentColor"
  133. class="w-5 h-5"
  134. >
  135. <path
  136. fill-rule="evenodd"
  137. 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"
  138. clip-rule="evenodd"
  139. />
  140. <path
  141. fill-rule="evenodd"
  142. 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"
  143. clip-rule="evenodd"
  144. />
  145. </svg>
  146. </div>
  147. </button>
  148. </div>
  149. <div class="pl-2.5 my-3 flex-1 flex flex-col space-y-1 overflow-y-auto">
  150. {#each _chats as chat, i}
  151. <div class=" w-full pr-2 relative">
  152. <button
  153. class=" w-full flex justify-between rounded-md px-4 py-3 hover:bg-gray-800 {chat.id ===
  154. selectedChatId
  155. ? 'bg-gray-800'
  156. : ''} transition whitespace-nowrap text-ellipsis"
  157. on:click={() => {
  158. if (chat.id !== chatTitleEditIdx) {
  159. chatTitleEditIdx = null;
  160. chatTitle = '';
  161. }
  162. loadChat(chat.id);
  163. }}
  164. >
  165. <div class=" flex self-center flex-1">
  166. <div class=" self-center mr-3">
  167. <svg
  168. xmlns="http://www.w3.org/2000/svg"
  169. fill="none"
  170. viewBox="0 0 24 24"
  171. stroke-width="1.5"
  172. stroke="currentColor"
  173. class="w-4 h-4"
  174. >
  175. <path
  176. stroke-linecap="round"
  177. stroke-linejoin="round"
  178. 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"
  179. />
  180. </svg>
  181. </div>
  182. <div
  183. class=" text-left self-center overflow-hidden {chat.id === selectedChatId
  184. ? 'w-[150px]'
  185. : 'w-[200px]'} "
  186. >
  187. {#if chatTitleEditIdx === chat.id}
  188. <input bind:value={chatTitle} class=" bg-transparent w-full" />
  189. {:else}
  190. {chat.title}
  191. {/if}
  192. </div>
  193. </div>
  194. </button>
  195. {#if chat.id === selectedChatId}
  196. <div class=" absolute right-[22px] top-[14px]">
  197. {#if chatTitleEditIdx === chat.id}
  198. <div class="flex self-center space-x-1.5">
  199. <button
  200. class=" self-center hover:text-white transition"
  201. on:click={() => {
  202. editChatTitle(chat.id, chatTitle);
  203. chatTitleEditIdx = null;
  204. chatTitle = '';
  205. }}
  206. >
  207. <svg
  208. xmlns="http://www.w3.org/2000/svg"
  209. viewBox="0 0 20 20"
  210. fill="currentColor"
  211. class="w-4 h-4"
  212. >
  213. <path
  214. fill-rule="evenodd"
  215. 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"
  216. clip-rule="evenodd"
  217. />
  218. </svg>
  219. </button>
  220. <button
  221. class=" self-center hover:text-white transition"
  222. on:click={() => {
  223. chatTitleEditIdx = null;
  224. chatTitle = '';
  225. }}
  226. >
  227. <svg
  228. xmlns="http://www.w3.org/2000/svg"
  229. viewBox="0 0 20 20"
  230. fill="currentColor"
  231. class="w-4 h-4"
  232. >
  233. <path
  234. 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"
  235. />
  236. </svg>
  237. </button>
  238. </div>
  239. {:else}
  240. <div class="flex self-center space-x-1.5">
  241. <button
  242. class=" self-center hover:text-white transition"
  243. on:click={() => {
  244. chatTitle = chat.title;
  245. chatTitleEditIdx = chat.id;
  246. // editChatTitle(chat.id, 'a');
  247. }}
  248. >
  249. <svg
  250. xmlns="http://www.w3.org/2000/svg"
  251. fill="none"
  252. viewBox="0 0 24 24"
  253. stroke-width="1.5"
  254. stroke="currentColor"
  255. class="w-4 h-4"
  256. >
  257. <path
  258. stroke-linecap="round"
  259. stroke-linejoin="round"
  260. 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"
  261. />
  262. </svg>
  263. </button>
  264. <button
  265. class=" self-center hover:text-white transition"
  266. on:click={() => {
  267. deleteChat(chat.id);
  268. }}
  269. >
  270. <svg
  271. xmlns="http://www.w3.org/2000/svg"
  272. fill="none"
  273. viewBox="0 0 24 24"
  274. stroke-width="1.5"
  275. stroke="currentColor"
  276. class="w-4 h-4"
  277. >
  278. <path
  279. stroke-linecap="round"
  280. stroke-linejoin="round"
  281. 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"
  282. />
  283. </svg>
  284. </button>
  285. </div>
  286. {/if}
  287. </div>
  288. {/if}
  289. </div>
  290. {/each}
  291. </div>
  292. <div class="px-2.5">
  293. <hr class=" border-gray-800 mb-2 w-full" />
  294. <div class="flex flex-col">
  295. <div class="flex">
  296. <input bind:this={importFileInputElement} bind:files={importFiles} type="file" hidden />
  297. <button
  298. class=" flex rounded-md p-3.5 w-full hover:bg-gray-800 transition"
  299. on:click={() => {
  300. importFileInputElement.click();
  301. // importChatHistory();
  302. }}
  303. >
  304. <div class=" self-center mr-3">
  305. <svg
  306. xmlns="http://www.w3.org/2000/svg"
  307. fill="none"
  308. viewBox="0 0 24 24"
  309. stroke-width="1.5"
  310. stroke="currentColor"
  311. class="w-5 h-5"
  312. >
  313. <path
  314. stroke-linecap="round"
  315. stroke-linejoin="round"
  316. 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"
  317. />
  318. </svg>
  319. </div>
  320. <div class=" self-center">Import</div>
  321. </button>
  322. <button
  323. class=" flex rounded-md p-3.5 w-full hover:bg-gray-800 transition"
  324. on:click={() => {
  325. exportChatHistory();
  326. }}
  327. >
  328. <div class=" self-center mr-3">
  329. <svg
  330. xmlns="http://www.w3.org/2000/svg"
  331. fill="none"
  332. viewBox="0 0 24 24"
  333. stroke-width="1.5"
  334. stroke="currentColor"
  335. class="w-5 h-5"
  336. >
  337. <path
  338. stroke-linecap="round"
  339. stroke-linejoin="round"
  340. 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"
  341. />
  342. </svg>
  343. </div>
  344. <div class=" self-center">Export</div>
  345. </button>
  346. </div>
  347. <button
  348. class=" flex rounded-md p-3.5 w-full hover:bg-gray-800 transition"
  349. on:click={() => {
  350. deleteChatHistory();
  351. }}
  352. >
  353. <div class=" self-center mr-3">
  354. <svg
  355. xmlns="http://www.w3.org/2000/svg"
  356. fill="none"
  357. viewBox="0 0 24 24"
  358. stroke-width="1.5"
  359. stroke="currentColor"
  360. class="w-5 h-5"
  361. >
  362. <path
  363. stroke-linecap="round"
  364. stroke-linejoin="round"
  365. 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"
  366. />
  367. </svg>
  368. </div>
  369. <div class=" self-center">Clear conversations</div>
  370. </button>
  371. <button
  372. class=" flex rounded-md p-3.5 w-full hover:bg-gray-800 transition"
  373. on:click={() => {
  374. openSettings();
  375. }}
  376. >
  377. <div class=" self-center mr-3">
  378. <svg
  379. xmlns="http://www.w3.org/2000/svg"
  380. fill="none"
  381. viewBox="0 0 24 24"
  382. stroke-width="1.5"
  383. stroke="currentColor"
  384. class="w-5 h-5"
  385. >
  386. <path
  387. stroke-linecap="round"
  388. stroke-linejoin="round"
  389. 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"
  390. />
  391. <path
  392. stroke-linecap="round"
  393. stroke-linejoin="round"
  394. d="M15 12a3 3 0 11-6 0 3 3 0 016 0z"
  395. />
  396. </svg>
  397. </div>
  398. <div class=" self-center font-medium">Settings</div>
  399. </button>
  400. </div>
  401. </div>
  402. </div>
  403. </div>