This commit is contained in:
2023-01-16 17:48:25 +00:00
parent b6a877877f
commit 8aed2c5550
39 changed files with 706 additions and 486 deletions

View File

@ -1,19 +1,26 @@
import { useLiveQuery } from "dexie-react-hooks";
import { useEffect, useMemo } from "react";
import { db } from "../db";
import { MetadataCache } from "../db/User";
import { HexKey } from "../nostr";
import { System } from "../nostr/System";
export default function useProfile(pubKey: HexKey | Array<HexKey>) {
export default function useProfile(pubKey: HexKey | Array<HexKey> | undefined): Map<HexKey, MetadataCache> | undefined {
const user = useLiveQuery(async () => {
let userList = new Map<HexKey, MetadataCache>();
if (pubKey) {
if (Array.isArray(pubKey)) {
let ret = await db.users.bulkGet(pubKey);
return ret.filter(a => a !== undefined).map(a => a!);
let filtered = ret.filter(a => a !== undefined).map(a => a!);
return new Map(filtered.map(a => [a.pubkey, a]))
} else {
return await db.users.get(pubKey);
let ret = await db.users.get(pubKey);
if (ret) {
userList.set(ret.pubkey, ret);
}
}
}
return userList;
}, [pubKey]);
useEffect(() => {