wip: migrate to ark

This commit is contained in:
2023-12-07 18:09:00 +07:00
parent 95124e5ded
commit 7507cd9ba1
29 changed files with 206 additions and 454 deletions

View File

@@ -1,20 +1,21 @@
import { NDKEvent, NDKKind } from '@nostr-dev-kit/ndk';
import { memo } from 'react';
import { useArk } from '@libs/ark';
import { ReplyIcon, RepostIcon } from '@shared/icons';
import { ChildNote, TextKind } from '@shared/notes';
import { User } from '@shared/user';
import { WIDGET_KIND } from '@utils/constants';
import { formatCreatedAt } from '@utils/createdAt';
import { useNostr } from '@utils/hooks/useNostr';
import { useWidget } from '@utils/hooks/useWidget';
export function NotifyNote({ event }: { event: NDKEvent }) {
const { getEventThread } = useNostr();
const { ark } = useArk();
const { addWidget } = useWidget();
const thread = getEventThread(event.tags);
const thread = ark.getEventThread({ tags: event.tags });
const createdAt = formatCreatedAt(event.created_at, false);
if (event.kind === NDKKind.Reaction) {

View File

@@ -1,38 +1,42 @@
import { NDKSubscription } from '@nostr-dev-kit/ndk';
import { useEffect, useState } from 'react';
import { useArk } from '@libs/ark';
import { LoaderIcon } from '@shared/icons';
import { Reply } from '@shared/notes';
import { useNostr } from '@utils/hooks/useNostr';
import { NDKEventWithReplies } from '@utils/types';
export function ReplyList({ eventId }: { eventId: string }) {
const { fetchAllReplies, sub } = useNostr();
const { ark } = useArk();
const [data, setData] = useState<null | NDKEventWithReplies[]>(null);
useEffect(() => {
let sub: NDKSubscription;
let isCancelled = false;
async function fetchRepliesAndSub() {
const events = await fetchAllReplies(eventId);
const events = await ark.getThreads({ id: eventId });
if (!isCancelled) {
setData(events);
}
// subscribe for new replies
sub(
{
sub = ark.subscribe({
filter: {
'#e': [eventId],
since: Math.floor(Date.now() / 1000),
},
(event: NDKEventWithReplies) => setData((prev) => [event, ...prev]),
false
);
closeOnEose: false,
cb: (event: NDKEventWithReplies) => setData((prev) => [event, ...prev]),
});
}
fetchRepliesAndSub();
return () => {
isCancelled = true;
if (sub) sub.stop();
};
}, [eventId]);
@@ -59,7 +63,7 @@ export function ReplyList({ eventId }: { eventId: string }) {
</div>
</div>
) : (
data.map((event) => <Reply key={event.id} event={event} root={eventId} />)
data.map((event) => <Reply key={event.id} event={event} />)
)}
</div>
);

View File

@@ -2,20 +2,21 @@ import { NDKEvent } from '@nostr-dev-kit/ndk';
import { memo } from 'react';
import { twMerge } from 'tailwind-merge';
import { useArk } from '@libs/ark';
import { ChildNote, NoteActions } from '@shared/notes';
import { User } from '@shared/user';
import { WIDGET_KIND } from '@utils/constants';
import { useNostr } from '@utils/hooks/useNostr';
import { useRichContent } from '@utils/hooks/useRichContent';
import { useWidget } from '@utils/hooks/useWidget';
export function TextNote({ event, className }: { event: NDKEvent; className?: string }) {
const { parsedContent } = useRichContent(event.content);
const { addWidget } = useWidget();
const { getEventThread } = useNostr();
const { ark } = useArk();
const thread = getEventThread(event.tags);
const thread = ark.getEventThread({ tags: event.tags });
return (
<div className={twMerge('mb-3 h-min w-full px-3', className)}>