feat: community leaders

This commit is contained in:
2023-12-18 15:57:00 +00:00
parent 457cba32a7
commit 7523b41610
14 changed files with 192 additions and 11 deletions

View File

@ -0,0 +1,41 @@
import { ExternalStore, unwrap } from "@snort/shared";
import { EventKind, parseNostrLink } from "@snort/system";
import { useLinkList } from "./useLists";
import { useEffect, useSyncExternalStore } from "react";
class CommunityLeadersStore extends ExternalStore<Array<string>> {
#leaders: Array<string> = [];
setLeaders(arr: Array<string>) {
this.#leaders = arr;
this.notifyChange();
}
takeSnapshot(): string[] {
return [...this.#leaders];
}
}
const LeadersStore = new CommunityLeadersStore();
export function useCommunityLeaders() {
const link = parseNostrLink(unwrap(CONFIG.communityLeaders).list);
const list = useLinkList("leaders", rb => {
rb.withFilter().kinds([EventKind.FollowSet]).link(link);
});
useEffect(() => {
console.debug("CommunityLeaders", list);
LeadersStore.setLeaders(list.map(a => a.id));
}, [list]);
}
export function useCommunityLeader(pubkey?: string) {
const store = useSyncExternalStore(
c => LeadersStore.hook(c),
() => LeadersStore.snapshot(),
);
return pubkey && store.includes(pubkey);
}