snort/src/feed/ProfileFeed.ts

27 lines
809 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";
2023-01-16 00:07:27 +00:00
import { db } from "../db";
2023-01-15 19:40:47 +00:00
import { HexKey } from "../nostr";
2023-01-16 00:07:27 +00:00
import { System } from "../nostr/System";
2023-01-15 19:40:47 +00:00
export default function useProfile(pubKey: HexKey | Array<HexKey>) {
2023-01-16 00:07:27 +00:00
const user = useLiveQuery(async () => {
if (pubKey) {
if (Array.isArray(pubKey)) {
let ret = await db.users.bulkGet(pubKey);
return ret.filter(a => a !== undefined).map(a => a!);
} else {
return await db.users.get(pubKey);
}
}
2023-01-16 00:07:27 +00:00
}, [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 user;
}