wip: refactor

This commit is contained in:
Ren Amamiya
2023-08-17 15:11:40 +07:00
parent ab61bfb2cd
commit 414dd50a5c
33 changed files with 958 additions and 648 deletions

View File

@@ -1,16 +1,16 @@
import { NDKEvent } from '@nostr-dev-kit/ndk';
import { useMemo } from 'react';
import { NoteActions, NoteContent, NoteMetadata } from '@shared/notes';
import { User } from '@shared/user';
import { parser } from '@utils/parser';
import { LumeEvent } from '@utils/types';
export function NoteKind_1({
event,
skipMetadata = false,
}: {
event: LumeEvent;
event: NDKEvent;
skipMetadata?: boolean;
}) {
const content = useMemo(() => parser(event), [event.id]);

View File

@@ -1,14 +1,14 @@
import { NDKEvent } from '@nostr-dev-kit/ndk';
import { Image } from '@shared/image';
import { NoteActions, NoteMetadata } from '@shared/notes';
import { User } from '@shared/user';
import { LumeEvent } from '@utils/types';
function isImage(url: string) {
return /\.(jpg|jpeg|gif|png|webp|avif)$/.test(url);
}
export function NoteKind_1063({ event }: { event: LumeEvent }) {
export function NoteKind_1063({ event }: { event: NDKEvent }) {
const url = event.tags[0][1];
return (

View File

@@ -1,3 +1,5 @@
import { NDKEvent } from '@nostr-dev-kit/ndk';
import {
NoteActions,
NoteContent,
@@ -8,25 +10,32 @@ import {
import { User } from '@shared/user';
import { useEvent } from '@utils/hooks/useEvent';
import { getRepostID } from '@utils/transform';
import { LumeEvent } from '@utils/types';
export function Repost({ event }: { event: LumeEvent }) {
const repostID = getRepostID(event.tags);
export function Repost({ event }: { event: NDKEvent }) {
const repostID = event.tags.find((el) => el[0] === 'e')?.[1];
const { status, data } = useEvent(repostID, event.content as unknown as string);
if (status === 'loading') {
return (
<div className="relative overflow-hidden rounded-xl bg-white/10 px-3 py-3">
<NoteSkeleton />
<div className="h-min w-full px-3 py-1.5">
<div className="relative overflow-hidden rounded-xl bg-white/10 px-3 py-3">
<NoteSkeleton />
</div>
</div>
);
}
if (status === 'error') {
return (
<div className="flex items-center justify-center overflow-hidden rounded-xl bg-white/10 px-3 py-3">
<p className="text-white/50">Failed to fetch event: {repostID}</p>
<div className="h-min w-full px-3 py-1.5">
<div className="flex flex-col gap-1 overflow-hidden rounded-xl bg-white/10 px-3 py-3">
<p className="select-text break-all text-white/50">
Failed to get repostr with ID
</p>
<div className="break-all rounded-lg bg-white/10 px-2 py-2">
<p className="text-white">{repostID}</p>
</div>
</div>
</div>
);
}

View File

@@ -1,17 +1,17 @@
import { NDKEvent } from '@nostr-dev-kit/ndk';
import { useMemo } from 'react';
import { NoteActions, NoteContent, NoteMetadata, SubNote } from '@shared/notes';
import { User } from '@shared/user';
import { parser } from '@utils/parser';
import { LumeEvent } from '@utils/types';
export function NoteThread({
event,
root,
reply,
}: {
event: LumeEvent;
event: NDKEvent;
root: string;
reply: string;
}) {

View File

@@ -1,9 +1,9 @@
import { NDKEvent } from '@nostr-dev-kit/ndk';
import { NoteActions, NoteMetadata } from '@shared/notes';
import { User } from '@shared/user';
import { LumeEvent } from '@utils/types';
export function NoteKindUnsupport({ event }: { event: LumeEvent }) {
export function NoteKindUnsupport({ event }: { event: NDKEvent }) {
return (
<div className="h-min w-full px-3 py-1.5">
<div className="relative overflow-hidden rounded-xl bg-white/10 px-3 pt-3">

View File

@@ -2,6 +2,8 @@ import { memo } from 'react';
import ReactMarkdown from 'react-markdown';
import remarkGfm from 'remark-gfm';
import { useStorage } from '@libs/storage/provider';
import { MentionUser, NoteSkeleton } from '@shared/notes';
import { User } from '@shared/user';
@@ -11,13 +13,15 @@ import { useWidgets } from '@stores/widgets';
import { useEvent } from '@utils/hooks/useEvent';
export const MentionNote = memo(function MentionNote({ id }: { id: string }) {
const { db } = useStorage();
const { status, data } = useEvent(id);
const setWidget = useWidgets((state) => state.setWidget);
const openThread = (event, thread: string) => {
const selection = window.getSelection();
if (selection.toString().length === 0) {
setWidget({ kind: widgetKinds.thread, title: 'Thread', content: thread });
setWidget(db, { kind: widgetKinds.thread, title: 'Thread', content: thread });
} else {
event.stopPropagation();
}
@@ -26,7 +30,7 @@ export const MentionNote = memo(function MentionNote({ id }: { id: string }) {
if (!id) {
return (
<div className="mb-2 mt-3 cursor-default rounded-lg bg-white/10 px-3 py-3">
<p className="break-all">Failed to fetch event: {id}</p>
<p className="break-all">Failed to get event with id: {id}</p>
</div>
);
}
@@ -64,14 +68,14 @@ export const MentionNote = memo(function MentionNote({ id }: { id: string }) {
},
}}
>
{data?.content?.original?.length > 160
? data.content.original.substring(0, 160) + '...'
: data.content.original}
{data?.content.length > 160
? data.content.substring(0, 160) + '...'
: data.content}
</ReactMarkdown>
</div>
</>
) : (
<p className="break-all">Failed to fetch event: {id}</p>
<p className="break-all">Failed to get event with id: {id}</p>
)}
</div>
);