From d87ca7b75b6a03156b42c21c33610e2d625ff513 Mon Sep 17 00:00:00 2001 From: Ren Amamiya <123083837+reyamir@users.noreply.github.com> Date: Sun, 18 Jun 2023 15:55:07 +0700 Subject: [PATCH] update repost --- src/app/chat/components/item.tsx | 2 +- src/shared/composer/modal.tsx | 28 +++++++++----------- src/shared/composer/types/post.tsx | 31 +++++++++++++++++----- src/shared/navigation.tsx | 14 +++++----- src/shared/notes/kind1.tsx | 8 ++++-- src/shared/notes/metadata/repost.tsx | 39 +++------------------------- src/shared/user.tsx | 6 +++-- src/stores/composer.tsx | 20 ++++++++++++++ src/stores/constants.tsx | 2 +- 9 files changed, 79 insertions(+), 71 deletions(-) create mode 100644 src/stores/composer.tsx diff --git a/src/app/chat/components/item.tsx b/src/app/chat/components/item.tsx index 4455002b..a4950060 100644 --- a/src/app/chat/components/item.tsx +++ b/src/app/chat/components/item.tsx @@ -36,7 +36,7 @@ export function ChatsListItem({ data }: { data: any }) { {data.sender_pubkey}
diff --git a/src/shared/composer/modal.tsx b/src/shared/composer/modal.tsx index b713935e..ef9b6e65 100644 --- a/src/shared/composer/modal.tsx +++ b/src/shared/composer/modal.tsx @@ -8,33 +8,31 @@ import { ComposeIcon, } from "@shared/icons"; import { useActiveAccount } from "@stores/accounts"; -import { Fragment, useState } from "react"; - -export function ComposerModal() { - const [isOpen, setIsOpen] = useState(false); - const [composer] = useState({ type: "post" }); +import { useComposer } from "@stores/composer"; +import { Fragment } from "react"; +export function Composer() { const account = useActiveAccount((state: any) => state.account); + const [toggle, open] = useComposer((state: any) => [ + state.toggleModal, + state.open, + ]); const closeModal = () => { - setIsOpen(false); - }; - - const openModal = () => { - setIsOpen(true); + toggle(false); }; return ( <> - + -
+
New Post
@@ -85,9 +83,7 @@ export function ComposerModal() { />
- {composer.type === "post" && account && ( - - )} + diff --git a/src/shared/composer/types/post.tsx b/src/shared/composer/types/post.tsx index 7bc86526..46fbdb09 100644 --- a/src/shared/composer/types/post.tsx +++ b/src/shared/composer/types/post.tsx @@ -1,7 +1,9 @@ import { NDKEvent, NDKPrivateKeySigner } from "@nostr-dev-kit/ndk"; import { ImageUploader } from "@shared/composer/imageUploader"; import { TrashIcon } from "@shared/icons"; +import { MentionNote } from "@shared/notes/mentions/note"; import { RelayContext } from "@shared/relayProvider"; +import { useComposer } from "@stores/composer"; import { dateToUnix } from "@utils/date"; import { useCallback, useContext, useMemo, useState } from "react"; import { Node, Transforms, createEditor } from "slate"; @@ -59,7 +61,10 @@ const ImagePreview = ({ export function Post({ pubkey, privkey }: { pubkey: string; privkey: string }) { const ndk = useContext(RelayContext); - + const [repost, toggle] = useComposer((state: any) => [ + state.repost, + state.toggle, + ]); const editor = useMemo( () => withReact(withImages(withHistory(createEditor()))), [], @@ -87,14 +92,25 @@ export function Post({ pubkey, privkey }: { pubkey: string; privkey: string }) { ndk.signer = signer; const event = new NDKEvent(ndk); - event.kind = 1; event.content = serializedContent; event.created_at = dateToUnix(); event.pubkey = pubkey; - event.tags = []; + if (repost.id && repost.pubkey) { + event.kind = 6; + event.tags = [ + ["e", repost.id], + ["p", repost.pubkey], + ]; + } else { + event.kind = 1; + event.tags = []; + } // publish event event.publish(); + + // close modal + toggle(false); }; const renderElement = useCallback((props: any) => { @@ -115,17 +131,20 @@ export function Post({ pubkey, privkey }: { pubkey: string; privkey: string }) {
-
+
+ {repost.id && }
-
+
); diff --git a/src/shared/user.tsx b/src/shared/user.tsx index 104db9bb..297cd5ae 100644 --- a/src/shared/user.tsx +++ b/src/shared/user.tsx @@ -27,12 +27,14 @@ export function User({ }`} > {pubkey}
diff --git a/src/stores/composer.tsx b/src/stores/composer.tsx new file mode 100644 index 00000000..77b58ec8 --- /dev/null +++ b/src/stores/composer.tsx @@ -0,0 +1,20 @@ +import { create } from "zustand"; + +export const useComposer = create((set) => ({ + open: false, + repost: { id: null, pubkey: null }, + reply: null, + toggleModal: (status: boolean) => { + set({ open: status }); + if (!status) { + set({ repost: { id: null, pubkey: null } }); + } + }, + setRepost: (id: string, pubkey: string) => { + set({ repost: { id: id, pubkey: pubkey } }); + set({ open: true }); + }, + clearRepost: () => { + set({ repost: { id: null, pubkey: null } }); + }, +})); diff --git a/src/stores/constants.tsx b/src/stores/constants.tsx index 58ac036d..d6b4c69d 100644 --- a/src/stores/constants.tsx +++ b/src/stores/constants.tsx @@ -1,6 +1,6 @@ export const APP_VERSION = "1.0.0"; -export const DEFAULT_AVATAR = "https://void.cat/d/PZcdCxNc24rCCxV8QXbdFQ"; +export const DEFAULT_AVATAR = "https://void.cat/d/5VKmKyuHyxrNMf9bWSVPih"; export const OPENGRAPH_KEY = "9EJG4SY-19Q4M5J-H8R29C9-091XPCC";