diff --git a/src/libs/storage.tsx b/src/libs/storage.tsx index 496f23c6..98c057ea 100644 --- a/src/libs/storage.tsx +++ b/src/libs/storage.tsx @@ -454,11 +454,9 @@ export async function createMetadata(id: string, pubkey: string, content: string // get metadata export async function getUserMetadata(pubkey: string) { const db = await connect(); - const result = await db.select( - `SELECT content, created_at FROM metadata WHERE id = "${pubkey}";` - ); + const result = await db.select(`SELECT * FROM metadata WHERE pubkey = "${pubkey}";`); if (result[0]) { - return JSON.parse(result[0].content); + return result[0]; } else { return null; } diff --git a/src/shared/notes/stats.tsx b/src/shared/notes/stats.tsx index ead08097..975ebba8 100644 --- a/src/shared/notes/stats.tsx +++ b/src/shared/notes/stats.tsx @@ -6,6 +6,8 @@ import { useNDK } from '@libs/ndk/provider'; import { LoaderIcon } from '@shared/icons'; +import { compactNumber } from '@utils/number'; + export function NoteStats({ id }: { id: string }) { const { ndk } = useNDK(); const { status, data } = useQuery( @@ -59,17 +61,25 @@ export function NoteStats({ id }: { id: string }) { return (
-

- {data.reactions} - reactions +

+ + {compactNumber.format(data.reactions)} + {' '} + reactions

-

- {data.reposts} - reposts + · +

+ + {compactNumber.format(data.reposts)} + {' '} + reposts

-

- {data.zaps} - zaps + · +

+ + {compactNumber.format(data.zaps)} + {' '} + zaps

); diff --git a/src/shared/notes/users/thread.tsx b/src/shared/notes/users/thread.tsx index c7ee4346..a44326b3 100644 --- a/src/shared/notes/users/thread.tsx +++ b/src/shared/notes/users/thread.tsx @@ -35,7 +35,7 @@ export function ThreadUser({ pubkey, time }: { pubkey: string; time: number }) { -
+
{createdAt} · {displayNpub(pubkey, 16)} diff --git a/src/utils/hooks/useProfile.tsx b/src/utils/hooks/useProfile.tsx index 8855546b..051adec5 100644 --- a/src/utils/hooks/useProfile.tsx +++ b/src/utils/hooks/useProfile.tsx @@ -11,29 +11,36 @@ 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('cache hit - ', cache); - return cache; - } else { - const filter: NDKFilter = { kinds: [0], authors: [pubkey] }; - const events = await ndk.fetchEvents(filter); - const latest = [...events].slice(-1)[0]; - if (latest) { - await createMetadata(pubkey, pubkey, latest.content); - return JSON.parse(latest.content); + } = 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 JSON.parse(cache.content); } else { - return null; + const filter: NDKFilter = { kinds: [0], authors: [pubkey] }; + const events = await ndk.fetchEvents(filter); + const latest = [...events].sort((a, b) => b.created_at - a.created_at).pop(); + if (latest) { + await createMetadata(latest.id, latest.pubkey, latest.content); + return JSON.parse(latest.content); + } else { + return null; + } } + } else { + const profile = JSON.parse(fallback); + return profile; } - } else { - const profile = JSON.parse(fallback); - return profile; + }, + { + refetchOnWindowFocus: false, + refetchOnReconnect: false, + staleTime: Infinity, } - }); + ); return { status, user, error, isFetching }; }