From 4f41022b3022f934e15eca2ba268c5225726d2f3 Mon Sep 17 00:00:00 2001 From: Ren Amamiya <123083837+reyamir@users.noreply.github.com> Date: Mon, 17 Jul 2023 07:51:00 +0700 Subject: [PATCH] update --- src/libs/storage.tsx | 22 ++++++++++++++-------- src/shared/notes/actions.tsx | 7 ++----- src/shared/notes/actions/reaction.tsx | 6 +++--- src/shared/notes/actions/reply.tsx | 7 ++----- src/shared/notes/actions/repost.tsx | 7 ++----- src/shared/notes/actions/zap.tsx | 7 ++----- src/shared/notes/mentions/note.tsx | 2 +- src/shared/user.tsx | 2 +- src/utils/types.d.ts | 17 +++++++++++++++++ 9 files changed, 44 insertions(+), 33 deletions(-) diff --git a/src/libs/storage.tsx b/src/libs/storage.tsx index 7d00f51e..0d568fc8 100644 --- a/src/libs/storage.tsx +++ b/src/libs/storage.tsx @@ -1,9 +1,8 @@ -import { NDKTag, NDKUserProfile } from '@nostr-dev-kit/ndk'; import destr from 'destr'; import Database from 'tauri-plugin-sql-api'; import { getParentID } from '@utils/transform'; -import { Chats, LumeEvent } from '@utils/types'; +import { Account, Block, Chats, LumeEvent } from '@utils/types'; let db: null | Database = null; @@ -20,7 +19,9 @@ export async function connect(): Promise { // get active account export async function getActiveAccount() { const db = await connect(); - const result: any = await db.select('SELECT * FROM accounts WHERE is_active = 1;'); + const result: Array = await db.select( + 'SELECT * FROM accounts WHERE is_active = 1;' + ); if (result.length > 0) { return result[0]; } else { @@ -31,9 +32,10 @@ export async function getActiveAccount() { // get all accounts export async function getAccounts() { const db = await connect(); - return await db.select( + const result: Array = await db.select( 'SELECT * FROM accounts WHERE is_active = 0 ORDER BY created_at DESC;' ); + return result; } // create account @@ -433,15 +435,19 @@ export async function updateItemInBlacklist(content: string, status: number) { // get all blocks export async function getBlocks() { const db = await connect(); - const activeAccount = await getActiveAccount(); - const result: any = await db.select( - `SELECT * FROM blocks WHERE account_id = "${activeAccount.id}" ORDER BY created_at DESC;` + const account = await getActiveAccount(); + const result: Array = await db.select( + `SELECT * FROM blocks WHERE account_id = "${account.id}" ORDER BY created_at DESC;` ); return result; } // create block -export async function createBlock(kind: number, title: string, content: any) { +export async function createBlock( + kind: number, + title: string, + content: string | string[] +) { const db = await connect(); const activeAccount = await getActiveAccount(); return await db.execute( diff --git a/src/shared/notes/actions.tsx b/src/shared/notes/actions.tsx index cba308bd..c106917b 100644 --- a/src/shared/notes/actions.tsx +++ b/src/shared/notes/actions.tsx @@ -46,12 +46,9 @@ export function NoteActions({ id, pubkey }: { id: string; pubkey: string }) { - + Open thread - + diff --git a/src/shared/notes/actions/reaction.tsx b/src/shared/notes/actions/reaction.tsx index 48ec3e6b..83889974 100644 --- a/src/shared/notes/actions/reaction.tsx +++ b/src/shared/notes/actions/reaction.tsx @@ -72,8 +72,8 @@ export function NoteReaction({ id, pubkey }: { id: string; pubkey: string }) {
@@ -133,7 +133,7 @@ export function NoteReaction({ id, pubkey }: { id: string; pubkey: string }) { />
- +
diff --git a/src/shared/notes/actions/reply.tsx b/src/shared/notes/actions/reply.tsx index e391849d..cbda02a8 100644 --- a/src/shared/notes/actions/reply.tsx +++ b/src/shared/notes/actions/reply.tsx @@ -19,12 +19,9 @@ export function NoteReply({ id, pubkey }: { id: string; pubkey: string }) { - + Quick reply - + diff --git a/src/shared/notes/actions/repost.tsx b/src/shared/notes/actions/repost.tsx index bf22d219..0bfd214b 100644 --- a/src/shared/notes/actions/repost.tsx +++ b/src/shared/notes/actions/repost.tsx @@ -29,12 +29,9 @@ export function NoteRepost({ id, pubkey }: { id: string; pubkey: string }) { - + Repost - + diff --git a/src/shared/notes/actions/zap.tsx b/src/shared/notes/actions/zap.tsx index 64f7a19b..a6407fc0 100644 --- a/src/shared/notes/actions/zap.tsx +++ b/src/shared/notes/actions/zap.tsx @@ -14,12 +14,9 @@ export function NoteZap() { - + Tip - + diff --git a/src/shared/notes/mentions/note.tsx b/src/shared/notes/mentions/note.tsx index 39582d8d..17f7ab1e 100644 --- a/src/shared/notes/mentions/note.tsx +++ b/src/shared/notes/mentions/note.tsx @@ -65,7 +65,7 @@ export const MentionNote = memo(function MentionNote({ id }: { id: string }) { }, }} > - {data.content.parsed.length > 200 + {data?.content?.parsed?.length > 200 ? data.content.parsed.substring(0, 200) + '...' : data.content.parsed} diff --git a/src/shared/user.tsx b/src/shared/user.tsx index b6e164b7..b930c3ef 100644 --- a/src/shared/user.tsx +++ b/src/shared/user.tsx @@ -2,7 +2,7 @@ import { Popover, Transition } from '@headlessui/react'; import { Fragment } from 'react'; import { Link } from 'react-router-dom'; -import { ChevronDownIcon, VerticalDotsIcon } from '@shared/icons'; +import { VerticalDotsIcon } from '@shared/icons'; import { Image } from '@shared/image'; import { DEFAULT_AVATAR } from '@stores/constants'; diff --git a/src/utils/types.d.ts b/src/utils/types.d.ts index 60702a63..b2068820 100644 --- a/src/utils/types.d.ts +++ b/src/utils/types.d.ts @@ -5,6 +5,23 @@ export interface LumeEvent extends NDKEvent { parent_id: string; } +export interface Account { + id: number; + npub: string; + pubkey: string; + privkey: string; + follows: string[] | string; + is_active: number; +} + +export interface Block { + id: string; + account_id: number; + kind: number; + title: string; + content: string; +} + export interface Chats { id: string; event_id: string;