From 5210aa2fb80dc91209538961aaf099924d278225 Mon Sep 17 00:00:00 2001 From: Ren Amamiya <123083837+reyamir@users.noreply.github.com> Date: Thu, 23 Feb 2023 10:11:57 +0700 Subject: [PATCH] added cache profile to db --- src/components/note/atoms/user.tsx | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/components/note/atoms/user.tsx b/src/components/note/atoms/user.tsx index 20899f94..729ff417 100644 --- a/src/components/note/atoms/user.tsx +++ b/src/components/note/atoms/user.tsx @@ -9,6 +9,9 @@ import Avatar from 'boring-avatars'; import { useNostrEvents } from 'nostr-react'; import { memo, useState } from 'react'; import Moment from 'react-moment'; +import Database from 'tauri-plugin-sql-api'; + +const db = typeof window !== 'undefined' ? await Database.load('sqlite:lume.db') : null; export const User = memo(function User({ pubkey, time }: { pubkey: string; time: any }) { const [profile, setProfile] = useState({ picture: null, name: null }); @@ -20,12 +23,16 @@ export const User = memo(function User({ pubkey, time }: { pubkey: string; time: }, }); - // #TODO: save response to DB - onEvent((rawMetadata) => { + onEvent(async (rawMetadata) => { try { const metadata: any = JSON.parse(rawMetadata.content); if (metadata) { setProfile(metadata); + await db.execute( + `INSERT INTO cache_profiles (pubkey, metadata) VALUES ("${pubkey}", '${JSON.stringify( + metadata + )}')` + ); } } catch (err) { console.error(err, rawMetadata);