diff --git a/package-lock.json b/package-lock.json index af9bf622..9af4fd01 100644 Binary files a/package-lock.json and b/package-lock.json differ diff --git a/package.json b/package.json index 2be7b7bc..39959a28 100644 --- a/package.json +++ b/package.json @@ -30,6 +30,7 @@ "hurdak": "github:ConsignCloud/hurdak", "nostr-tools": "github:fiatjaf/nostr-tools#1b798b2", "ramda": "^0.28.0", + "svelte-loading-spinners": "^0.3.4", "svelte-routing": "^1.6.0", "throttle-debounce": "^5.0.0", "vite-plugin-node-polyfills": "^0.5.0" diff --git a/src/App.svelte b/src/App.svelte index 93dc9f4e..b350f5c8 100644 --- a/src/App.svelte +++ b/src/App.svelte @@ -50,10 +50,14 @@ modal.subscribe($modal => { // 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}