From 632406ceffc045b3969fcd903e5d65cd7167faff Mon Sep 17 00:00:00 2001 From: gsovereignty Date: Fri, 19 Apr 2024 11:17:13 +1200 Subject: [PATCH] problem: scroll position is all over the place --- src/lib/views/messages/Messages.svelte | 112 +++++++++--------- src/lib/views/messages/RenderKind1.svelte | 23 +++- .../messages/RenderKind1AsThreadHead.svelte | 87 ++++++++------ 3 files changed, 125 insertions(+), 97 deletions(-) diff --git a/src/lib/views/messages/Messages.svelte b/src/lib/views/messages/Messages.svelte index fdfa125..80ec3dc 100644 --- a/src/lib/views/messages/Messages.svelte +++ b/src/lib/views/messages/Messages.svelte @@ -12,8 +12,7 @@ //take current threadparentID (or root) and create a derived store of all events. derive antoher one to pipe it through sorting/filtering store. // -//export let FrontendDataStore: Writable - + //export let FrontendDataStore: Writable let threadParentIDChain = writable(['root']); @@ -54,49 +53,50 @@ threadParentID.subscribe(() => { _stableShortlist = []; - stableShortList.set(_stableShortlist) + stableShortList.set(_stableShortlist); }); - - renderQueue.subscribe((q) => {}); //remove viewed and add new items that haven't been viewed - let shortListLength = derived([renderQueue, viewed, threadParentID], ([$renderQ, $viewed, $parentID]) => { - let dirty = false; - let updated: NostrEvent[] = []; - for (let e of _stableShortlist) { - if (!$viewed.has(e.id) || $parentID != "root") { - //console.log(72, e.id); - updated.push(e); - } else { - dirty = true; + let shortListLength = derived( + [renderQueue, viewed, threadParentID], + ([$renderQ, $viewed, $parentID]) => { + let dirty = false; + let updated: NostrEvent[] = []; + for (let e of _stableShortlist) { + if (!$viewed.has(e.id) || $parentID != 'root') { + //console.log(72, e.id); + updated.push(e); + } else { + dirty = true; + } } - } - let needed = 6 - updated.length; - if (needed > 0) { - let pushed = 0; - for (let e of $renderQ) { - if (needed > pushed) { - if (!$viewed.has(e.id) && !arrayContainsEvent(updated, e.id)) { - pushed++; - updated.push(e); - //console.log(84, pushed); - dirty = true; + let needed = 6 - updated.length; + if (needed > 0) { + let pushed = 0; + for (let e of $renderQ) { + if (needed > pushed) { + if (!$viewed.has(e.id) && !arrayContainsEvent(updated, e.id)) { + pushed++; + updated.push(e); + //console.log(84, pushed); + dirty = true; + } } } } + if (dirty) { + _stableShortlist = updated; + stableShortList.update((c) => { + c = updated; + return c; + }); + //console.log(90); + } + return _stableShortlist.length; } - if (dirty) { - _stableShortlist = updated; - stableShortList.update((c) => { - c = updated; - return c; - }); - //console.log(90); - } - return _stableShortlist.length; - }); + ); function arrayContainsEvent(a: NostrEvent[], id: string): boolean { let inSet = new Set(); @@ -117,26 +117,30 @@ {/if} - {#if $stableShortList.length > 0 || $threadParentID != "root"} - {#if $threadParentID != "root"} - - {/if} - {#each $stableShortList as event, i (event.id)} 0 || $threadParentID != 'root'} + {#if $threadParentID != 'root'} + { - if ($threadParentID == "root") { - viewed.update((v) => { - v.add(event.id); - return v; - }); - } - threadParentIDChain.update((exising) => { - exising.push(event.id); - return exising; - }); - }} - />{/each} + note={$FrontendDataStore.rawEvents.get($threadParentID)} + /> + {/if} + {#each $stableShortList as event, i (event.id)} { + if ($threadParentID == 'root') { + viewed.update((v) => { + v.add(event.id); + return v; + }); + } + threadParentIDChain.update((exising) => { + exising.push(event.id); + return exising; + }); + }} + /> + {/each} {:else} {/if} diff --git a/src/lib/views/messages/RenderKind1.svelte b/src/lib/views/messages/RenderKind1.svelte index fc59297..0301b4d 100644 --- a/src/lib/views/messages/RenderKind1.svelte +++ b/src/lib/views/messages/RenderKind1.svelte @@ -8,15 +8,29 @@ import type { FrontendData } from '@/snort_workers/types'; import { inview } from 'svelte-inview'; import { viewed } from '@/workers_snort/firehose_master'; + import { onMount } from 'svelte'; export let note: NostrEvent; export let onClickReply: () => void; export let store: Writable; + export let isTop: boolean = false; + + let top: HTMLDivElement; + +onMount(() => { + if (isTop) { + (async () => { + top.scrollIntoView() + //top.scrollIntoView() + })(); + } +}); + $: childrenCount = $store?.replies.get(note.id) ? $store.replies.get(note.id)!.size : 0; -
+
-
- -
+
- {new Date(note.created_at * 1000).toLocaleString()} {#if $viewed.has(note.id)}✓{/if} + {new Date(note.created_at * 1000).toLocaleString()} + {#if $viewed.has(note.id)}✓{/if}
diff --git a/src/lib/views/messages/RenderKind1AsThreadHead.svelte b/src/lib/views/messages/RenderKind1AsThreadHead.svelte index 6928019..ded0221 100644 --- a/src/lib/views/messages/RenderKind1AsThreadHead.svelte +++ b/src/lib/views/messages/RenderKind1AsThreadHead.svelte @@ -1,43 +1,54 @@ -
-
-
- profile pic -
-
Marcus
-
-
-
- -
-
-
-
- {new Date(note.created_at * 1000).toLocaleString()}{#if $viewed.has(note.id)}✓{/if} -
-
-
-
-
-
-
\ No newline at end of file + +
+
+
+ profile pic +
+
Marcus
+
+
+
+ +
+
+
+
+ {new Date(note.created_at * 1000).toLocaleString()}{#if $viewed.has(note.id)}✓{/if} +
+
+
+
+
+
+