Move search to its own file, validate and search by nip05
This commit is contained in:
@@ -1,15 +1,11 @@
|
||||
import {debounce} from 'throttle-debounce'
|
||||
import {derived, readable} from 'svelte/store'
|
||||
import {dec} from '@welshman/lib'
|
||||
import {readProfile, displayProfile, displayPubkey, PROFILE} from '@welshman/util'
|
||||
import type {SubscribeRequestWithHandlers} from "@welshman/net"
|
||||
import type {PublishedProfile, TrustedEvent} from "@welshman/util"
|
||||
import {deriveEventsMapped, withGetter} from '@welshman/store'
|
||||
import {repository, load} from './core'
|
||||
import {createSearch} from './util'
|
||||
import {collection} from './collection'
|
||||
import {loadRelaySelections} from './relaySelections'
|
||||
import {wotGraph} from './wot'
|
||||
|
||||
export const profiles = withGetter(
|
||||
deriveEventsMapped<PublishedProfile>(repository, {
|
||||
@@ -49,31 +45,6 @@ export const {
|
||||
},
|
||||
})
|
||||
|
||||
export const searchProfiles = debounce(500, (search: string) => {
|
||||
if (search.length > 2) {
|
||||
load({filters: [{kinds: [PROFILE], search}]})
|
||||
}
|
||||
})
|
||||
|
||||
export const profileSearch = derived(profiles, $profiles =>
|
||||
createSearch($profiles, {
|
||||
onSearch: searchProfiles,
|
||||
getValue: (profile: PublishedProfile) => profile.event.pubkey,
|
||||
sortFn: ({score, item}) => {
|
||||
if (score && score > 0.1) return -score!
|
||||
|
||||
const wotScore = wotGraph.get().get(item.event.pubkey) || 0
|
||||
|
||||
return score ? dec(score) * wotScore : -wotScore
|
||||
},
|
||||
fuseOptions: {
|
||||
keys: ["name", "display_name", {name: "about", weight: 0.3}],
|
||||
threshold: 0.3,
|
||||
shouldSort: false,
|
||||
},
|
||||
}),
|
||||
)
|
||||
|
||||
export const displayProfileByPubkey = (pubkey: string | undefined) =>
|
||||
pubkey
|
||||
? displayProfile(profilesByPubkey.get().get(pubkey), displayPubkey(pubkey))
|
||||
|
||||
Reference in New Issue
Block a user