diff --git a/src/components/note/atoms/user.tsx b/src/components/note/atoms/user.tsx index 729ff417..6fe5e87b 100644 --- a/src/components/note/atoms/user.tsx +++ b/src/components/note/atoms/user.tsx @@ -7,7 +7,7 @@ import MoreIcon from '@assets/icons/More'; import Avatar from 'boring-avatars'; import { useNostrEvents } from 'nostr-react'; -import { memo, useState } from 'react'; +import { memo, useEffect, useState } from 'react'; import Moment from 'react-moment'; import Database from 'tauri-plugin-sql-api'; @@ -26,19 +26,39 @@ export const User = memo(function User({ pubkey, time }: { pubkey: string; time: onEvent(async (rawMetadata) => { try { const metadata: any = JSON.parse(rawMetadata.content); - if (metadata) { + if (profile.picture === null || profile.name === null) { setProfile(metadata); await db.execute( - `INSERT INTO cache_profiles (pubkey, metadata) VALUES ("${pubkey}", '${JSON.stringify( + `INSERT OR IGNORE INTO cache_profiles (pubkey, metadata) VALUES ("${pubkey}", '${JSON.stringify( metadata )}')` ); + } else { + return; } } catch (err) { console.error(err, rawMetadata); } }); + useEffect(() => { + const initialProfile = async () => { + const result: any = await db.select( + `SELECT metadata FROM cache_profiles WHERE pubkey = "${pubkey}"` + ); + db.close; + return result; + }; + + initialProfile() + .then((res) => { + if (res[0] !== undefined) { + setProfile(JSON.parse(res[0].metadata)); + } + }) + .catch(console.error); + }, [pubkey]); + return (
Loading...
- > - ), -}); - export const Liked = memo(function Liked({ eventUser, sourceID, @@ -48,7 +39,7 @@ export const Liked = memo(function Liked({Loading...
- > - ), -}); - // eslint-disable-next-line @typescript-eslint/no-explicit-any export function Multi({ event }: { event: any }) { const tags = event.tags; @@ -36,7 +27,7 @@ export function Multi({ event }: { event: any }) {Loading...
- > - ), -}); - export const Repost = memo(function Repost({ eventUser, sourceID, @@ -48,7 +39,7 @@ export const Repost = memo(function Repost({Loading...
- > - ), -}); - // eslint-disable-next-line @typescript-eslint/no-explicit-any export const Single = memo(function Single({ event }: { event: any }) { const router = useRouter(); @@ -32,7 +23,7 @@ export const Single = memo(function Single({ event }: { event: any }) {