refactored eventcollector & index page

This commit is contained in:
Ren Amamiya
2023-04-13 16:29:52 +07:00
parent 1f73be3a06
commit 2fced53a60
11 changed files with 235 additions and 243 deletions

13
src/utils/commands.tsx Normal file
View File

@@ -0,0 +1,13 @@
import { invoke } from '@tauri-apps/api';
export function countTotalNotes() {
return invoke('count_total_notes');
}
export function countTotalChannels() {
return invoke('count_total_channels');
}
export function countTotalChats() {
return invoke('count_total_chats');
}

View File

@@ -12,35 +12,20 @@ export const fetchMetadata = async (pubkey: string) => {
export const useMetadata = (pubkey) => {
const [profile, setProfile] = useState(null);
/*
const insertPlebToDB = useCallback(async (account, pubkey, metadata) => {
const { createPleb } = await import('@utils/bindings');
return await createPleb({
pleb_id: pubkey + '-lume' + account.toString(),
pubkey: pubkey,
kind: 1,
metadata: metadata,
account_id: account,
}).catch(console.error);
}, []);
*/
const getCachedMetadata = useCallback(async () => {
const { getPlebByPubkey } = await import('@utils/bindings');
getPlebByPubkey({ pubkey: pubkey })
.then((res) => {
if (res) {
if (res && res.metadata.length > 0) {
const metadata = JSON.parse(res.metadata);
// update state
setProfile(metadata);
} else {
fetchMetadata(pubkey).then((res: any) => {
if (res.content) {
if (res) {
const metadata = JSON.parse(res.content);
// update state
setProfile(metadata);
// save to database
// insertPlebToDB(activeAccount.id, pubkey, metadata);
}
});
}