enh: scroll to message from overview

This commit is contained in:
Timothy J. Baek 2024-09-18 03:13:37 +02:00
parent 8d92093570
commit 67f704c98d
5 changed files with 38 additions and 4 deletions

View File

@ -143,6 +143,28 @@
})(); })();
} }
const showMessage = async (message) => {
let _messageId = JSON.parse(JSON.stringify(message.id));
let messageChildrenIds = history.messages[_messageId].childrenIds;
while (messageChildrenIds.length !== 0) {
_messageId = messageChildrenIds.at(-1);
messageChildrenIds = history.messages[_messageId].childrenIds;
}
history.currentId = _messageId;
await tick();
await tick();
await tick();
const messageElement = document.getElementById(`message-${message.id}`);
if (messageElement) {
messageElement.scrollIntoView({ behavior: 'smooth', block: 'center' });
}
};
const chatEventHandler = async (event, cb) => { const chatEventHandler = async (event, cb) => {
if (event.chat_id === $chatId) { if (event.chat_id === $chatId) {
await tick(); await tick();
@ -1812,6 +1834,7 @@
bind:files bind:files
{submitPrompt} {submitPrompt}
{stopResponse} {stopResponse}
{showMessage}
modelId={selectedModelIds?.at(0) ?? null} modelId={selectedModelIds?.at(0) ?? null}
chatId={$chatId} chatId={$chatId}
{eventTarget} {eventTarget}

View File

@ -21,6 +21,7 @@
export let eventTarget: EventTarget; export let eventTarget: EventTarget;
export let submitPrompt: Function; export let submitPrompt: Function;
export let stopResponse: Function; export let stopResponse: Function;
export let showMessage: Function;
export let files; export let files;
export let modelId; export let modelId;
@ -126,6 +127,9 @@
{:else if $showOverview} {:else if $showOverview}
<Overview <Overview
bind:history bind:history
on:nodeclick={(e) => {
showMessage(e.detail.node.data.message);
}}
on:close={() => { on:close={() => {
showControls.set(false); showControls.set(false);
}} }}

View File

@ -337,7 +337,11 @@
<div class="w-full pt-2"> <div class="w-full pt-2">
{#key chatId} {#key chatId}
{#each messages as message, messageIdx (message.id)} {#each messages as message, messageIdx (message.id)}
<div class=" w-full {messageIdx === messages.length - 1 ? ' pb-12' : ''}"> <div
class=" w-full {messageIdx === messages.length - 1
? ' pb-12'
: ''} message-{message.id}"
>
<div <div
class="flex flex-col justify-between px-5 mb-3 {($settings?.widescreenMode ?? null) class="flex flex-col justify-between px-5 mb-3 {($settings?.widescreenMode ?? null)
? 'max-w-full' ? 'max-w-full'

View File

@ -1,7 +1,6 @@
<script lang="ts"> <script lang="ts">
import { getContext, createEventDispatcher } from 'svelte'; import { getContext, createEventDispatcher } from 'svelte';
import { useSvelteFlow, useNodesInitialized, useStore } from '@xyflow/svelte'; import { useSvelteFlow, useNodesInitialized, useStore } from '@xyflow/svelte';
import { SvelteFlow, Controls, Background, BackgroundVariant } from '@xyflow/svelte';
const dispatch = createEventDispatcher(); const dispatch = createEventDispatcher();
const i18n = getContext('i18n'); const i18n = getContext('i18n');
@ -148,6 +147,6 @@
</div> </div>
{#if $nodes.length > 0} {#if $nodes.length > 0}
<Flow {nodes} {nodeTypes} {edges} /> <Flow {nodes} {nodeTypes} {edges} on:nodeclick={(e) => dispatch('nodeclick', e.detail)} />
{/if} {/if}
</div> </div>

View File

@ -1,4 +1,8 @@
<script> <script>
import { createEventDispatcher } from 'svelte';
const dispatch = createEventDispatcher();
import { theme } from '$lib/stores'; import { theme } from '$lib/stores';
import { Background, Controls, SvelteFlow, BackgroundVariant } from '@xyflow/svelte'; import { Background, Controls, SvelteFlow, BackgroundVariant } from '@xyflow/svelte';
@ -22,7 +26,7 @@
: 'light'} : 'light'}
nodesConnectable={false} nodesConnectable={false}
nodesDraggable={false} nodesDraggable={false}
on:nodeclick={(event) => console.log('on node click', event.detail.node)} on:nodeclick={(e) => dispatch('nodeclick', e.detail)}
oninit={() => { oninit={() => {
console.log('Flow initialized'); console.log('Flow initialized');
}} }}