fixed note
This commit is contained in:
@@ -25,7 +25,7 @@ export const NoteConnector = memo(function NoteConnector() {
|
|||||||
// insert to local database
|
// insert to local database
|
||||||
await db.execute(
|
await db.execute(
|
||||||
'INSERT OR IGNORE INTO cache_notes (id, pubkey, created_at, kind, content, tags) VALUES (?, ?, ?, ?, ?, ?);',
|
'INSERT OR IGNORE INTO cache_notes (id, pubkey, created_at, kind, content, tags) VALUES (?, ?, ?, ?, ?, ?);',
|
||||||
[event.id, event.pubkey, event.created_at, event.kind, event.content, String(event.tags)]
|
[event.id, event.pubkey, event.created_at, event.kind, event.content, JSON.stringify(event.tags)]
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
[db]
|
[db]
|
||||||
|
|||||||
@@ -10,8 +10,7 @@ export const Content = memo(function Content({ data }: { data: any }) {
|
|||||||
const content = useMemo(() => {
|
const content = useMemo(() => {
|
||||||
let parsedContent;
|
let parsedContent;
|
||||||
// get data tags
|
// get data tags
|
||||||
const tags = String(data.tags).replaceAll("'", '"');
|
const tags = JSON.parse(data.tags);
|
||||||
const parseTags = JSON.parse(tags);
|
|
||||||
// remove all image urls
|
// remove all image urls
|
||||||
parsedContent = data.content.replace(/(https?:\/\/.*\.(jpg|jpeg|gif|png|webp|mp4|webm)((\?.*)$|$))/gim, '');
|
parsedContent = data.content.replace(/(https?:\/\/.*\.(jpg|jpeg|gif|png|webp|mp4|webm)((\?.*)$|$))/gim, '');
|
||||||
// handle urls
|
// handle urls
|
||||||
@@ -27,10 +26,10 @@ export const Content = memo(function Content({ data }: { data: any }) {
|
|||||||
</span>
|
</span>
|
||||||
));
|
));
|
||||||
// handle mentions
|
// handle mentions
|
||||||
if (parseTags.length > 0) {
|
if (tags.length > 0) {
|
||||||
parsedContent = reactStringReplace(parsedContent, /\#\[(\d+)\]/gm, (match, i) => {
|
parsedContent = reactStringReplace(parsedContent, /\#\[(\d+)\]/gm, (match, i) => {
|
||||||
if (parseTags[match][0] === 'p') {
|
if (tags[match][0] === 'p') {
|
||||||
return <UserMention key={match + i} pubkey={parseTags[match][1]} />;
|
return <UserMention key={match + i} pubkey={tags[match][1]} />;
|
||||||
} else {
|
} else {
|
||||||
// #TODO: handle mention other note
|
// #TODO: handle mention other note
|
||||||
// console.log(tags[match]);
|
// console.log(tags[match]);
|
||||||
|
|||||||
@@ -4,17 +4,16 @@ import { RootNote } from '@components/note/root';
|
|||||||
import { memo, useMemo } from 'react';
|
import { memo, useMemo } from 'react';
|
||||||
|
|
||||||
export const Note = memo(function Note({ event }: { event: any }) {
|
export const Note = memo(function Note({ event }: { event: any }) {
|
||||||
const tags = event.tags.replaceAll("'", '"');
|
const tags = JSON.parse(event.tags);
|
||||||
const parseTags = JSON.parse(tags);
|
|
||||||
|
|
||||||
const fetchRootEvent = useMemo(() => {
|
const fetchRootEvent = useMemo(() => {
|
||||||
if (parseTags.length > 0) {
|
if (tags.length > 0) {
|
||||||
if (parseTags[0][0] === 'e' || parseTags[0][2] === 'root') {
|
if (tags[0][0] === 'e' || tags[0][2] === 'root') {
|
||||||
return <RootNote id={parseTags[0][1]} />;
|
return <RootNote id={tags[0][1]} />;
|
||||||
} else {
|
} else {
|
||||||
parseTags.every((tag) => {
|
tags.every((tag) => {
|
||||||
if (tag[0] === 'e' && tag[2] === 'root') {
|
if (tag[0] === 'e' && tag[2] === 'root') {
|
||||||
return <RootNote id={parseTags[1]} />;
|
return <RootNote id={tags[1]} />;
|
||||||
}
|
}
|
||||||
return <></>;
|
return <></>;
|
||||||
});
|
});
|
||||||
@@ -22,7 +21,7 @@ export const Note = memo(function Note({ event }: { event: any }) {
|
|||||||
} else {
|
} else {
|
||||||
return <></>;
|
return <></>;
|
||||||
}
|
}
|
||||||
}, [parseTags]);
|
}, [tags]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="relative z-10 flex h-min min-h-min w-full cursor-pointer select-text flex-col border-b border-zinc-800 py-5 px-3 hover:bg-black/20">
|
<div className="relative z-10 flex h-min min-h-min w-full cursor-pointer select-text flex-col border-b border-zinc-800 py-5 px-3 hover:bg-black/20">
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ export const RootNote = memo(function RootNote({ id }: { id: string }) {
|
|||||||
// insert to local database
|
// insert to local database
|
||||||
await db.execute(
|
await db.execute(
|
||||||
'INSERT OR IGNORE INTO cache_notes (id, pubkey, created_at, kind, content, tags, is_root) VALUES (?, ?, ?, ?, ?, ?, ?);',
|
'INSERT OR IGNORE INTO cache_notes (id, pubkey, created_at, kind, content, tags, is_root) VALUES (?, ?, ?, ?, ?, ?, ?);',
|
||||||
[event.id, event.pubkey, event.created_at, event.kind, event.content, String(event.tags), 1]
|
[event.id, event.pubkey, event.created_at, event.kind, event.content, JSON.stringify(event.tags), 1]
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
[db]
|
[db]
|
||||||
|
|||||||
Reference in New Issue
Block a user