From 4747299ade2c2a4b80d4defda2ddd5f5cfabe80d Mon Sep 17 00:00:00 2001 From: Ren Amamiya <123083837+reyamir@users.noreply.github.com> Date: Sat, 8 Jul 2023 15:21:06 +0700 Subject: [PATCH] update composer --- src/shared/composer/types/post.tsx | 51 +++++++++++++--------------- src/shared/notes/mentions/note.tsx | 2 +- src/shared/notes/metadata/repost.tsx | 16 +++++++-- src/shared/user.tsx | 4 +-- src/stores/composer.tsx | 13 ------- src/utils/hooks/useProfile.tsx | 36 ++++++++------------ 6 files changed, 54 insertions(+), 68 deletions(-) diff --git a/src/shared/composer/types/post.tsx b/src/shared/composer/types/post.tsx index 06db00ba..0ed67d1c 100644 --- a/src/shared/composer/types/post.tsx +++ b/src/shared/composer/types/post.tsx @@ -7,7 +7,7 @@ import { usePublish } from '@libs/ndk'; import { Button } from '@shared/button'; import { ImageUploader } from '@shared/composer/imageUploader'; -import { TrashIcon } from '@shared/icons'; +import { CancelIcon, TrashIcon } from '@shared/icons'; import { MentionNote } from '@shared/notes/mentions/note'; import { useComposer } from '@stores/composer'; @@ -60,9 +60,9 @@ export function Post() { const publish = usePublish(); const editor = useMemo(() => withReact(withImages(withHistory(createEditor()))), []); - const [repost, reply, toggle] = useComposer((state) => [ - state.repost, + const [reply, clearReply, toggle] = useComposer((state) => [ state.reply, + state.clearReply, state.toggleModal, ]); const [content, setContent] = useState([ @@ -79,30 +79,14 @@ export function Post() { return nodes.map((n) => Node.string(n)).join('\n'); }, []); - const getRef = () => { - if (repost.id) { - return repost.id; - } else if (reply.id) { - return reply.id; - } else { - return null; - } + const removeReply = () => { + clearReply(); }; - const refID = getRef(); - const submit = async () => { let tags: string[][] = []; - let kind: number; - if (repost.id && repost.pubkey) { - kind = 6; - tags = [ - ['e', repost.id, FULL_RELAYS[0], 'root'], - ['p', repost.pubkey], - ]; - } else if (reply.id && reply.pubkey) { - kind = 1; + if (reply.id && reply.pubkey) { if (reply.root && reply.root !== reply.id) { tags = [ ['e', reply.id, FULL_RELAYS[0], 'root'], @@ -116,7 +100,6 @@ export function Post() { ]; } } else { - kind = 1; tags = []; } @@ -124,7 +107,7 @@ export function Post() { const serializedContent = serialize(content); // publish message - await publish({ content: serializedContent, kind, tags }); + await publish({ content: serializedContent, kind: 1, tags }); // close modal toggle(false); @@ -151,14 +134,28 @@ export function Post() {
- {refID && } + {reply.id && ( +
+ + +
+ )}
diff --git a/src/shared/notes/mentions/note.tsx b/src/shared/notes/mentions/note.tsx index dc58eaae..671412c7 100644 --- a/src/shared/notes/mentions/note.tsx +++ b/src/shared/notes/mentions/note.tsx @@ -45,7 +45,7 @@ export const MentionNote = memo(function MentionNote({ id }: { id: string }) { ) : status === 'success' ? ( <> -
+
{data.kind === 1 && } {data.kind === 1063 && } {data.kind !== 1 && data.kind !== 1063 && ( diff --git a/src/shared/notes/metadata/repost.tsx b/src/shared/notes/metadata/repost.tsx index 36d66978..ff9b8000 100644 --- a/src/shared/notes/metadata/repost.tsx +++ b/src/shared/notes/metadata/repost.tsx @@ -1,8 +1,10 @@ import * as Tooltip from '@radix-ui/react-tooltip'; +import { usePublish } from '@libs/ndk'; + import { RepostIcon } from '@shared/icons'; -import { useComposer } from '@stores/composer'; +import { FULL_RELAYS } from '@stores/constants'; import { compactNumber } from '@utils/number'; @@ -15,13 +17,21 @@ export function NoteRepost({ pubkey: string; reposts: number; }) { - const setRepost = useComposer((state) => state.setRepost); + const publish = usePublish(); + + const submit = async () => { + const tags = [ + ['e', id, FULL_RELAYS[0], 'root'], + ['p', pubkey], + ]; + await publish({ content: '', kind: 6, tags: tags }); + }; return (