mirror of
https://github.com/luminous-devs/lume.git
synced 2024-09-19 19:46:34 +00:00
fixed sql execute
This commit is contained in:
parent
1084b208d3
commit
e9aa7bd4ff
@ -7,7 +7,7 @@ import { dateToUnix, hoursAgo } from '@utils/getDate';
|
|||||||
|
|
||||||
import { useLocalStorage } from '@rehooks/local-storage';
|
import { useLocalStorage } from '@rehooks/local-storage';
|
||||||
import { useSetAtom } from 'jotai';
|
import { useSetAtom } from 'jotai';
|
||||||
import { memo, useCallback, useContext, useEffect, useRef } from 'react';
|
import { memo, useCallback, useContext, useMemo, useRef } from 'react';
|
||||||
|
|
||||||
export const NoteConnector = memo(function NoteConnector() {
|
export const NoteConnector = memo(function NoteConnector() {
|
||||||
const { db }: any = useContext(DatabaseContext);
|
const { db }: any = useContext(DatabaseContext);
|
||||||
@ -23,23 +23,14 @@ export const NoteConnector = memo(function NoteConnector() {
|
|||||||
async (event: any) => {
|
async (event: any) => {
|
||||||
// insert to local database
|
// insert to local database
|
||||||
await db.execute(
|
await db.execute(
|
||||||
`INSERT OR IGNORE INTO
|
'INSERT OR IGNORE INTO cache_notes (id, pubkey, created_at, kind, content, tags) VALUES (?, ?, ?, ?, ?, ?);',
|
||||||
cache_notes
|
[event.id, event.pubkey, event.created_at, event.kind, event.content, JSON.stringify(event.tags)]
|
||||||
(id, pubkey, created_at, kind, content, tags) VALUES
|
|
||||||
(
|
|
||||||
"${event.id}",
|
|
||||||
"${event.pubkey}",
|
|
||||||
"${event.created_at}",
|
|
||||||
"${event.kind}",
|
|
||||||
"${event.content}",
|
|
||||||
'${JSON.stringify(event.tags)}'
|
|
||||||
);`
|
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
[db]
|
[db]
|
||||||
);
|
);
|
||||||
|
|
||||||
const fetchEvent = useCallback(() => {
|
useMemo(() => {
|
||||||
relayPool.subscribe(
|
relayPool.subscribe(
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
@ -60,10 +51,6 @@ export const NoteConnector = memo(function NoteConnector() {
|
|||||||
);
|
);
|
||||||
}, [relayPool, follows, relays, insertDB, setHasNewerNote]);
|
}, [relayPool, follows, relays, insertDB, setHasNewerNote]);
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
fetchEvent();
|
|
||||||
}, [fetchEvent]);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<div className="inline-flex items-center gap-1 rounded-md py-1 px-1.5 hover:bg-zinc-900">
|
<div className="inline-flex items-center gap-1 rounded-md py-1 px-1.5 hover:bg-zinc-900">
|
||||||
|
@ -70,7 +70,7 @@ export const Content = memo(function Content({ data }: { data: any }) {
|
|||||||
<MarkdownPreview
|
<MarkdownPreview
|
||||||
source={content.current}
|
source={content.current}
|
||||||
className={
|
className={
|
||||||
'prose prose-zinc max-w-none break-words dark:prose-invert prose-headings:mt-3 prose-headings:mb-2 prose-p:m-0 prose-p:leading-normal prose-a:font-medium prose-a:text-fuchsia-500 prose-a:no-underline prose-ul:mt-2 prose-li:my-1'
|
'prose prose-zinc max-w-none break-words dark:prose-invert prose-headings:mt-3 prose-headings:mb-2 prose-p:m-0 prose-p:leading-tight prose-a:font-medium prose-a:text-fuchsia-500 prose-a:no-underline prose-ul:mt-2 prose-li:my-1'
|
||||||
}
|
}
|
||||||
linkTarget="_blank"
|
linkTarget="_blank"
|
||||||
disallowedElements={[
|
disallowedElements={[
|
||||||
|
@ -113,7 +113,10 @@ export default function FormBasic() {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className="flex items-center gap-2">
|
<div className="flex items-center gap-2">
|
||||||
<button className="inline-flex h-8 w-16 items-center justify-center rounded-md bg-fuchsia-500 px-4 text-sm font-medium shadow-md shadow-fuchsia-900/50 hover:bg-fuchsia-600">
|
<button
|
||||||
|
disabled={value.length === 0 ? true : false}
|
||||||
|
className="inline-flex h-8 w-16 items-center justify-center rounded-md bg-fuchsia-500 px-4 text-sm font-medium shadow-md shadow-fuchsia-900/50 hover:bg-fuchsia-600 disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50"
|
||||||
|
>
|
||||||
<span className="text-white drop-shadow">Send</span>
|
<span className="text-white drop-shadow">Send</span>
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
@ -12,13 +12,10 @@ export const UserBase = memo(function UserBase({ pubkey }: { pubkey: string }) {
|
|||||||
|
|
||||||
const cacheProfile = useCallback(
|
const cacheProfile = useCallback(
|
||||||
async (event) => {
|
async (event) => {
|
||||||
const metadata: any = JSON.parse(event.content);
|
|
||||||
// insert to database
|
// insert to database
|
||||||
await db.execute(
|
await db.execute('INSERT OR IGNORE INTO cache_profiles (id, metadata) VALUES (?, ?);', [pubkey, event.content]);
|
||||||
`INSERT OR IGNORE INTO cache_profiles (id, metadata) VALUES ("${pubkey}", '${JSON.stringify(metadata)}')`
|
|
||||||
);
|
|
||||||
// update state
|
// update state
|
||||||
setProfile(metadata);
|
setProfile(JSON.parse(event.content));
|
||||||
},
|
},
|
||||||
[db, pubkey]
|
[db, pubkey]
|
||||||
);
|
);
|
||||||
|
@ -17,13 +17,10 @@ export const UserExtend = memo(function UserExtend({ pubkey, time }: { pubkey: s
|
|||||||
|
|
||||||
const insertCacheProfile = useCallback(
|
const insertCacheProfile = useCallback(
|
||||||
async (event) => {
|
async (event) => {
|
||||||
const metadata: any = JSON.parse(event.content);
|
|
||||||
// insert to database
|
// insert to database
|
||||||
await db.execute(
|
await db.execute('INSERT OR IGNORE INTO cache_profiles (id, metadata) VALUES (?, ?);', [pubkey, event.content]);
|
||||||
`INSERT OR IGNORE INTO cache_profiles (id, metadata) VALUES ("${pubkey}", '${JSON.stringify(metadata)}')`
|
|
||||||
);
|
|
||||||
// update state
|
// update state
|
||||||
setProfile(metadata);
|
setProfile(JSON.parse(event.content));
|
||||||
},
|
},
|
||||||
[db, pubkey]
|
[db, pubkey]
|
||||||
);
|
);
|
||||||
|
@ -12,13 +12,10 @@ export const UserMini = memo(function UserMini({ pubkey }: { pubkey: string }) {
|
|||||||
|
|
||||||
const insertCacheProfile = useCallback(
|
const insertCacheProfile = useCallback(
|
||||||
async (event) => {
|
async (event) => {
|
||||||
const metadata: any = JSON.parse(event.content);
|
|
||||||
// insert to database
|
// insert to database
|
||||||
await db.execute(
|
await db.execute('INSERT OR IGNORE INTO cache_profiles (id, metadata) VALUES (?, ?);', [pubkey, event.content]);
|
||||||
`INSERT OR IGNORE INTO cache_profiles (id, metadata) VALUES ("${pubkey}", '${JSON.stringify(metadata)}')`
|
|
||||||
);
|
|
||||||
// update state
|
// update state
|
||||||
setProfile(metadata);
|
setProfile(JSON.parse(event.content));
|
||||||
},
|
},
|
||||||
[db, pubkey]
|
[db, pubkey]
|
||||||
);
|
);
|
||||||
|
Loading…
Reference in New Issue
Block a user