completed migrate to tauri-sql

This commit is contained in:
Ren Amamiya
2023-04-18 19:15:04 +07:00
parent fc1101f97b
commit c72798507e
40 changed files with 321 additions and 476 deletions

View File

@@ -3,6 +3,7 @@ import { RelayContext } from '@components/relaysProvider';
import { UserExtend } from '@components/user/extend';
import { contentParser } from '@utils/parser';
import { createNote, getNoteByID } from '@utils/storage';
import { getParentID } from '@utils/transform';
import useLocalStorage from '@rehooks/local-storage';
@@ -11,14 +12,13 @@ import { memo, useCallback, useContext, useEffect, useRef, useState } from 'reac
export const NoteParent = memo(function NoteParent({ id }: { id: string }) {
const [pool, relays]: any = useContext(RelayContext);
const [activeAccount]: any = useLocalStorage('activeAccount', {});
const [activeAccount]: any = useLocalStorage('account', {});
const [event, setEvent] = useState(null);
const unsubscribe = useRef(null);
const content = event ? contentParser(event.content, event.tags) : '';
const fetchEvent = useCallback(async () => {
const { createNote } = await import('@utils/bindings');
unsubscribe.current = pool.subscribe(
[
{
@@ -33,17 +33,16 @@ export const NoteParent = memo(function NoteParent({ id }: { id: string }) {
// insert to database
const parentID = getParentID(event.tags, event.id);
// insert event to local database
createNote({
event_id: event.id,
pubkey: event.pubkey,
kind: event.kind,
tags: JSON.stringify(event.tags),
content: event.content,
parent_id: parentID,
parent_comment_id: '',
created_at: event.created_at,
account_id: activeAccount.id,
}).catch(console.error);
createNote(
event.id,
activeAccount.id,
event.pubkey,
event.kind,
event.tags,
event.content,
event.created_at,
parentID
);
},
undefined,
undefined,
@@ -54,8 +53,7 @@ export const NoteParent = memo(function NoteParent({ id }: { id: string }) {
}, [activeAccount.id, id, pool, relays]);
const checkNoteExist = useCallback(async () => {
const { getNoteById } = await import('@utils/bindings');
getNoteById({ event_id: id })
getNoteByID(id)
.then((res) => {
if (res) {
setEvent(res);
@@ -81,16 +79,16 @@ export const NoteParent = memo(function NoteParent({ id }: { id: string }) {
<div className="relative pb-5">
<div className="absolute left-[21px] top-0 h-full w-0.5 bg-gradient-to-t from-zinc-800 to-zinc-600"></div>
<div className="relative z-10 flex flex-col">
<UserExtend pubkey={event.pubkey} time={event.createdAt || event.created_at} />
<UserExtend pubkey={event.pubkey} time={event.created_at} />
<div className="mt-1 pl-[52px]">
<div className="whitespace-pre-line break-words text-[15px] leading-tight text-zinc-100">{content}</div>
</div>
<div onClick={(e) => e.stopPropagation()} className="mt-5 pl-[52px]">
<NoteMetadata
eventID={event.eventId}
eventID={event.event_id}
eventPubkey={event.pubkey}
eventContent={event.content}
eventTime={event.createdAt || event.created_at}
eventTime={event.created_at}
/>
</div>
</div>