open-webui/src/lib/components/chat/ChatControls.svelte

130 lines
3.0 KiB
Svelte
Raw Normal View History

2024-07-08 23:55:12 +00:00
<script lang="ts">
2024-09-17 20:05:19 +00:00
import { SvelteFlowProvider } from '@xyflow/svelte';
2024-07-08 23:55:12 +00:00
import { slide } from 'svelte/transition';
2024-09-17 20:05:19 +00:00
import { onMount } from 'svelte';
import { mobile, showControls, showCallOverlay, showOverview } from '$lib/stores';
2024-07-08 23:55:12 +00:00
import Modal from '../common/Modal.svelte';
import Controls from './Controls/Controls.svelte';
2024-08-23 14:42:36 +00:00
import CallOverlay from './MessageInput/CallOverlay.svelte';
2024-09-05 15:23:59 +00:00
import Drawer from '../common/Drawer.svelte';
2024-09-17 20:05:19 +00:00
import Overview from './Overview.svelte';
2024-07-08 23:55:12 +00:00
2024-09-17 20:05:19 +00:00
export let history;
2024-07-12 00:18:18 +00:00
export let models = [];
2024-07-09 02:26:31 +00:00
export let chatId = null;
2024-07-17 09:39:37 +00:00
export let chatFiles = [];
2024-07-09 02:26:31 +00:00
export let params = {};
2024-07-08 23:55:12 +00:00
2024-08-23 14:42:36 +00:00
export let eventTarget: EventTarget;
export let submitPrompt: Function;
export let stopResponse: Function;
export let files;
export let modelId;
2024-07-09 02:26:31 +00:00
let largeScreen = false;
2024-07-08 23:55:12 +00:00
onMount(() => {
// listen to resize 1024px
const mediaQuery = window.matchMedia('(min-width: 1024px)');
const handleMediaQuery = (e) => {
if (e.matches) {
largeScreen = true;
} else {
largeScreen = false;
}
};
mediaQuery.addEventListener('change', handleMediaQuery);
handleMediaQuery(mediaQuery);
return () => {
mediaQuery.removeEventListener('change', handleMediaQuery);
};
});
</script>
2024-09-17 20:05:19 +00:00
<SvelteFlowProvider>
{#if !largeScreen}
{#if $showCallOverlay}
<div class=" absolute w-full h-screen max-h-[100dvh] flex z-[999] overflow-hidden">
<div
class="absolute w-full h-screen max-h-[100dvh] bg-white text-gray-700 dark:bg-black dark:text-gray-300 flex justify-center"
>
<CallOverlay
bind:files
{submitPrompt}
{stopResponse}
{modelId}
{chatId}
{eventTarget}
on:close={() => {
2024-09-17 20:05:19 +00:00
showControls.set(false);
}}
/>
2024-09-17 20:05:19 +00:00
</div>
</div>
{:else if $showControls}
<Drawer
on:close={() => {
showControls.set(false);
}}
>
<div class=" px-6 py-4 h-full">
2024-09-05 17:11:27 +00:00
<Controls
on:close={() => {
2024-09-17 20:05:19 +00:00
showControls.set(false);
2024-09-05 17:11:27 +00:00
}}
{models}
bind:chatFiles
bind:params
/>
2024-09-17 20:05:19 +00:00
</div>
</Drawer>
{/if}
{:else if $showControls}
<div class=" absolute bottom-0 right-0 z-20 h-full pointer-events-none">
<div class="pr-4 pt-14 pb-8 w-[24rem] h-full" in:slide={{ duration: 200, axis: 'x' }}>
<div
class="w-full h-full {$showOverview
? ' '
: 'px-5 py-4 bg-white dark:shadow-lg dark:bg-gray-850 border border-gray-50 dark:border-gray-800'} rounded-lg z-50 pointer-events-auto overflow-y-auto scrollbar-hidden"
>
{#if $showCallOverlay}
<CallOverlay
bind:files
{submitPrompt}
{stopResponse}
{modelId}
{chatId}
{eventTarget}
on:close={() => {
showControls.set(false);
}}
/>
{:else if $showOverview}
<Overview
bind:history
on:close={() => {
showControls.set(false);
}}
/>
{:else}
<Controls
on:close={() => {
showControls.set(false);
}}
{models}
bind:chatFiles
bind:params
/>
{/if}
</div>
2024-09-05 17:11:27 +00:00
</div>
2024-07-08 23:55:12 +00:00
</div>
2024-09-17 20:05:19 +00:00
{/if}
</SvelteFlowProvider>