refac: click to focus on mesage node

This commit is contained in:
Timothy J. Baek 2024-09-20 15:43:18 +02:00
parent c89bb01db9
commit 732f730213

View File

@ -23,6 +23,8 @@
export let history; export let history;
let selectedMessageId = null;
const nodes = writable([]); const nodes = writable([]);
const edges = writable([]); const edges = writable([]);
@ -34,10 +36,17 @@
drawFlow(); drawFlow();
} }
$: if (history?.currentId) { $: if (history && history.currentId) {
fitView({ nodes: [{ id: history.currentId }] }); focusNode();
selectedMessageId = null;
} }
const focusNode = async () => {
if (selectedMessageId === null) {
await fitView({ nodes: [{ id: history.currentId }] });
}
};
const drawFlow = async () => { const drawFlow = async () => {
const nodeList = []; const nodeList = [];
const edgeList = []; const edgeList = [];
@ -168,6 +177,8 @@
on:nodeclick={(e) => { on:nodeclick={(e) => {
console.log(e.detail.node.data); console.log(e.detail.node.data);
dispatch('nodeclick', e.detail); dispatch('nodeclick', e.detail);
selectedMessageId = e.detail.node.data.message.id;
fitView({ nodes: [{ id: selectedMessageId }] });
}} }}
/> />
{/if} {/if}