fix: use latest event

This commit is contained in:
Shusui MOYATANI
2023-03-13 00:31:38 +09:00
parent c3d9eaa10b
commit 19b2a8c367
5 changed files with 25 additions and 16 deletions

View File

@@ -30,11 +30,10 @@ export type UseProfileProps = {
type UseProfile = {
profile: Accessor<Profile | undefined>;
query: CreateQueryResult<NostrEvent>;
query: CreateQueryResult<Accessor<NostrEvent> | undefined>;
};
const { exec } = useBatchedEvent<UseProfileProps>(() => ({
interval: 2000,
generateKey: ({ pubkey }: UseProfileProps): string => pubkey,
mergeFilters: (args: UseProfileProps[]): Filter[] => {
const pubkeys = args.map((arg) => arg.pubkey);
@@ -62,12 +61,13 @@ const useProfile = (propsProvider: () => UseProfileProps | null): UseProfile =>
);
const profile = () => {
if (query.data == null) return undefined;
const content = query.data?.()?.content;
if (content == null) return undefined;
// TODO 大きすぎたりしないかどうか、JSONかどうかのチェック
try {
return JSON.parse(query.data.content) as Profile;
return JSON.parse(content) as Profile;
} catch (e) {
console.error(e, query.data.content);
console.error(e, content);
return undefined;
}
};