Debounce search

This commit is contained in:
Jon Staab
2025-11-25 11:55:32 -08:00
parent 64c77cfd13
commit 229d92055f
4 changed files with 18 additions and 15 deletions

View File

@@ -643,7 +643,7 @@ export const getBlossomServer = async (options: GetBlossomServerOptions = {}) =>
} }
} }
const userUrls = getTagValues("server", getListTags(userBlossomServerList.get())) const userUrls = getTagValues("server", getListTags(get(userBlossomServerList)))
for (const url of userUrls) { for (const url of userUrls) {
return normalizeBlossomUrl(url) return normalizeBlossomUrl(url)

View File

@@ -14,7 +14,6 @@ import {
sortBy, sortBy,
append, append,
sort, sort,
prop,
uniq, uniq,
indexBy, indexBy,
partition, partition,
@@ -308,10 +307,7 @@ export const loadSettings = makeLoadItem(
getSettings, getSettings,
) )
export const userSettings = makeUserData({ export const userSettings = makeUserData(settingsByPubkey, loadSettings)
mapStore: settingsByPubkey,
loadItem: loadSettings,
})
export const loadUserSettings = makeUserLoader(loadSettings) export const loadUserSettings = makeUserLoader(loadSettings)
@@ -610,10 +606,7 @@ export const getSpaceRoomsFromGroupList = (url: string, groupList: List | undefi
return sortBy(roomComparator(url), rooms) return sortBy(roomComparator(url), rooms)
} }
export const userGroupList = makeUserData({ export const userGroupList = makeUserData(groupListsByPubkey, loadGroupList)
mapStore: groupListsByPubkey,
loadItem: loadGroupList,
})
export const loadUserGroupList = makeUserLoader(loadGroupList) export const loadUserGroupList = makeUserLoader(loadGroupList)

View File

@@ -10,8 +10,8 @@ import {
profiles, profiles,
searchProfiles, searchProfiles,
handlesByNip05, handlesByNip05,
maxWot, getMaxWot,
wotGraph, getWotGraph,
} from "@welshman/app" } from "@welshman/app"
import type {FileAttributes} from "@welshman/editor" import type {FileAttributes} from "@welshman/editor"
import {Editor, MentionSuggestion, WelshmanExtension} from "@welshman/editor" import {Editor, MentionSuggestion, WelshmanExtension} from "@welshman/editor"
@@ -62,10 +62,10 @@ export const makeEditor = async ({
onSearch: searchProfiles, onSearch: searchProfiles,
getValue: (profile: PublishedProfile) => profile.event.pubkey, getValue: (profile: PublishedProfile) => profile.event.pubkey,
sortFn: ({score = 1, item}) => { sortFn: ({score = 1, item}) => {
const wotScore = wotGraph.get().get(item.event.pubkey) || 0 const wotScore = getWotGraph().get(item.event.pubkey) || 0
const membershipScale = $spaceMembers.includes(item.event.pubkey) ? 2 : 1 const membershipScale = $spaceMembers.includes(item.event.pubkey) ? 2 : 1
return dec(score) * inc(wotScore / maxWot.get()) * membershipScale return dec(score) * inc(wotScore / getMaxWot()) * membershipScale
}, },
fuseOptions: { fuseOptions: {
keys: [ keys: [

View File

@@ -1,5 +1,6 @@
<script lang="ts"> <script lang="ts">
import {onMount} from "svelte" import {onMount} from "svelte"
import {debounce} from "throttle-debounce"
import {createScroller, isMobile} from "@lib/html" import {createScroller, isMobile} from "@lib/html"
import {profileSearch} from "@welshman/app" import {profileSearch} from "@welshman/app"
import Magnifier from "@assets/icons/magnifier.svg?dataurl" import Magnifier from "@assets/icons/magnifier.svg?dataurl"
@@ -11,9 +12,18 @@
let term = $state("") let term = $state("")
let limit = $state(10) let limit = $state(10)
let pubkeys = $state($bootstrapPubkeys)
let element: Element | undefined = $state() let element: Element | undefined = $state()
const pubkeys = $derived(term ? $profileSearch.searchValues(term) : $bootstrapPubkeys) const search = debounce(200, (term: string) => {
if (term) {
pubkeys = $profileSearch.searchValues(term)
} else {
pubkeys = $bootstrapPubkeys
}
})
$effect(() => search(term))
onMount(() => { onMount(() => {
const scroller = createScroller({ const scroller = createScroller({