added note content parser

This commit is contained in:
Ren Amamiya
2023-03-21 09:24:40 +07:00
parent b10a70b4ce
commit a17c5dfba5
6 changed files with 104 additions and 39 deletions

View File

@@ -1,23 +1,31 @@
import { Content } from '@components/note/content';
import { RootNote } from '@components/note/root';
import { memo, useEffect, useState } from 'react';
import { memo, useMemo } from 'react';
export const Note = memo(function Note({ event }: { event: any }) {
const [root, setRoot] = useState(null);
const tags = JSON.parse(event.tags);
useEffect(() => {
const fetchRootEvent = useMemo(() => {
if (tags.length > 0) {
if (tags[0][0] === 'e') {
setRoot(tags[0][1]);
return <RootNote id={tags[0][1]} />;
} else {
tags.every((tag) => {
if (tag[2] === 'root') {
return <RootNote id={tags[1]} />;
}
return <></>;
});
}
} else {
return <></>;
}
}, [tags]);
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">
{root && <RootNote id={root} />}
<>{fetchRootEvent}</>
<Content data={event} />
</div>
);