Files
5chan/src/components/post-form/post-form.tsx
T

61 lines
1.9 KiB
TypeScript
Raw Normal View History

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';
import { useComment } from '@plebbit/plebbit-react-hooks';
2024-04-08 17:32:12 +02:00
import { isDescriptionView, isPostPageView, isRulesView } from '../../lib/utils/view-utils';
import styles from './post-form.module.css';
2024-03-20 13:00:11 +01: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 || {};
const comment = useComment({ commentCid });
const { deleted, locked, removed } = comment || {};
2024-04-08 17:32:12 +02:00
const isThreadClosed = deleted || locked || removed || isInDescriptionView || isInRulesView;
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}>
{isThreadClosed ? (
<div className={styles.closed}>
{t('thread_closed')}
<br />
{t('may_not_reply')}
</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}>
{t('thread_closed')}
2024-04-08 17:46:36 +02:00
<br />
{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;