Navbar.svelte 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. <script lang="ts">
  2. import { getContext } from 'svelte';
  3. import { toast } from 'svelte-sonner';
  4. import {
  5. WEBUI_NAME,
  6. banners,
  7. chatId,
  8. config,
  9. mobile,
  10. settings,
  11. showArchivedChats,
  12. showControls,
  13. showSidebar,
  14. temporaryChatEnabled,
  15. user
  16. } from '$lib/stores';
  17. import { slide } from 'svelte/transition';
  18. import { page } from '$app/stores';
  19. import ShareChatModal from '../chat/ShareChatModal.svelte';
  20. import ModelSelector from '../chat/ModelSelector.svelte';
  21. import Tooltip from '../common/Tooltip.svelte';
  22. import Menu from '$lib/components/layout/Navbar/Menu.svelte';
  23. import UserMenu from '$lib/components/layout/Sidebar/UserMenu.svelte';
  24. import MenuLines from '../icons/MenuLines.svelte';
  25. import AdjustmentsHorizontal from '../icons/AdjustmentsHorizontal.svelte';
  26. import PencilSquare from '../icons/PencilSquare.svelte';
  27. import Banner from '../common/Banner.svelte';
  28. const i18n = getContext('i18n');
  29. export let initNewChat: Function;
  30. export let title: string = $WEBUI_NAME;
  31. export let shareEnabled: boolean = false;
  32. export let chat;
  33. export let history;
  34. export let selectedModels;
  35. export let showModelSelector = true;
  36. let showShareChatModal = false;
  37. let showDownloadChatModal = false;
  38. </script>
  39. <ShareChatModal bind:show={showShareChatModal} chatId={$chatId} />
  40. <nav class="sticky top-0 z-30 w-full py-1.5 -mb-8 flex flex-col items-center drag-region">
  41. <div class="flex items-center w-full px-1.5">
  42. <div
  43. class=" bg-linear-to-b via-50% from-white via-white to-transparent dark:from-gray-900 dark:via-gray-900 dark:to-transparent pointer-events-none absolute inset-0 -bottom-7 z-[-1]"
  44. ></div>
  45. <div class=" flex max-w-full w-full mx-auto px-1 pt-0.5 bg-transparent">
  46. <div class="flex items-center w-full max-w-full">
  47. <div
  48. class="{$showSidebar
  49. ? 'md:hidden'
  50. : ''} mr-1 self-start flex flex-none items-center text-gray-600 dark:text-gray-400"
  51. >
  52. <button
  53. id="sidebar-toggle-button"
  54. class="cursor-pointer px-2 py-2 flex rounded-xl hover:bg-gray-50 dark:hover:bg-gray-850 transition"
  55. on:click={() => {
  56. showSidebar.set(!$showSidebar);
  57. }}
  58. aria-label="Toggle Sidebar"
  59. >
  60. <div class=" m-auto self-center">
  61. <MenuLines />
  62. </div>
  63. </button>
  64. </div>
  65. <div
  66. class="flex-1 overflow-hidden max-w-full py-0.5
  67. {$showSidebar ? 'ml-1' : ''}
  68. "
  69. >
  70. {#if showModelSelector}
  71. <ModelSelector bind:selectedModels showSetDefault={!shareEnabled} />
  72. {/if}
  73. </div>
  74. <div class="self-start flex flex-none items-center text-gray-600 dark:text-gray-400">
  75. <!-- <div class="md:hidden flex self-center w-[1px] h-5 mx-2 bg-gray-300 dark:bg-stone-700" /> -->
  76. {#if shareEnabled && chat && (chat.id || $temporaryChatEnabled)}
  77. <Menu
  78. {chat}
  79. {shareEnabled}
  80. shareHandler={() => {
  81. showShareChatModal = !showShareChatModal;
  82. }}
  83. downloadHandler={() => {
  84. showDownloadChatModal = !showDownloadChatModal;
  85. }}
  86. >
  87. <button
  88. class="flex cursor-pointer px-2 py-2 rounded-xl hover:bg-gray-50 dark:hover:bg-gray-850 transition"
  89. id="chat-context-menu-button"
  90. >
  91. <div class=" m-auto self-center">
  92. <svg
  93. xmlns="http://www.w3.org/2000/svg"
  94. fill="none"
  95. viewBox="0 0 24 24"
  96. stroke-width="1.5"
  97. stroke="currentColor"
  98. class="size-5"
  99. >
  100. <path
  101. stroke-linecap="round"
  102. stroke-linejoin="round"
  103. d="M6.75 12a.75.75 0 1 1-1.5 0 .75.75 0 0 1 1.5 0ZM12.75 12a.75.75 0 1 1-1.5 0 .75.75 0 0 1 1.5 0ZM18.75 12a.75.75 0 1 1-1.5 0 .75.75 0 0 1 1.5 0Z"
  104. />
  105. </svg>
  106. </div>
  107. </button>
  108. </Menu>
  109. {/if}
  110. <Tooltip content={$i18n.t('Controls')}>
  111. <button
  112. class=" flex cursor-pointer px-2 py-2 rounded-xl hover:bg-gray-50 dark:hover:bg-gray-850 transition"
  113. on:click={async () => {
  114. await showControls.set(!$showControls);
  115. }}
  116. aria-label="Controls"
  117. >
  118. <div class=" m-auto self-center">
  119. <AdjustmentsHorizontal className=" size-5" strokeWidth="0.5" />
  120. </div>
  121. </button>
  122. </Tooltip>
  123. <Tooltip content={$i18n.t('New Chat')}>
  124. <button
  125. id="new-chat-button"
  126. class=" flex {$showSidebar
  127. ? 'md:hidden'
  128. : ''} cursor-pointer px-2 py-2 rounded-xl text-gray-600 dark:text-gray-400 hover:bg-gray-50 dark:hover:bg-gray-850 transition"
  129. on:click={() => {
  130. initNewChat();
  131. }}
  132. aria-label="New Chat"
  133. >
  134. <div class=" m-auto self-center">
  135. <PencilSquare className=" size-5" strokeWidth="2" />
  136. </div>
  137. </button>
  138. </Tooltip>
  139. {#if $user !== undefined && $user !== null}
  140. <UserMenu
  141. className="max-w-[200px]"
  142. role={$user?.role}
  143. on:show={(e) => {
  144. if (e.detail === 'archived-chat') {
  145. showArchivedChats.set(true);
  146. }
  147. }}
  148. >
  149. <button
  150. class="select-none flex rounded-xl p-1.5 w-full hover:bg-gray-50 dark:hover:bg-gray-850 transition"
  151. aria-label="User Menu"
  152. >
  153. <div class=" self-center">
  154. <img
  155. src={$user?.profile_image_url}
  156. class="size-6 object-cover rounded-full"
  157. alt="User profile"
  158. draggable="false"
  159. />
  160. </div>
  161. </button>
  162. </UserMenu>
  163. {/if}
  164. </div>
  165. </div>
  166. </div>
  167. </div>
  168. {#if !history.currentId && !$chatId && ($banners.length > 0 || ($config?.license_metadata?.type ?? null) === 'trial' || (($config?.license_metadata?.seats ?? null) !== null && $config?.user_count > $config?.license_metadata?.seats))}
  169. <div class=" w-full z-30 mt-5">
  170. <div class=" flex flex-col gap-1 w-full">
  171. {#if ($config?.license_metadata?.type ?? null) === 'trial'}
  172. <Banner
  173. banner={{
  174. type: 'info',
  175. title: 'Trial License',
  176. content: $i18n.t(
  177. 'You are currently using a trial license. Please contact support to upgrade your license.'
  178. )
  179. }}
  180. />
  181. {/if}
  182. {#if ($config?.license_metadata?.seats ?? null) !== null && $config?.user_count > $config?.license_metadata?.seats}
  183. <Banner
  184. banner={{
  185. type: 'error',
  186. title: 'License Error',
  187. content: $i18n.t(
  188. 'Exceeded the number of seats in your license. Please contact support to increase the number of seats.'
  189. )
  190. }}
  191. />
  192. {/if}
  193. {#each $banners.filter( (b) => (b.dismissible ? !JSON.parse(localStorage.getItem('dismissedBannerIds') ?? '[]').includes(b.id) : true) ) as banner}
  194. <Banner
  195. {banner}
  196. on:dismiss={(e) => {
  197. const bannerId = e.detail;
  198. localStorage.setItem(
  199. 'dismissedBannerIds',
  200. JSON.stringify(
  201. [
  202. bannerId,
  203. ...JSON.parse(localStorage.getItem('dismissedBannerIds') ?? '[]')
  204. ].filter((id) => $banners.find((b) => b.id === id))
  205. )
  206. );
  207. }}
  208. />
  209. {/each}
  210. </div>
  211. </div>
  212. {/if}
  213. </nav>