diff --git a/src/App.svelte b/src/App.svelte index 909dd9ee..9ff3befb 100644 --- a/src/App.svelte +++ b/src/App.svelte @@ -76,7 +76,11 @@
- + + {#key params.type} + + {/key} + @@ -115,7 +119,7 @@ {/if}
  • - + Search
  • diff --git a/src/partials/UserBadge.svelte b/src/partials/UserBadge.svelte index 2734d5a0..19a303e6 100644 --- a/src/partials/UserBadge.svelte +++ b/src/partials/UserBadge.svelte @@ -7,6 +7,6 @@
    - {user.name || ''} + {user.name || user.pubkey.slice(0, 8)} {/if} diff --git a/src/routes/Search.svelte b/src/routes/Search.svelte index af698776..9c0c424c 100644 --- a/src/routes/Search.svelte +++ b/src/routes/Search.svelte @@ -2,18 +2,19 @@ import {onMount, onDestroy} from 'svelte' import {writable} from 'svelte/store' import {fly} from 'svelte/transition' - import {uniqBy, identity, uniq, pluck, prop} from 'ramda' + import {uniqBy, pluck, prop} from 'ramda' import {fuzzy} from "src/util/misc" import Anchor from "src/partials/Anchor.svelte" import Input from "src/partials/Input.svelte" import Spinner from "src/partials/Spinner.svelte" import Note from "src/partials/Note.svelte" import {relays, Cursor} from "src/state/nostr" - import {createScroller, accounts, annotateNotes, modal} from "src/state/app" + import {user} from "src/state/user" + import {createScroller, ensureAccounts, accounts, annotateNotes, modal} from "src/state/app" - const notes = writable([]) - const people = writable([]) - let type = writable('people') + export let type + + const data = writable([]) let q = '' let search let results @@ -21,11 +22,7 @@ let scroller let modalUnsub - $: search = ( - $type === 'people' - ? fuzzy($people, {keys: ["name", "about"]}) - : fuzzy($notes, {keys: ["content"]}) - ) + $: search = fuzzy($data, {keys: type === 'people' ? ["name", "about", "pubkey"] : ["content"]}) $: { scroller?.start() @@ -33,17 +30,17 @@ } onMount(async () => { - cursor = new Cursor({kinds: [1]}) + cursor = new Cursor({kinds: type === 'people' ? [0] : [1]}) scroller = createScroller(cursor, async chunk => { - const annotated = await annotateNotes(chunk) - const keys = uniq(pluck('pubkey', chunk)) + if (type === 'people') { + await ensureAccounts(pluck('pubkey', chunk)) - notes.update($notes => uniqBy(prop('id'), $notes.concat(annotated))) - people.update($people => { - $people = $people.concat(keys.map(k => $accounts[k]).filter(identity)) + data.set(Object.values($accounts)) + } else { + const annotated = await annotateNotes(chunk) - return uniqBy(prop('pubkey'), $people) - }) + data.update($data => uniqBy(prop('id'), $data.concat(annotated))) + } }) // When a modal opens, suspend our subscriptions @@ -69,49 +66,57 @@
    • type.set('people')}> - People + class="cursor-pointer hover:border-b border-solid border-medium" + class:border-b={type === 'people'}> + People
    • type.set('notes')}> - Notes + class="cursor-pointer hover:border-b border-solid border-medium" + class:border-b={type === 'notes'}> + Notes
    - +
    +{#if type === 'people'} +{/if} + +{#if type === 'notes'} +
      + {#each (results || []) as e (e.id)} +
    • {#each e.replies as r (r.id)}
      {/each} - {/if}
    • {/each}
    +{/if} diff --git a/src/state/app.js b/src/state/app.js index 3493e531..f4f02ad3 100644 --- a/src/state/app.js +++ b/src/state/app.js @@ -41,7 +41,7 @@ export const ensureAccounts = async (pubkeys, {force = false} = {}) => { ) if (pubkeys.length) { - const events = await channels.getter.all({kinds: [0], authors: pubkeys}) + const events = await channels.getter.all({kinds: [0], authors: uniq(pubkeys)}) await accounts.update($accounts => { events.forEach(e => { @@ -50,7 +50,7 @@ export const ensureAccounts = async (pubkeys, {force = false} = {}) => { ...$accounts[e.pubkey], ...JSON.parse(e.content), refreshed: now(), - isAccount: true, + isUser: true, } })