snort/src/Feed/ProfileFeed.ts

35 lines
941 B
TypeScript
Raw Normal View History

2023-01-16 00:07:27 +00:00
import { useLiveQuery } from "dexie-react-hooks";
import { useEffect, useMemo } from "react";
import { RootState } from "State/Store";
import { MetadataCache } from "State/Users";
import { useKey, useKeys } from "State/Users/Hooks";
2023-01-20 11:11:50 +00:00
import { HexKey } from "Nostr";
import { System } from "Nostr/System";
2023-01-15 19:40:47 +00:00
export function useUserProfile(pubKey: HexKey): MetadataCache | undefined {
const users = useKey(pubKey);
2023-01-15 19:40:47 +00:00
useEffect(() => {
if (pubKey) {
System.TrackMetadata(pubKey);
return () => System.UntrackMetadata(pubKey);
}
2023-01-15 19:40:47 +00:00
}, [pubKey]);
return users;
}
export function useUserProfiles(pubKeys: Array<HexKey>): Map<HexKey, MetadataCache> | undefined {
const users = useKeys(pubKeys);
useEffect(() => {
if (pubKeys) {
System.TrackMetadata(pubKeys);
return () => System.UntrackMetadata(pubKeys);
}
}, [pubKeys]);
return users;
}