From 7015ed136c3aa90d85c0235d8e86b5121a8b7b14 Mon Sep 17 00:00:00 2001 From: Jonathan Staab Date: Wed, 30 Nov 2022 20:47:53 -0800 Subject: [PATCH] Add some loading icons --- package-lock.json | Bin 257394 -> 258034 bytes package.json | 1 + src/App.svelte | 18 +++++++++---- src/partials/Note.svelte | 5 +--- src/partials/NoteDetail.svelte | 47 +++++++++++++++++++-------------- src/routes/ChatRoom.svelte | 2 +- src/routes/Notes.svelte | 12 ++++++--- src/routes/UserDetail.svelte | 24 ++++++++++++++--- 8 files changed, 72 insertions(+), 37 deletions(-) diff --git a/package-lock.json b/package-lock.json index af9bf6220ab569e2472c59bc745891d93cc7942b..9af4fd01acea77c462cc2394f486bffcaf0242c7 100644 GIT binary patch delta 417 zcmex#i~rMo{ta$SQaSmFDVcfcy2S;Vd3mWt#Y$ERN^u5y#(E}`1+|2ypWV*P)f~XI zJ%EYv_-lSN#nU%RFi9~QPhJpXJbm9AMs^)E`C@%t{o=CJoRU;sbQxWP=?gL#)xyfW z6T{671AU#Hl0*D5vmD)%4RS+sEV7MV0?o`aBXbMPe4Q+ueBGTRD#NoajFLi%l6@*I z-2C%`b1lV`DAz9dj&Zx-JElD+sqgMk Snz(y<-!^86?Z6;kY6<`{kCWv9 delta 39 vcmex#pa0V>{ta$S(|va_b2Zm8ZLeiwJpQ`9 { // Keep scroll position on body, but don't allow scrolling if ($modal) { - scrollY = window.scrollY - document.body.style.top = `-${scrollY}px` - document.body.style.position = `fixed` + // This is not idempotent, so don't duplicate it + if (document.body.style.position !== 'fixed') { + scrollY = window.scrollY + + document.body.style.top = `-${scrollY}px` + document.body.style.position = `fixed` + } } else { document.body.style = '' window.scrollTo(0, scrollY) @@ -77,11 +81,15 @@ {#key params.room} - + {/key} - + + {#key params.pubkey} + + {/key} + diff --git a/src/partials/Note.svelte b/src/partials/Note.svelte index 9534ef81..c9aebb0c 100644 --- a/src/partials/Note.svelte +++ b/src/partials/Note.svelte @@ -37,11 +37,8 @@ } const showParent = async () => { - const notes = await annotateNotes( - await channels.getter.all({kinds: [1, 5, 7], ids: [parentId]}) - ) - modal.set({note: notes[0]}) + modal.set({note: {id: parentId}}) } const react = content => { diff --git a/src/partials/NoteDetail.svelte b/src/partials/NoteDetail.svelte index 5ff38b92..0675d731 100644 --- a/src/partials/NoteDetail.svelte +++ b/src/partials/NoteDetail.svelte @@ -1,20 +1,28 @@ -{#if note.pubkey} - -{#each note.replies as r (r.id)} -
- - {#each r.replies as r2 (r2.id)} +{#each $notes as note (note.id)} +
+ + {#each note.replies as r (r.id)}
- - {#each r2.replies as r3 (r3.id)} + + {#each r.replies as r2 (r2.id)}
- + + {#each r2.replies as r3 (r3.id)} +
+ +
+ {/each}
{/each}
{/each} -
+
+{:else} + {/each} -{/if} diff --git a/src/routes/ChatRoom.svelte b/src/routes/ChatRoom.svelte index 18c527dc..fa13d3e6 100644 --- a/src/routes/ChatRoom.svelte +++ b/src/routes/ChatRoom.svelte @@ -134,7 +134,7 @@
-
+
    {#each annotatedMessages as m (m.id)}
  • diff --git a/src/routes/Notes.svelte b/src/routes/Notes.svelte index d1122d50..d4eb0f34 100644 --- a/src/routes/Notes.svelte +++ b/src/routes/Notes.svelte @@ -5,6 +5,7 @@ import {navigate} from "svelte-routing" import {uniqBy, prop} from 'ramda' import Anchor from "src/partials/Anchor.svelte" + import Spinner from "src/partials/Spinner.svelte" import Note from "src/partials/Note.svelte" import {relays, Cursor} from "src/state/nostr" import {scroller, annotateNotes, notesListener, modal} from "src/state/app" @@ -31,7 +32,7 @@ scroll() // When a modal opens, suspend our subscriptions - modal.subscribe(async $modal => { + const modalUnsub = modal.subscribe(async $modal => { if ($modal) { cursor.stop() listener.stop() @@ -40,6 +41,10 @@ listener.start() } }) + + return () => { + modalUnsub() + } }) onDestroy(() => { @@ -61,11 +66,10 @@ {/each}
  • {/each} -
  • -

    Loading notes...

    -
+ + {#if $relays.length > 0}
diff --git a/src/routes/UserDetail.svelte b/src/routes/UserDetail.svelte index fcc12fed..909c90be 100644 --- a/src/routes/UserDetail.svelte +++ b/src/routes/UserDetail.svelte @@ -4,7 +4,8 @@ import {uniqBy, prop} from 'ramda' import {fly} from 'svelte/transition' import Note from "src/partials/Note.svelte" - import {Cursor} from 'src/state/nostr' + import Spinner from "src/partials/Spinner.svelte" + import {Cursor, epoch} from 'src/state/nostr' import {user as currentUser} from 'src/state/user' import {accounts, scroller, notesListener, modal, annotateNotes} from "src/state/app" @@ -15,12 +16,15 @@ let cursor let listener let scroll + let interval + let loading = true + let modalUnsub $: user = $accounts[pubkey] onMount(async () => { cursor = new Cursor({kinds: [1], authors: [pubkey]}) - listener = await notesListener(notes, {kinds: [1, 5, 7], authors: [pubkey]}) + listener = await notesListener(notes, [{kinds: [1], authors: [pubkey]}, {kinds: [5, 7]}]) scroll = scroller(cursor, async chunk => { const annotated = await annotateNotes(chunk, {showParents: true}) @@ -30,8 +34,13 @@ // Populate our initial empty space scroll() + // Track loading based on cursor cutoff date + interval = setInterval(() => { + loading = cursor.since > epoch + }, 1000) + // When a modal opens, suspend our subscriptions - modal.subscribe(async $modal => { + modalUnsub = modal.subscribe(async $modal => { if ($modal) { cursor.stop() listener.stop() @@ -45,7 +54,10 @@ onDestroy(() => { cursor?.stop() listener?.stop() + modalUnsub() + clearInterval(interval) }) + @@ -81,6 +93,12 @@
{/each} + {:else} + {#if loading} +
  • + {:else} +
  • No notes found.
  • + {/if} {/each}