Add wot calculation to app

This commit is contained in:
Jon Staab
2024-09-24 16:30:18 -07:00
parent f246e9914a
commit fd4f782798
7 changed files with 116 additions and 3 deletions
+14
View File
@@ -1,4 +1,6 @@
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"
@@ -7,6 +9,7 @@ import {repository, load} from './core'
import {createSearch} from './util'
import {collection} from './collection'
import {loadRelaySelections} from './relaySelections'
import {getUserWotScore} from './wot'
export const profiles = withGetter(
deriveEventsMapped<PublishedProfile>(repository, {
@@ -45,11 +48,22 @@ 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}) =>
score! < 0.1 ? dec(score!) * getUserWotScore(item.event.pubkey) : -score!,
fuseOptions: {
keys: ["name", "display_name", {name: "about", weight: 0.3}],
threshold: 0.3,
shouldSort: false,
},
}),
)