feat(post form): enable posting from p/all or p/subscriptions

This commit is contained in:
plebeius.eth
2024-05-17 14:56:09 +02:00
parent 11d1424c0a
commit 797d665150
+34 -4
View File
@@ -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<HTMLInputElement>(null);
const subjectRef = useRef<HTMLInputElement>(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 (
<table className={styles.postFormTable}>
<tbody>
@@ -212,6 +220,28 @@ const PostFormTable = ({ closeForm }: { closeForm: () => void }) => {
</span>
</td>
</tr>
{(isInAllView || isInSubscriptionsView) && (
<tr>
<td>{t('board')}</td>
<td>
<select onChange={(e) => setSubmitStore({ subplebbitAddress: e.target.value })} value={subplebbitAddress}>
<option value=''>--no board selected--</option>
{isInAllView &&
defaultSubplebbitAddresses.map((address: string) => (
<option key={address} value={address}>
{address}
</option>
))}
{isInSubscriptionsView &&
subscriptions.map((sub: string) => (
<option key={sub} value={sub}>
{sub}
</option>
))}
</select>
</td>
</tr>
)}
</tbody>
</table>
);
@@ -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 });