2024-03-22 12:22:20 +01:00
|
|
|
import { useState } from 'react';
|
2024-03-20 13:08:08 +01:00
|
|
|
import { useTranslation } from 'react-i18next';
|
2024-04-03 22:52:27 +02:00
|
|
|
import { useLocation, useParams } from 'react-router-dom';
|
2024-04-08 17:13:02 +02:00
|
|
|
import { useComment } from '@plebbit/plebbit-react-hooks';
|
2024-04-08 17:32:12 +02:00
|
|
|
import { isDescriptionView, isPostPageView, isRulesView } from '../../lib/utils/view-utils';
|
2024-04-08 17:13:02 +02:00
|
|
|
import styles from './post-form.module.css';
|
2024-03-20 13:00:11 +01:00
|
|
|
|
2024-04-08 17:13:02 +02:00
|
|
|
const PostForm = () => {
|
2024-03-20 13:08:08 +01:00
|
|
|
const { t } = useTranslation();
|
2024-04-08 17:32:12 +02:00
|
|
|
const location = useLocation();
|
|
|
|
|
const params = useParams();
|
|
|
|
|
const isInPostPage = isPostPageView(location.pathname, params);
|
|
|
|
|
const isInDescriptionView = isDescriptionView(location.pathname, params);
|
|
|
|
|
const isInRulesView = isRulesView(location.pathname, params);
|
|
|
|
|
|
|
|
|
|
const { subplebbitAddress, commentCid } = params || {};
|
2024-04-08 17:13:02 +02:00
|
|
|
|
|
|
|
|
const comment = useComment({ commentCid });
|
|
|
|
|
const { deleted, locked, removed } = comment || {};
|
2024-04-08 17:32:12 +02:00
|
|
|
const isThreadClosed = deleted || locked || removed || isInDescriptionView || isInRulesView;
|
2024-04-08 17:13:02 +02:00
|
|
|
|
2024-03-22 12:22:20 +01:00
|
|
|
const [showForm, setShowForm] = useState(false);
|
2024-03-20 13:08:08 +01:00
|
|
|
|
2024-03-20 13:00:11 +01:00
|
|
|
return (
|
2024-03-21 15:21:33 +01:00
|
|
|
<>
|
|
|
|
|
<div className={styles.postFormButtonDesktop}>
|
2024-04-08 17:13:02 +02:00
|
|
|
{isThreadClosed ? (
|
|
|
|
|
<div className={styles.closed}>
|
2024-04-08 18:36:51 +02:00
|
|
|
{t('thread_closed')}
|
2024-04-08 17:13:02 +02:00
|
|
|
<br />
|
2024-04-08 18:36:51 +02:00
|
|
|
{t('may_not_reply')}
|
2024-04-08 17:13:02 +02:00
|
|
|
</div>
|
|
|
|
|
) : (
|
|
|
|
|
<div>
|
|
|
|
|
[
|
|
|
|
|
<button className='button' onClick={() => setShowForm(true)}>
|
|
|
|
|
{isInPostPage ? t('post_a_reply') : t('start_new_thread')}
|
|
|
|
|
</button>
|
|
|
|
|
]
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
2024-03-21 15:21:33 +01:00
|
|
|
</div>
|
|
|
|
|
<div className={styles.postFormButtonMobile}>
|
2024-04-08 17:46:36 +02:00
|
|
|
{isThreadClosed ? (
|
|
|
|
|
<div className={styles.closed}>
|
2024-04-14 14:42:05 +02:00
|
|
|
{t('thread_closed')}
|
2024-04-08 17:46:36 +02:00
|
|
|
<br />
|
2024-04-14 14:42:05 +02:00
|
|
|
{t('may_not_reply')}
|
2024-04-08 17:46:36 +02:00
|
|
|
</div>
|
|
|
|
|
) : (
|
|
|
|
|
<button className='button' onClick={() => setShowForm(true)}>
|
|
|
|
|
{isInPostPage ? t('post_a_reply') : t('start_new_thread')}
|
|
|
|
|
</button>
|
|
|
|
|
)}
|
2024-03-21 15:21:33 +01:00
|
|
|
</div>
|
|
|
|
|
</>
|
2024-03-20 13:00:11 +01:00
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default PostForm;
|