update composer
This commit is contained in:
@@ -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 };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user