From 797d66515021a181ba7b8bc9ca92aab0bda6c4cd Mon Sep 17 00:00:00 2001 From: "plebeius.eth" Date: Fri, 17 May 2024 14:56:09 +0200 Subject: [PATCH] feat(post form): enable posting from p/all or p/subscriptions --- src/components/post-form/post-form.tsx | 38 +++++++++++++++++++++++--- 1 file changed, 34 insertions(+), 4 deletions(-) diff --git a/src/components/post-form/post-form.tsx b/src/components/post-form/post-form.tsx index b008f362..18ba1ad5 100644 --- a/src/components/post-form/post-form.tsx +++ b/src/components/post-form/post-form.tsx @@ -3,13 +3,14 @@ import { useTranslation } from 'react-i18next'; import { useLocation, useNavigate, useParams } from 'react-router-dom'; import { PublishCommentOptions, setAccount, useAccount, useAccountComment, useComment, usePublishComment } from '@plebbit/plebbit-react-hooks'; import { create } from 'zustand'; -import styles from './post-form.module.css'; import { alertChallengeVerificationFailed } from '../../lib/utils/challenge-utils'; import { getLinkMediaInfo } from '../../lib/utils/media-utils'; import { isValidURL } from '../../lib/utils/url-utils'; -import { isDescriptionView, isPostPageView, isRulesView } from '../../lib/utils/view-utils'; +import { isAllView, isDescriptionView, isPostPageView, isRulesView, isSubscriptionsView } from '../../lib/utils/view-utils'; import challengesStore from '../../hooks/use-challenges'; +import { useDefaultSubplebbitAddresses } from '../../hooks/use-default-subplebbits'; import useReply from '../../hooks/use-reply'; +import styles from './post-form.module.css'; import _ from 'lodash'; type SubmitState = { @@ -70,6 +71,12 @@ const PostFormTable = ({ closeForm }: { closeForm: () => void }) => { const urlRef = useRef(null); const subjectRef = useRef(null); + const location = useLocation(); + const isInAllView = isAllView(location.pathname); + const isInSubscriptionsView = isSubscriptionsView(location.pathname); + const subscriptions = account?.subscriptions || []; + const defaultSubplebbitAddresses = useDefaultSubplebbitAddresses(); + const resetFields = () => { if (textRef.current) { textRef.current.value = ''; @@ -115,7 +122,6 @@ const PostFormTable = ({ closeForm }: { closeForm: () => void }) => { }, [index, resetSubmitStore, navigate]); // in post page, publish a reply to the post - const location = useLocation(); const isInPostPage = isPostPageView(location.pathname, params); const cid = params?.commentCid as string; const { setContent, resetContent, replyIndex, publishReply } = useReply({ cid, subplebbitAddress }); @@ -144,6 +150,8 @@ const PostFormTable = ({ closeForm }: { closeForm: () => void }) => { } }, [replyIndex, resetContent]); + console.log(publishCommentOptions.subplebbitAddress); + return ( @@ -212,6 +220,28 @@ const PostFormTable = ({ closeForm }: { closeForm: () => void }) => { + {(isInAllView || isInSubscriptionsView) && ( + + + + + )}
{t('board')} + +
); @@ -221,8 +251,8 @@ const PostForm = () => { const { t } = useTranslation(); const location = useLocation(); const params = useParams(); - const isInPostPage = isPostPageView(location.pathname, params); const isInDescriptionView = isDescriptionView(location.pathname, params); + const isInPostPage = isPostPageView(location.pathname, params); const isInRulesView = isRulesView(location.pathname, params); const comment = useComment({ commentCid: useParams().commentCid });