Add app package

This commit is contained in:
Jon Staab
2024-08-30 09:46:47 -07:00
parent e462ec2ada
commit 6e1ad713c3
34 changed files with 1193 additions and 48 deletions
+41
View File
@@ -0,0 +1,41 @@
import {throttle} from 'throttle-debounce'
import {derived} from 'svelte/store'
import {inc} from '@welshman/lib'
import {custom} from '@welshman/store'
import {createSearch} from './util'
import {repository} from './core'
export type Topic = {
name: string
count: number
}
export const topics = custom<Topic[]>(setter => {
const getTopics = () => {
const topics = new Map<string, number>()
for (const tagString of repository.eventsByTag.keys()) {
if (tagString.startsWith("t:")) {
const topic = tagString.slice(2).toLowerCase()
topics.set(topic, inc(topics.get(topic)))
}
}
return Array.from(topics.entries()).map(([name, count]) => ({name, count}))
}
setter(getTopics())
const onUpdate = throttle(3000, () => setter(getTopics()))
repository.on("update", onUpdate)
return () => repository.off("update", onUpdate)
})
export const topicSearch = derived(topics, $topics =>
createSearch($topics, {
getValue: (topic: Topic) => topic.name,
fuseOptions: {keys: ["name"]},
}),
)