open-webui/src/lib/components/layout/Navbar.svelte

182 lines
5.2 KiB
Svelte
Raw Normal View History

2023-10-08 22:38:42 +00:00
<script lang="ts">
import { getContext } from 'svelte';
2024-03-01 09:18:07 +00:00
import { toast } from 'svelte-sonner';
2024-01-01 07:13:17 +00:00
2024-05-15 00:50:24 +00:00
import {
WEBUI_NAME,
chatId,
mobile,
settings,
2024-05-15 08:22:15 +00:00
showArchivedChats,
2024-09-17 20:05:19 +00:00
showControls,
2024-05-15 00:50:24 +00:00
showSidebar,
2024-10-07 21:28:28 +00:00
temporaryChatEnabled,
2024-05-15 00:50:24 +00:00
user
} from '$lib/stores';
2024-03-30 00:20:07 +00:00
import { slide } from 'svelte/transition';
2024-01-18 05:01:30 +00:00
import ShareChatModal from '../chat/ShareChatModal.svelte';
2024-03-30 00:20:07 +00:00
import ModelSelector from '../chat/ModelSelector.svelte';
import Tooltip from '../common/Tooltip.svelte';
import Menu from './Navbar/Menu.svelte';
import { page } from '$app/stores';
2024-05-15 00:50:24 +00:00
import UserMenu from './Sidebar/UserMenu.svelte';
2024-05-15 06:16:22 +00:00
import MenuLines from '../icons/MenuLines.svelte';
2024-07-08 23:55:12 +00:00
import AdjustmentsHorizontal from '../icons/AdjustmentsHorizontal.svelte';
2024-09-17 20:05:19 +00:00
import Map from '../icons/Map.svelte';
2024-10-07 21:28:28 +00:00
import { stringify } from 'postcss';
2024-11-05 03:52:12 +00:00
import PencilSquare from '../icons/PencilSquare.svelte';
2024-11-07 09:30:51 +00:00
import Plus from '../icons/Plus.svelte';
2023-10-19 05:57:55 +00:00
const i18n = getContext('i18n');
2023-12-26 11:28:30 +00:00
export let initNewChat: Function;
2024-02-24 01:12:19 +00:00
export let title: string = $WEBUI_NAME;
2023-12-14 09:05:38 +00:00
export let shareEnabled: boolean = false;
2023-12-15 00:50:54 +00:00
2024-04-04 02:30:25 +00:00
export let chat;
2024-03-30 00:20:07 +00:00
export let selectedModels;
export let showModelSelector = true;
2024-01-18 06:49:58 +00:00
2024-03-30 00:20:07 +00:00
let showShareChatModal = false;
2024-04-04 02:30:25 +00:00
let showDownloadChatModal = false;
2023-10-08 22:38:42 +00:00
</script>
2024-04-20 19:40:06 +00:00
<ShareChatModal bind:show={showShareChatModal} chatId={$chatId} />
2024-10-05 21:26:54 +00:00
2024-11-07 09:30:51 +00:00
<div class="sticky top-0 z-30 w-full px-1.5 py-1.5 -mb-8 flex items-center">
2024-10-05 21:26:54 +00:00
<div
class=" bg-gradient-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] blur"
></div>
2024-11-07 09:30:51 +00:00
<div class=" flex max-w-full w-full mx-auto px-1 pt-0.5 bg-transparent">
2024-03-30 00:20:07 +00:00
<div class="flex items-center w-full max-w-full">
2024-05-15 06:21:22 +00:00
<div
class="{$showSidebar
? 'md:hidden'
2024-11-07 09:30:51 +00:00
: ''} mr-1 self-start flex flex-none items-center text-gray-600 dark:text-gray-400"
2024-05-15 06:21:22 +00:00
>
2024-05-14 22:09:30 +00:00
<button
2024-05-14 22:17:56 +00:00
id="sidebar-toggle-button"
2024-07-09 03:17:09 +00:00
class="cursor-pointer px-2 py-2 flex rounded-xl hover:bg-gray-50 dark:hover:bg-gray-850 transition"
2024-05-14 22:09:30 +00:00
on:click={() => {
showSidebar.set(!$showSidebar);
}}
aria-label="Toggle Sidebar"
2024-05-14 22:09:30 +00:00
>
<div class=" m-auto self-center">
2024-05-15 06:16:22 +00:00
<MenuLines />
2024-05-14 22:09:30 +00:00
</div>
</button>
</div>
2024-07-08 23:55:12 +00:00
2024-11-07 09:30:51 +00:00
<div
class="flex-1 overflow-hidden max-w-full py-0.5
{$showSidebar ? 'ml-1' : ''}
"
>
{#if showModelSelector}
<ModelSelector bind:selectedModels showSetDefault={!shareEnabled} />
{/if}
2024-03-30 00:20:07 +00:00
</div>
2024-01-18 05:01:30 +00:00
2024-05-15 06:21:22 +00:00
<div class="self-start flex flex-none items-center text-gray-600 dark:text-gray-400">
2024-05-14 22:09:30 +00:00
<!-- <div class="md:hidden flex self-center w-[1px] h-5 mx-2 bg-gray-300 dark:bg-stone-700" /> -->
2024-10-07 21:28:28 +00:00
{#if shareEnabled && chat && (chat.id || $temporaryChatEnabled)}
2024-03-30 00:20:07 +00:00
<Menu
2024-04-04 02:30:25 +00:00
{chat}
2024-03-30 00:20:07 +00:00
{shareEnabled}
shareHandler={() => {
showShareChatModal = !showShareChatModal;
}}
2024-04-04 02:30:25 +00:00
downloadHandler={() => {
showDownloadChatModal = !showDownloadChatModal;
}}
2024-03-30 00:20:07 +00:00
>
<button
2024-09-17 23:30:09 +00:00
class="flex cursor-pointer px-2 py-2 rounded-xl hover:bg-gray-50 dark:hover:bg-gray-850 transition"
id="chat-context-menu-button"
2024-05-17 04:21:19 +00:00
>
2024-03-30 00:20:07 +00:00
<div class=" m-auto self-center">
<svg
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
stroke-width="1.5"
stroke="currentColor"
class="size-5"
>
<path
stroke-linecap="round"
stroke-linejoin="round"
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"
/>
</svg>
</div>
</button>
</Menu>
{/if}
2024-07-08 23:55:12 +00:00
2024-09-17 23:30:09 +00:00
{#if !$mobile}
<Tooltip content={$i18n.t('Controls')}>
<button
class=" flex cursor-pointer px-2 py-2 rounded-xl hover:bg-gray-50 dark:hover:bg-gray-850 transition"
2024-09-21 01:33:06 +00:00
on:click={async () => {
await showControls.set(!$showControls);
2024-09-17 23:30:09 +00:00
}}
aria-label="Controls"
>
<div class=" m-auto self-center">
<AdjustmentsHorizontal className=" size-5" strokeWidth="0.5" />
</div>
</button>
</Tooltip>
{/if}
2024-07-08 23:55:12 +00:00
<Tooltip content={$i18n.t('New Chat')}>
2024-03-30 00:20:07 +00:00
<button
id="new-chat-button"
2024-05-14 22:11:57 +00:00
class=" flex {$showSidebar
? 'md:hidden'
2024-07-09 03:17:09 +00:00
: ''} 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"
2024-03-30 00:20:07 +00:00
on:click={() => {
initNewChat();
2023-12-14 09:05:38 +00:00
}}
aria-label="New Chat"
2023-10-08 22:38:42 +00:00
>
2023-12-14 09:05:38 +00:00
<div class=" m-auto self-center">
2024-11-05 03:52:12 +00:00
<PencilSquare className=" size-5" strokeWidth="2" />
2023-12-14 09:05:38 +00:00
</div>
</button>
2024-03-30 00:20:07 +00:00
</Tooltip>
2024-05-15 00:50:24 +00:00
2024-05-15 09:45:27 +00:00
{#if $user !== undefined}
2024-05-15 00:50:24 +00:00
<UserMenu
2024-05-15 09:45:27 +00:00
className="max-w-[200px]"
2024-05-15 00:50:24 +00:00
role={$user.role}
on:show={(e) => {
if (e.detail === 'archived-chat') {
2024-05-15 08:22:15 +00:00
showArchivedChats.set(true);
2024-05-15 00:50:24 +00:00
}
}}
>
<button
2024-07-09 03:17:09 +00:00
class="select-none flex rounded-xl p-1.5 w-full hover:bg-gray-50 dark:hover:bg-gray-850 transition"
aria-label="User Menu"
2024-05-15 00:50:24 +00:00
>
<div class=" self-center">
<img
src={$user.profile_image_url}
2024-05-18 21:04:35 +00:00
class="size-6 object-cover rounded-full"
2024-05-15 00:50:24 +00:00
alt="User profile"
2024-05-18 21:04:35 +00:00
draggable="false"
2024-05-15 00:50:24 +00:00
/>
</div>
</button>
</UserMenu>
{/if}
2024-01-18 05:01:30 +00:00
</div>
2023-12-14 09:05:38 +00:00
</div>
2023-10-08 22:38:42 +00:00
</div>
2024-10-05 21:26:54 +00:00
</div>