More TSX
This commit is contained in:
@ -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(() => {
|
||||
|
Reference in New Issue
Block a user