update composer

This commit is contained in:
Ren Amamiya
2023-07-08 15:21:06 +07:00
parent 3752a3ab0f
commit 4747299ade
6 changed files with 54 additions and 68 deletions

View File

@@ -12,31 +12,23 @@ export function useProfile(pubkey: string, fallback?: string) {
data: user,
error,
isFetching,
} = useQuery(
['user', pubkey],
async () => {
if (!fallback) {
const current = Math.floor(Date.now() / 1000);
const cache = await getUserMetadata(pubkey);
if (cache && parseInt(cache.created_at) + 86400 >= current) {
console.log('use cache', cache);
return cache;
} else {
const user = ndk.getUser({ hexpubkey: pubkey });
await user.fetchProfile();
await createMetadata(pubkey, pubkey, JSON.stringify(user.profile));
return user.profile;
}
} = useQuery(['user', pubkey], async () => {
if (!fallback) {
const current = Math.floor(Date.now() / 1000);
const cache = await getUserMetadata(pubkey);
if (cache && parseInt(cache.created_at) + 86400 >= current) {
return cache;
} else {
const profile = JSON.parse(fallback);
return profile;
const user = ndk.getUser({ hexpubkey: pubkey });
await user.fetchProfile();
await createMetadata(pubkey, pubkey, JSON.stringify(user.profile));
return user.profile;
}
},
{
refetchOnWindowFocus: false,
refetchOnReconnect: false,
} else {
const profile = JSON.parse(fallback);
return profile;
}
);
});
return { status, user, error, isFetching };
}