diff --git a/src/components/post-desktop/post-desktop.tsx b/src/components/post-desktop/post-desktop.tsx index be9a752b..adb59a5b 100644 --- a/src/components/post-desktop/post-desktop.tsx +++ b/src/components/post-desktop/post-desktop.tsx @@ -147,7 +147,7 @@ const PostInfo = ({ openReplyModal, post, postReplyCount = 0, roles, isHidden }: !cid && e.preventDefault()}> c/ - openReplyModal && openReplyModal(cid, postCid)}> + openReplyModal && openReplyModal(cid, postCid, subplebbitAddress)}> {shortCid} diff --git a/src/components/post-mobile/post-mobile.tsx b/src/components/post-mobile/post-mobile.tsx index 0854ac03..a77f9b2c 100644 --- a/src/components/post-mobile/post-mobile.tsx +++ b/src/components/post-mobile/post-mobile.tsx @@ -136,7 +136,7 @@ const PostInfoAndMedia = ({ openReplyModal, post, postReplyCount = 0, roles }: P !cid && e.preventDefault()}> c/ - openReplyModal && openReplyModal(cid, postCid)}> + openReplyModal && openReplyModal(cid, postCid, subplebbitAddress)}> {shortCid} diff --git a/src/components/reply-modal/reply-modal.tsx b/src/components/reply-modal/reply-modal.tsx index efdc50e3..fb047814 100644 --- a/src/components/reply-modal/reply-modal.tsx +++ b/src/components/reply-modal/reply-modal.tsx @@ -21,11 +21,11 @@ interface ReplyModalProps { parentCid: string; postCid: string; scrollY: number; + subplebbitAddress: string; } -const ReplyModal = ({ closeModal, showReplyModal, parentCid, postCid, scrollY }: ReplyModalProps) => { +const ReplyModal = ({ closeModal, showReplyModal, parentCid, postCid, scrollY, subplebbitAddress }: ReplyModalProps) => { const { t } = useTranslation(); - const { subplebbitAddress } = useParams() as { subplebbitAddress: string }; const { setPublishReplyOptions, publishReply } = usePublishReply({ cid: parentCid, subplebbitAddress }); const account = useAccount(); const { displayName } = account?.author || {}; diff --git a/src/hooks/use-reply-modal.ts b/src/hooks/use-reply-modal.ts index 861bc416..e4f56301 100644 --- a/src/hooks/use-reply-modal.ts +++ b/src/hooks/use-reply-modal.ts @@ -6,6 +6,7 @@ const useReplyModal = () => { const [showReplyModal, setShowReplyModal] = useState(false); const [activeCid, setActiveCid] = useState(null); const [threadCid, setThreadCid] = useState(null); + const [subplebbitAddress, setSubplebbitAddress] = useState(null); const { resetSelectedText, setSelectedText } = useSelectedTextStore(); // on mobile, the css position is absolute instead of fixed, so we need to calculate the top position @@ -23,7 +24,7 @@ const useReplyModal = () => { text && setSelectedText(`>${text}\n`); }; - const openReplyModal = (parentCid: string, postCid: string) => { + const openReplyModal = (parentCid: string, postCid: string, subplebbitAddress: string) => { getSelectedText(); if (isMobile) { @@ -37,9 +38,10 @@ const useReplyModal = () => { setActiveCid(parentCid); setThreadCid(postCid); setShowReplyModal(true); + setSubplebbitAddress(subplebbitAddress); }; - return { activeCid, threadCid, closeModal, openReplyModal, scrollY, showReplyModal }; + return { activeCid, threadCid, closeModal, openReplyModal, scrollY, showReplyModal, subplebbitAddress }; }; export default useReplyModal; diff --git a/src/views/board/board.tsx b/src/views/board/board.tsx index 64036b43..290a5730 100644 --- a/src/views/board/board.tsx +++ b/src/views/board/board.tsx @@ -104,7 +104,7 @@ const Board = () => { const { createdAt, description, error, rules, shortAddress, state, suggested } = subplebbit || {}; const title = isInAllView ? t('all') : isInSubscriptionsView ? t('subscriptions') : subplebbit?.title; - const { activeCid, threadCid, closeModal, openReplyModal, showReplyModal, scrollY } = useReplyModal(); + const { activeCid, threadCid, closeModal, openReplyModal, showReplyModal, scrollY, subplebbitAddress: postSubplebbitAddress } = useReplyModal(); const { blocked, unblock } = useBlock({ address: subplebbitAddress }); const loadingStateString = useFeedStateString(subplebbitAddresses) || t('loading'); @@ -158,7 +158,16 @@ const Board = () => { return (
{location.pathname.endsWith('/settings') && } - {activeCid && threadCid && } + {activeCid && threadCid && postSubplebbitAddress && ( + + )} {feed.length !== 0 ? ( <> {rules && rules.length > 0 && } diff --git a/src/views/post/post.tsx b/src/views/post/post.tsx index 0f4cf02a..f62a4a85 100644 --- a/src/views/post/post.tsx +++ b/src/views/post/post.tsx @@ -22,7 +22,7 @@ export interface PostProps { roles?: Role[]; showAllReplies?: boolean; showReplies?: boolean; - openReplyModal?: (parentCid: string, postCid: string) => void; + openReplyModal?: (parentCid: string, postCid: string, subplebbitAddress: string) => void; } export const Post = ({ post, showAllReplies = false, showReplies = true, openReplyModal }: PostProps) => { @@ -62,7 +62,7 @@ const PostPage = () => { const subplebbit = useSubplebbit({ subplebbitAddress }); const { createdAt, description, rules, shortAddress, suggested, title } = subplebbit; - const { activeCid, threadCid, closeModal, openReplyModal, showReplyModal, scrollY } = useReplyModal(); + const { activeCid, threadCid, closeModal, openReplyModal, showReplyModal, scrollY, subplebbitAddress: postSubplebbitAddress } = useReplyModal(); const comment = useComment({ commentCid }); @@ -91,7 +91,16 @@ const PostPage = () => { return (
{isInSettigsView && } - {activeCid && threadCid && } + {activeCid && threadCid && postSubplebbitAddress && ( + + )} {/* TODO: remove this replyCount error once api supports scrolling replies pages */} {replyCount > 60 && Error: this thread has too many replies, some of them cannot be displayed right now.} {error && Error: {error.message}}