Fix search

This commit is contained in:
Jonathan Staab 2022-12-23 13:58:21 -08:00
parent f5aae29582
commit a3ae2e9940
3 changed files with 20 additions and 31 deletions

View File

@ -26,12 +26,7 @@ Coracle is currently in _alpha_ - expect bugs, slow loading times, and rough edg
# Bugs
- [ ] Use https://nostr.watch/relays.json to populate relays
- [ ] Completely redo notes fetching, it's buggy as heck
- [ ] uniq and sortBy are sprinkled all over the place, figure out a better solution
- [ ] Search page is slow and likes don't show up. Probably move this server-side
- [ ] User detail is not filtering by author
- [ ] Add alerts for replies to posts the user liked
- [ ] Support bech32 keys/add guide on how to convert
- [ ] With link/image previews, remove the url from the note body if it's on a separate last line
- [ ] Stack views so scroll position isn't lost on navigation
- [ ] We're sending client=astral tags, event id 125ff9dc495f65d302e8d95ea6f9385106cc31b81c80e8c582b44be92fa50c44

View File

@ -1,35 +1,35 @@
<script>
import {take} from 'ramda'
import {onMount} from 'svelte'
import {fly} from 'svelte/transition'
import {fuzzy} from "src/util/misc"
import Note from "src/partials/Note.svelte"
import relay from 'src/relay'
import Spinner from "src/partials/Spinner.svelte"
export let q
let results = []
let search
const search = relay.lq(async () => {
const notes = take(5000, await relay.filterEvents({kinds: [1]}))
return fuzzy(notes, {keys: ["content"]})
onMount(async () => {
search = fuzzy(
take(5000, await relay.filterEvents({kinds: [1]})),
{keys: ["content"]}
)
})
$: {
if ($search) {
Promise.all(
$search(q).map(n => relay.findNote(n.id))
).then(notes => {
results = notes
})
}
}
</script>
{#if search}
<ul class="py-8 flex flex-col gap-2 max-w-xl m-auto">
{#each results.slice(0, 50) as e (e.id)}
{#await Promise.all(search(q).slice(0, 30).map(n => relay.findNote(n.id)))}
<Spinner />
{:then results}
{#each results as e (e.id)}
<li in:fly={{y: 20}}>
<Note interactive note={e} />
</li>
{/each}
{/each}
{/await}
</ul>
{:else}
<Spinner />
{/if}

View File

@ -1,18 +1,13 @@
<script>
import {fly} from 'svelte/transition'
import {fuzzy} from "src/util/misc"
import relay, {user} from 'src/relay'
import {user, people} from 'src/relay'
export let q
let search
const people = relay.lq(() => relay.db.people.toArray())
$: search = fuzzy($people || [], {keys: ["name", "about", "pubkey"]})
let search = fuzzy(Object.values($people), {keys: ["name", "about", "pubkey"]})
</script>
{#if search}
<ul class="py-8 flex flex-col gap-2 max-w-xl m-auto">
{#each search(q) as p (p.pubkey)}
{#if p.pubkey !== $user.pubkey}
@ -30,4 +25,3 @@
{/if}
{/each}
</ul>
{/if}