From 65c8f6372115df5a512297a14576c12d223d4af2 Mon Sep 17 00:00:00 2001 From: Jonathan Staab Date: Thu, 8 Dec 2022 09:48:39 -0800 Subject: [PATCH] Add likes/network tabs --- README.md | 5 +- src/App.svelte | 4 +- src/partials/Likes.svelte | 86 +++++++++++++++++++++++++++++++++++ src/partials/Notes.svelte | 4 +- src/partials/UserBadge.svelte | 6 +-- src/routes/Profile.svelte | 2 +- src/routes/Search.svelte | 2 +- src/routes/UserDetail.svelte | 32 +++++++++---- src/state/app.js | 61 ++++++++++++------------- src/state/nostr.js | 4 +- 10 files changed, 152 insertions(+), 54 deletions(-) create mode 100644 src/partials/Likes.svelte diff --git a/README.md b/README.md index 524fb76b..b68efb7c 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,13 @@ Bugs -- [ ] Permalink note detail (share/permalink button?) +- [ ] Back button is pretty broken +- [ ] Permalink note detail (share/permalink button?). Permalinks don't work - [ ] Prevent tabs from re-mounting (or at least re- animating) - [ ] Go "back" after adding a note - [ ] uniq and sortBy are sprinkled all over the place, figure out a better solution - [ ] With link/image previews, remove the url from the note body if it's on a separate last line +- [ ] Search page is slow and likes don't show up. Probably move this server-side +- [ ] Replies counts aren't showing on replies Features diff --git a/src/App.svelte b/src/App.svelte index f6de8fc1..e02be2a1 100644 --- a/src/App.svelte +++ b/src/App.svelte @@ -102,7 +102,7 @@ {/key} - + {#key params.pubkey} {/key} @@ -122,7 +122,7 @@ > {#if $user}
  • - +
    diff --git a/src/partials/Likes.svelte b/src/partials/Likes.svelte new file mode 100644 index 00000000..1b7d82d9 --- /dev/null +++ b/src/partials/Likes.svelte @@ -0,0 +1,86 @@ + + + + +
      + {#each $notes as n (n.id)} +
    • + + {#each n.replies as r (r.id)} +
      + +
      + {/each} +
    • + {:else} + {#if loading} +
    • + {:else} +
    • No notes found.
    • + {/if} + {/each} +
    diff --git a/src/partials/Notes.svelte b/src/partials/Notes.svelte index f03ddd63..7c19f111 100644 --- a/src/partials/Notes.svelte +++ b/src/partials/Notes.svelte @@ -1,7 +1,7 @@ -
    +
    - {user?.name || user?.pubkey.slice(0, 8)} + style="background-image: url({user.picture})" /> + {user.name || user.pubkey.slice(0, 8)} diff --git a/src/routes/Profile.svelte b/src/routes/Profile.svelte index 1605b4c4..bfddb1d0 100644 --- a/src/routes/Profile.svelte +++ b/src/routes/Profile.svelte @@ -43,7 +43,7 @@ } else { await dispatch("account/update", values) - navigate(`/users/${$user.pubkey}`) + navigate(`/users/${$user.pubkey}/profile`) toast.show("info", "Your profile has been updated!") } diff --git a/src/routes/Search.svelte b/src/routes/Search.svelte index 501a8791..89eb5b14 100644 --- a/src/routes/Search.svelte +++ b/src/routes/Search.svelte @@ -88,7 +88,7 @@ {#each (results || []) as e (e.pubkey)} {#if e.pubkey !== $user.pubkey}
  • - +
    diff --git a/src/routes/UserDetail.svelte b/src/routes/UserDetail.svelte index f9cf151b..dfc9c331 100644 --- a/src/routes/UserDetail.svelte +++ b/src/routes/UserDetail.svelte @@ -1,19 +1,27 @@ -{#if user} -
    +
    + style="background-image: url({user?.picture})" />
    -

    {user.name}

    +

    {user?.name || pubkey.slice(0, 8)}

    {#if $currentUser && $currentUser.pubkey !== pubkey} {/if}
    -

    {user.about || ''}

    +

    {user?.about || ''}

    {#if $currentUser?.pubkey === pubkey} @@ -71,7 +78,12 @@
    -
    -
    + +{#if activeTab === 'notes'} + +{:else if activeTab === 'likes'} + +{:else if activeTab === 'network'} + {/if} diff --git a/src/state/app.js b/src/state/app.js index 47245162..33145ee2 100644 --- a/src/state/app.js +++ b/src/state/app.js @@ -1,8 +1,8 @@ -import {when, assoc, prop, identity, whereEq, reverse, uniq, sortBy, uniqBy, find, last, pluck, groupBy} from 'ramda' +import {when, prop, identity, whereEq, reverse, uniq, sortBy, uniqBy, find, last, pluck, groupBy} from 'ramda' import {debounce} from 'throttle-debounce' import {writable, get} from 'svelte/store' import {navigate} from "svelte-routing" -import {switcherFn, ensurePlural} from 'hurdak/lib/hurdak' +import {switcherFn} from 'hurdak/lib/hurdak' import {getLocalJson, setLocalJson, now, timedelta, sleep} from "src/util/misc" import {user} from 'src/state/user' import {epoch, filterMatches, Listener, channels, relays, findReplyTo} from 'src/state/nostr' @@ -179,38 +179,35 @@ export const notesListener = (notes, filter, {shouldMuffle = false} = {}) => { reactions: n.reactions.filter(e => !ids.includes(e.id)), })) - return new Listener( - ensurePlural(filter).map(assoc('since', now())), - e => switcherFn(e.kind, { - 1: async () => { - const id = findReplyTo(e) + return new Listener(filter, e => switcherFn(e.kind, { + 1: async () => { + const id = findReplyTo(e) - if (shouldMuffle && Math.random() > getMuffleValue(e.pubkey)) { - return - } - - if (id) { - const [reply] = await annotateNotes([e]) - - updateNote(id, n => ({...n, replies: n.replies.concat(reply)})) - } else if (filterMatches(filter, e)) { - const [note] = await annotateNotes([e]) - - notes.update($notes => uniqBy(prop('id'), [note].concat($notes))) - } - }, - 5: () => { - const ids = e.tags.map(t => t[1]) - - notes.update($notes => deleteNotes($notes, ids)) - }, - 7: () => { - const id = findReplyTo(e) - - updateNote(id, n => ({...n, reactions: n.reactions.concat(e)})) + if (shouldMuffle && Math.random() > getMuffleValue(e.pubkey)) { + return } - }) - ) + + if (id) { + const [reply] = await annotateNotes([e]) + + updateNote(id, n => ({...n, replies: n.replies.concat(reply)})) + } else if (filterMatches(filter, e)) { + const [note] = await annotateNotes([e]) + + notes.update($notes => uniqBy(prop('id'), [note].concat($notes))) + } + }, + 5: () => { + const ids = e.tags.map(t => t[1]) + + notes.update($notes => deleteNotes($notes, ids)) + }, + 7: () => { + const id = findReplyTo(e) + + updateNote(id, n => ({...n, reactions: n.reactions.concat(e)})) + } + })) } // UI diff --git a/src/state/nostr.js b/src/state/nostr.js index eb8c6f84..ee97648b 100644 --- a/src/state/nostr.js +++ b/src/state/nostr.js @@ -1,6 +1,6 @@ import {writable, get} from 'svelte/store' import {relayPool, getPublicKey} from 'nostr-tools' -import {last, find, intersection, uniqBy, prop} from 'ramda' +import {assoc, last, find, intersection, uniqBy, prop} from 'ramda' import {first, noop, ensurePlural} from 'hurdak/lib/hurdak' import {getLocalJson, setLocalJson, now, timedelta} from "src/util/misc" @@ -184,7 +184,7 @@ export class Cursor { export class Listener { constructor(filter, onEvent) { - this.filter = ensurePlural(filter) + this.filter = ensurePlural(filter).map(assoc('since', now())) this.onEvent = onEvent this.since = now() this.sub = null