This commit is contained in:
2023-12-10 08:39:40 +07:00
parent 38e82a4feb
commit 72a38e3aa7
9 changed files with 398 additions and 388 deletions

View File

@@ -72,6 +72,7 @@ export function FollowScreen() {
if (item.startsWith('npub1')) return ['p', nip19.decode(item).data as string];
return ['p', item];
}),
publish: true,
});
if (publish) {
@@ -80,6 +81,7 @@ export function FollowScreen() {
return item;
});
setLoading(false);
return navigate('/auth/finish');
}
} catch (e) {

View File

@@ -7,7 +7,7 @@ import { EditorContent, useEditor } from '@tiptap/react';
import StarterKit from '@tiptap/starter-kit';
import { convert } from 'html-to-text';
import { nip19 } from 'nostr-tools';
import { useEffect, useLayoutEffect, useRef, useState } from 'react';
import { useLayoutEffect, useRef, useState } from 'react';
import { useNavigate, useSearchParams } from 'react-router-dom';
import { toast } from 'sonner';
@@ -81,32 +81,23 @@ export function NewPostScreen() {
],
});
const event = new NDKEvent();
event.content = serializedContent;
event.kind = NDKKind.Text;
// add reply to tags if present
const replyTo = searchParams.get('replyTo');
const rootReplyTo = searchParams.get('rootReplyTo');
if (rootReplyTo) {
const rootEvent = await ndk.fetchEvent(rootReplyTo);
event.tag(rootEvent, 'root');
}
if (replyTo) {
const replyEvent = await ndk.fetchEvent(replyTo);
event.tag(replyEvent, 'reply');
}
// publish event
const publishedRelays = await ark.createEvent({
const event = (await ark.createEvent({
kind: NDKKind.Text,
tags: [],
content: serializedContent,
});
replyTo,
rootReplyTo,
})) as NDKEvent;
if (publishedRelays) {
toast.success(`Broadcasted to ${publishedRelays.size} relays successfully.`);
const publish = await event.publish();
if (publish) {
toast.success(`Broadcasted to ${publish.size} relays successfully.`);
// update state
setLoading(false);
@@ -135,10 +126,6 @@ export function NewPostScreen() {
setHeight(containerRef.current.clientHeight);
}, []);
useEffect(() => {
if (editor) editor.commands.focus('end');
}, [editor]);
return (
<div className="flex flex-1 flex-col gap-4">
<div className="flex-1 overflow-y-auto">

View File

@@ -62,14 +62,14 @@ export function NewPrivkeyScreen() {
<button
type="button"
onClick={() => submit()}
className="inline-flex h-9 w-full shrink-0 items-center justify-center rounded-lg bg-blue-500 font-semibold text-white hover:bg-blue-600"
className="inline-flex h-11 w-full shrink-0 items-center justify-center rounded-lg bg-blue-500 font-semibold text-white hover:bg-blue-600"
>
Submit
</button>
<button
type="button"
onClick={() => submit(true)}
className="inline-flex h-9 w-full shrink-0 items-center justify-center rounded-lg bg-neutral-100 font-medium text-neutral-900 hover:bg-neutral-200 dark:bg-neutral-900 dark:text-neutral-100 dark:hover:bg-neutral-800"
className="inline-flex h-11 w-full shrink-0 items-center justify-center rounded-lg bg-neutral-100 font-medium text-neutral-900 hover:bg-neutral-200 dark:bg-neutral-900 dark:text-neutral-100 dark:hover:bg-neutral-800"
>
Submit and Save
</button>

View File

@@ -192,6 +192,7 @@ export class Ark {
public updateNostrSigner({ signer }: { signer: NDKNip46Signer | NDKPrivateKeySigner }) {
this.#ndk.signer = signer;
this.readyToSign = true;
return this.#ndk.signer;
}
@@ -418,11 +419,15 @@ export class Ark {
kind,
tags,
content,
rootReplyTo = undefined,
replyTo = undefined,
publish,
}: {
kind: NDKKind | number;
tags: NDKTag[];
content?: string;
rootReplyTo?: string;
replyTo?: string;
publish?: boolean;
}) {
try {
@@ -431,6 +436,16 @@ export class Ark {
event.kind = kind;
event.tags = tags;
if (rootReplyTo) {
const rootEvent = await this.#ndk.fetchEvent(rootReplyTo);
if (rootEvent) event.tag(rootEvent, 'root');
}
if (replyTo) {
const replyEvent = await this.#ndk.fetchEvent(replyTo);
if (replyEvent) event.tag(replyEvent, 'reply');
}
if (publish) {
const publishedEvent = await event.publish();
if (!publishedEvent) throw new Error('Failed to publish event');
@@ -888,9 +903,9 @@ export class Ark {
public async replyTo({ content, event }: { content: string; event: NDKEvent }) {
try {
const replyEvent = new NDKEvent(this.#ndk);
event.content = content;
event.kind = NDKKind.Text;
event.tag(event, 'reply');
replyEvent.content = content;
replyEvent.kind = NDKKind.Text;
replyEvent.tag(event, 'reply');
return await replyEvent.publish();
} catch (e) {

View File

@@ -8,7 +8,13 @@ import { User } from '@shared/user';
import { NDKEventWithReplies } from '@utils/types';
export function Reply({ event }: { event: NDKEventWithReplies }) {
export function Reply({
event,
rootEvent,
}: {
event: NDKEventWithReplies;
rootEvent: string;
}) {
const [open, setOpen] = useState(false);
return (
@@ -30,7 +36,7 @@ export function Reply({ event }: { event: NDKEventWithReplies }) {
</div>
</Collapsible.Trigger>
) : null}
<NoteActions event={event} canOpenEvent={false} />
<NoteActions event={event} rootEventId={rootEvent} canOpenEvent={false} />
</div>
</div>
<div className={twMerge('px-3', open ? 'pb-3' : '')}>

View File

@@ -63,7 +63,7 @@ export function ReplyList({ eventId }: { eventId: string }) {
</div>
</div>
) : (
data.map((event) => <Reply key={event.id} event={event} />)
data.map((event) => <Reply key={event.id} event={event} rootEvent={eventId} />)
)}
</div>
);