mirror of
https://github.com/bitsocialnet/5chan.git
synced 2026-08-03 07:41:04 +02:00
feat(post form): enable posting from p/all or p/subscriptions
This commit is contained in:
@@ -3,13 +3,14 @@ import { useTranslation } from 'react-i18next';
|
|||||||
import { useLocation, useNavigate, useParams } from 'react-router-dom';
|
import { useLocation, useNavigate, useParams } from 'react-router-dom';
|
||||||
import { PublishCommentOptions, setAccount, useAccount, useAccountComment, useComment, usePublishComment } from '@plebbit/plebbit-react-hooks';
|
import { PublishCommentOptions, setAccount, useAccount, useAccountComment, useComment, usePublishComment } from '@plebbit/plebbit-react-hooks';
|
||||||
import { create } from 'zustand';
|
import { create } from 'zustand';
|
||||||
import styles from './post-form.module.css';
|
|
||||||
import { alertChallengeVerificationFailed } from '../../lib/utils/challenge-utils';
|
import { alertChallengeVerificationFailed } from '../../lib/utils/challenge-utils';
|
||||||
import { getLinkMediaInfo } from '../../lib/utils/media-utils';
|
import { getLinkMediaInfo } from '../../lib/utils/media-utils';
|
||||||
import { isValidURL } from '../../lib/utils/url-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 challengesStore from '../../hooks/use-challenges';
|
||||||
|
import { useDefaultSubplebbitAddresses } from '../../hooks/use-default-subplebbits';
|
||||||
import useReply from '../../hooks/use-reply';
|
import useReply from '../../hooks/use-reply';
|
||||||
|
import styles from './post-form.module.css';
|
||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
|
|
||||||
type SubmitState = {
|
type SubmitState = {
|
||||||
@@ -70,6 +71,12 @@ const PostFormTable = ({ closeForm }: { closeForm: () => void }) => {
|
|||||||
const urlRef = useRef<HTMLInputElement>(null);
|
const urlRef = useRef<HTMLInputElement>(null);
|
||||||
const subjectRef = 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 = () => {
|
const resetFields = () => {
|
||||||
if (textRef.current) {
|
if (textRef.current) {
|
||||||
textRef.current.value = '';
|
textRef.current.value = '';
|
||||||
@@ -115,7 +122,6 @@ const PostFormTable = ({ closeForm }: { closeForm: () => void }) => {
|
|||||||
}, [index, resetSubmitStore, navigate]);
|
}, [index, resetSubmitStore, navigate]);
|
||||||
|
|
||||||
// in post page, publish a reply to the post
|
// in post page, publish a reply to the post
|
||||||
const location = useLocation();
|
|
||||||
const isInPostPage = isPostPageView(location.pathname, params);
|
const isInPostPage = isPostPageView(location.pathname, params);
|
||||||
const cid = params?.commentCid as string;
|
const cid = params?.commentCid as string;
|
||||||
const { setContent, resetContent, replyIndex, publishReply } = useReply({ cid, subplebbitAddress });
|
const { setContent, resetContent, replyIndex, publishReply } = useReply({ cid, subplebbitAddress });
|
||||||
@@ -144,6 +150,8 @@ const PostFormTable = ({ closeForm }: { closeForm: () => void }) => {
|
|||||||
}
|
}
|
||||||
}, [replyIndex, resetContent]);
|
}, [replyIndex, resetContent]);
|
||||||
|
|
||||||
|
console.log(publishCommentOptions.subplebbitAddress);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<table className={styles.postFormTable}>
|
<table className={styles.postFormTable}>
|
||||||
<tbody>
|
<tbody>
|
||||||
@@ -212,6 +220,28 @@ const PostFormTable = ({ closeForm }: { closeForm: () => void }) => {
|
|||||||
</span>
|
</span>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</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>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
);
|
);
|
||||||
@@ -221,8 +251,8 @@ const PostForm = () => {
|
|||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const location = useLocation();
|
const location = useLocation();
|
||||||
const params = useParams();
|
const params = useParams();
|
||||||
const isInPostPage = isPostPageView(location.pathname, params);
|
|
||||||
const isInDescriptionView = isDescriptionView(location.pathname, params);
|
const isInDescriptionView = isDescriptionView(location.pathname, params);
|
||||||
|
const isInPostPage = isPostPageView(location.pathname, params);
|
||||||
const isInRulesView = isRulesView(location.pathname, params);
|
const isInRulesView = isRulesView(location.pathname, params);
|
||||||
|
|
||||||
const comment = useComment({ commentCid: useParams().commentCid });
|
const comment = useComment({ commentCid: useParams().commentCid });
|
||||||
|
|||||||
Reference in New Issue
Block a user