rf: dom queries in layout and pages

This commit is contained in:
Carlos Daniel Vilaseca 2024-03-03 17:42:01 -05:00
parent 50acdb09de
commit b986c2aefd
7 changed files with 32 additions and 32 deletions

View file

@ -37,7 +37,7 @@
let ollamaVersion = ''; let ollamaVersion = '';
let loaded = false; let loaded = false;
let showShortcutsButton:HTMLButtonElement
let DB = null; let DB = null;
let localDBChats = []; let localDBChats = [];
@ -184,7 +184,7 @@
if (isCtrlPressed && event.key === '/') { if (isCtrlPressed && event.key === '/') {
event.preventDefault(); event.preventDefault();
console.log('showShortcuts'); console.log('showShortcuts');
document.getElementById('show-shortcuts-button')?.click(); showShortcutsButton.click();
} }
}); });
@ -203,6 +203,7 @@
<div class=" hidden lg:flex fixed bottom-0 right-0 px-3 py-3 z-10"> <div class=" hidden lg:flex fixed bottom-0 right-0 px-3 py-3 z-10">
<button <button
id="show-shortcuts-button" id="show-shortcuts-button"
bind:this={showShortcutsButton}
class="text-gray-600 dark:text-gray-300 bg-gray-300/20 w-6 h-6 flex items-center justify-center text-xs rounded-full" class="text-gray-600 dark:text-gray-300 bg-gray-300/20 w-6 h-6 flex items-center justify-center text-xs rounded-full"
on:click={() => { on:click={() => {
showShortcuts = !showShortcuts; showShortcuts = !showShortcuts;

View file

@ -42,7 +42,7 @@
let stopResponseFlag = false; let stopResponseFlag = false;
let autoScroll = true; let autoScroll = true;
let processing = ''; let processing = '';
let messagesContainerElement: HTMLDivElement;
let currentRequestId = null; let currentRequestId = null;
let selectedModels = ['']; let selectedModels = [''];
@ -140,8 +140,7 @@
}; };
const scrollToBottom = () => { const scrollToBottom = () => {
const element = document.getElementById('messages-container'); messagesContainerElement.scrollTop = messagesContainerElement.scrollHeight;
element.scrollTop = element.scrollHeight;
}; };
////////////////////////// //////////////////////////
@ -821,8 +820,11 @@
<div <div
class=" pb-2.5 flex flex-col justify-between w-full flex-auto overflow-auto h-0" class=" pb-2.5 flex flex-col justify-between w-full flex-auto overflow-auto h-0"
id="messages-container" id="messages-container"
bind:this={messagesContainerElement}
on:scroll={(e) => { on:scroll={(e) => {
autoScroll = e.target.scrollHeight - e.target.scrollTop <= e.target.clientHeight + 50; autoScroll =
messagesContainerElement.scrollHeight - messagesContainerElement.scrollTop <=
messagesContainerElement.clientHeight + 50;
}} }}
> >
<div <div

View file

@ -45,7 +45,7 @@
let stopResponseFlag = false; let stopResponseFlag = false;
let autoScroll = true; let autoScroll = true;
let processing = ''; let processing = '';
let messagesContainerElement: HTMLDivElement;
let currentRequestId = null; let currentRequestId = null;
// let chatId = $page.params.id; // let chatId = $page.params.id;
@ -160,8 +160,7 @@
}; };
const scrollToBottom = () => { const scrollToBottom = () => {
const element = document.getElementById('messages-container'); messagesContainerElement.scrollTop = messagesContainerElement.scrollHeight;
element.scrollTop = element.scrollHeight;
}; };
////////////////////////// //////////////////////////
@ -852,8 +851,11 @@
<div <div
class=" pb-2.5 flex flex-col justify-between w-full flex-auto overflow-auto h-0" class=" pb-2.5 flex flex-col justify-between w-full flex-auto overflow-auto h-0"
id="messages-container" id="messages-container"
bind:this={messagesContainerElement}
on:scroll={(e) => { on:scroll={(e) => {
autoScroll = e.target.scrollHeight - e.target.scrollTop <= e.target.clientHeight + 50; autoScroll =
messagesContainerElement.scrollHeight - messagesContainerElement.scrollTop <=
messagesContainerElement.clientHeight + 50;
}} }}
> >
<div <div

View file

@ -21,7 +21,7 @@
let inputFiles = ''; let inputFiles = '';
let query = ''; let query = '';
let documentsImportInputElement: HTMLInputElement;
let tags = []; let tags = [];
let showSettingsModal = false; let showSettingsModal = false;
@ -524,6 +524,7 @@
<div class="flex space-x-2"> <div class="flex space-x-2">
<input <input
id="documents-import-input" id="documents-import-input"
bind:this={documentsImportInputElement}
bind:files={importFiles} bind:files={importFiles}
type="file" type="file"
accept=".json" accept=".json"
@ -558,9 +559,7 @@
<button <button
class="flex text-xs items-center space-x-1 px-3 py-1.5 rounded-xl bg-gray-50 hover:bg-gray-100 dark:bg-gray-800 dark:hover:bg-gray-700 dark:text-gray-200 transition" class="flex text-xs items-center space-x-1 px-3 py-1.5 rounded-xl bg-gray-50 hover:bg-gray-100 dark:bg-gray-800 dark:hover:bg-gray-700 dark:text-gray-200 transition"
on:click={async () => { on:click={documentsImportInputElement.click}
document.getElementById('documents-import-input')?.click();
}}
> >
<div class=" self-center mr-2 font-medium">Import Documents Mapping</div> <div class=" self-center mr-2 font-medium">Import Documents Mapping</div>

View file

@ -16,7 +16,7 @@
let localModelfiles = []; let localModelfiles = [];
let importFiles; let importFiles;
let modelfilesImportInputElement: HTMLInputElement;
const deleteModelHandler = async (tagName) => { const deleteModelHandler = async (tagName) => {
let success = null; let success = null;
@ -235,6 +235,7 @@
<div class="flex space-x-1"> <div class="flex space-x-1">
<input <input
id="modelfiles-import-input" id="modelfiles-import-input"
bind:this={modelfilesImportInputElement}
bind:files={importFiles} bind:files={importFiles}
type="file" type="file"
accept=".json" accept=".json"
@ -262,9 +263,7 @@
<button <button
class="flex text-xs items-center space-x-1 px-3 py-1.5 rounded-xl bg-gray-50 hover:bg-gray-100 dark:bg-gray-800 dark:hover:bg-gray-700 dark:text-gray-200 transition" class="flex text-xs items-center space-x-1 px-3 py-1.5 rounded-xl bg-gray-50 hover:bg-gray-100 dark:bg-gray-800 dark:hover:bg-gray-700 dark:text-gray-200 transition"
on:click={async () => { on:click={modelfilesImportInputElement.click}
document.getElementById('modelfiles-import-input')?.click();
}}
> >
<div class=" self-center mr-2 font-medium">Import Modelfiles</div> <div class=" self-center mr-2 font-medium">Import Modelfiles</div>

View file

@ -1,4 +1,4 @@
<script> <script lang="ts">
import { goto } from '$app/navigation'; import { goto } from '$app/navigation';
import { onMount, tick } from 'svelte'; import { onMount, tick } from 'svelte';
@ -21,7 +21,6 @@
let mode = 'chat'; let mode = 'chat';
let loaded = false; let loaded = false;
let text = ''; let text = '';
let selectedModelId = ''; let selectedModelId = '';
@ -30,6 +29,9 @@
let currentRequestId; let currentRequestId;
let stopResponseFlag = false; let stopResponseFlag = false;
let messagesContainerElement: HTMLDivElement;
let textCompletionAreaElement: HTMLTextAreaElement;
let system = ''; let system = '';
let messages = [ let messages = [
{ {
@ -39,13 +41,7 @@
]; ];
const scrollToBottom = () => { const scrollToBottom = () => {
let element; const element = mode === 'chat' ? messagesContainerElement : textCompletionAreaElement;
if (mode === 'chat') {
element = document.getElementById('messages-container');
} else {
element = document.getElementById('text-completion-textarea');
}
if (element) { if (element) {
element.scrollTop = element?.scrollHeight; element.scrollTop = element?.scrollHeight;
@ -417,12 +413,14 @@
<div <div
class=" pb-2.5 flex flex-col justify-between w-full flex-auto overflow-auto h-0" class=" pb-2.5 flex flex-col justify-between w-full flex-auto overflow-auto h-0"
id="messages-container" id="messages-container"
bind:this={messagesContainerElement}
> >
<div class=" h-full w-full flex flex-col"> <div class=" h-full w-full flex flex-col">
<div class="flex-1 p-1"> <div class="flex-1 p-1">
{#if mode === 'complete'} {#if mode === 'complete'}
<textarea <textarea
id="text-completion-textarea" id="text-completion-textarea"
bind:this={textCompletionAreaElement}
class="w-full h-full p-3 bg-transparent outline outline-1 outline-gray-200 dark:outline-gray-800 resize-none rounded-lg text-sm" class="w-full h-full p-3 bg-transparent outline outline-1 outline-gray-200 dark:outline-gray-800 resize-none rounded-lg text-sm"
bind:value={text} bind:value={text}
placeholder="You're a helpful assistant." placeholder="You're a helpful assistant."

View file

@ -11,7 +11,7 @@
let importFiles = ''; let importFiles = '';
let query = ''; let query = '';
let promptsImportInputElement: HTMLInputElement;
const sharePrompt = async (prompt) => { const sharePrompt = async (prompt) => {
toast.success('Redirecting you to OpenWebUI Community'); toast.success('Redirecting you to OpenWebUI Community');
@ -208,6 +208,7 @@
<div class="flex space-x-2"> <div class="flex space-x-2">
<input <input
id="prompts-import-input" id="prompts-import-input"
bind:this={promptsImportInputElement}
bind:files={importFiles} bind:files={importFiles}
type="file" type="file"
accept=".json" accept=".json"
@ -241,9 +242,7 @@
<button <button
class="flex text-xs items-center space-x-1 px-3 py-1.5 rounded-xl bg-gray-50 hover:bg-gray-100 dark:bg-gray-800 dark:hover:bg-gray-700 dark:text-gray-200 transition" class="flex text-xs items-center space-x-1 px-3 py-1.5 rounded-xl bg-gray-50 hover:bg-gray-100 dark:bg-gray-800 dark:hover:bg-gray-700 dark:text-gray-200 transition"
on:click={async () => { on:click={promptsImportInputElement.click}
document.getElementById('prompts-import-input')?.click();
}}
> >
<div class=" self-center mr-2 font-medium">Import Prompts</div> <div class=" self-center mr-2 font-medium">Import Prompts</div>
@ -266,7 +265,7 @@
<button <button
class="flex text-xs items-center space-x-1 px-3 py-1.5 rounded-xl bg-gray-50 hover:bg-gray-100 dark:bg-gray-800 dark:hover:bg-gray-700 dark:text-gray-200 transition" class="flex text-xs items-center space-x-1 px-3 py-1.5 rounded-xl bg-gray-50 hover:bg-gray-100 dark:bg-gray-800 dark:hover:bg-gray-700 dark:text-gray-200 transition"
on:click={async () => { on:click={async () => {
// document.getElementById('modelfiles-import-input')?.click(); // promptsImportInputElement.click();
let blob = new Blob([JSON.stringify($prompts)], { let blob = new Blob([JSON.stringify($prompts)], {
type: 'application/json' type: 'application/json'
}); });