Switch from applesauce to welshman
This commit is contained in:
+15
-7
@@ -1,7 +1,8 @@
|
||||
import { createSignal, createEffect, onCleanup } from "solid-js"
|
||||
import type { NostrEvent } from "applesauce-core/helpers/event"
|
||||
import type { TrustedEvent } from "@welshman/util"
|
||||
import type { RepositoryUpdate } from "@welshman/net"
|
||||
import { account } from "./store"
|
||||
import { eventStore } from "./nostr"
|
||||
import { repository } from "./nostr"
|
||||
import { parseRelayList, parseOutboxRelays } from "./lib/relays"
|
||||
|
||||
export function useActivePubkey(): () => string {
|
||||
@@ -14,18 +15,25 @@ export function useAutoThreshold(members: () => string[]): [() => number, (n: nu
|
||||
return [threshold, setThreshold]
|
||||
}
|
||||
|
||||
function useReplaceable(kind: number, pubkey: () => string): () => NostrEvent | undefined {
|
||||
const [event, setEvent] = createSignal<NostrEvent | undefined>()
|
||||
function useReplaceable(kind: number, pubkey: () => string): () => TrustedEvent | undefined {
|
||||
const [event, setEvent] = createSignal<TrustedEvent | undefined>()
|
||||
createEffect(() => {
|
||||
const pk = pubkey()
|
||||
if (!pk) { setEvent(undefined); return }
|
||||
const sub = eventStore.replaceable(kind, pk).subscribe(e => setEvent(e ?? undefined))
|
||||
onCleanup(() => sub.unsubscribe())
|
||||
const query = () => setEvent(repository.getEvent(`${kind}:${pk}:`))
|
||||
const onUpdate = (update: RepositoryUpdate) => {
|
||||
if (update.added.some(e => e.kind === kind && e.pubkey === pk) || update.removed.size > 0) {
|
||||
query()
|
||||
}
|
||||
}
|
||||
query()
|
||||
repository.on("update", onUpdate)
|
||||
onCleanup(() => repository.off("update", onUpdate))
|
||||
})
|
||||
return event
|
||||
}
|
||||
|
||||
export function useProfileEvent(pubkey: () => string): () => NostrEvent | undefined {
|
||||
export function useProfileEvent(pubkey: () => string): () => TrustedEvent | undefined {
|
||||
return useReplaceable(0, pubkey)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user