2025-11-25 13:13:38 +01:00
|
|
|
import { useEffect, useRef, useState } from 'react';
|
2024-03-20 13:08:08 +01:00
|
|
|
import { useTranslation } from 'react-i18next';
|
2024-04-26 19:13:23 +02:00
|
|
|
import { useLocation, useNavigate, useParams } from 'react-router-dom';
|
2025-06-04 16:37:17 +02:00
|
|
|
import { Comment, setAccount, useAccount, useAccountComment, useAccountSubplebbits, useEditedComment } from '@plebbit/plebbit-react-hooks';
|
|
|
|
|
import Plebbit from '@plebbit/plebbit-js';
|
2025-03-06 13:15:33 +01:00
|
|
|
import useSubplebbitsStore from '@plebbit/plebbit-react-hooks/dist/stores/subplebbits';
|
|
|
|
|
import useSubplebbitsPagesStore from '@plebbit/plebbit-react-hooks/dist/stores/subplebbits-pages';
|
2024-09-20 17:57:25 +02:00
|
|
|
import { getHasThumbnail, getLinkMediaInfo } from '../../lib/utils/media-utils';
|
2024-08-27 18:46:42 +02:00
|
|
|
import { formatMarkdown } from '../../lib/utils/post-utils';
|
2024-04-24 08:48:31 +02:00
|
|
|
import { isValidURL } from '../../lib/utils/url-utils';
|
2026-01-25 16:29:15 +08:00
|
|
|
import { isAllView, isCatalogView, isModQueueView, isModView, isPostPageView, isSubscriptionsView } from '../../lib/utils/view-utils';
|
2026-02-17 17:35:53 +08:00
|
|
|
import { useDirectories, useDirectoryByAddress } from '../../hooks/use-directories';
|
2025-11-07 12:50:58 +01:00
|
|
|
import { useResolvedSubplebbitAddress } from '../../hooks/use-resolved-subplebbit-address';
|
2025-01-30 17:09:21 +01:00
|
|
|
import useFetchGifFirstFrame from '../../hooks/use-fetch-gif-first-frame';
|
|
|
|
|
import useIsSubplebbitOffline from '../../hooks/use-is-subplebbit-offline';
|
|
|
|
|
import usePublishPost from '../../hooks/use-publish-post';
|
2026-01-03 16:17:48 +01:00
|
|
|
import usePublishReply from '../../hooks/use-publish-reply';
|
2026-02-17 16:44:16 +08:00
|
|
|
import { useFileUpload } from '../../hooks/use-file-upload';
|
2026-01-03 16:17:48 +01:00
|
|
|
import styles from './post-form.module.css';
|
2026-02-11 19:01:09 +08:00
|
|
|
import { capitalize, debounce } from 'lodash';
|
2026-01-03 16:17:48 +01:00
|
|
|
|
2026-01-02 16:42:16 +01:00
|
|
|
// Separate component for offline alert to isolate rerenders from updatingState
|
|
|
|
|
// Only this component will rerender when updatingState changes, not the whole PostForm
|
|
|
|
|
const OfflineAlert = ({ subplebbitAddress }: { subplebbitAddress: string | undefined }) => {
|
|
|
|
|
const subplebbit = useSubplebbitsStore((state) => (subplebbitAddress ? state.subplebbits[subplebbitAddress] : undefined));
|
|
|
|
|
const { isOffline, isOnlineStatusLoading, offlineTitle } = useIsSubplebbitOffline(subplebbit);
|
|
|
|
|
|
|
|
|
|
if (!isOffline && !isOnlineStatusLoading) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return <div className={styles.offlineBoard}>{offlineTitle}</div>;
|
|
|
|
|
};
|
2024-03-20 13:00:11 +01:00
|
|
|
|
2024-05-31 15:45:48 +02:00
|
|
|
export const LinkTypePreviewer = ({ link }: { link: string }) => {
|
2024-05-31 16:51:22 +02:00
|
|
|
const { t } = useTranslation();
|
2024-04-24 08:48:31 +02:00
|
|
|
const mediaInfo = getLinkMediaInfo(link);
|
2024-08-03 22:41:40 +02:00
|
|
|
let type = mediaInfo?.type;
|
|
|
|
|
const gifFrameUrl = useFetchGifFirstFrame(mediaInfo?.url);
|
|
|
|
|
|
|
|
|
|
if (type === 'gif' && gifFrameUrl !== null) {
|
|
|
|
|
type = t('animated_gif');
|
|
|
|
|
} else if (type === 'gif' && gifFrameUrl === null) {
|
2024-09-03 14:27:29 +02:00
|
|
|
type = t('gif');
|
2024-08-03 22:41:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return isValidURL(link) ? type : t('invalid_url');
|
2024-04-24 08:48:31 +02:00
|
|
|
};
|
|
|
|
|
|
2024-08-06 20:12:07 +02:00
|
|
|
const PostFormTable = ({ closeForm, postCid }: { closeForm: () => void; postCid: string }) => {
|
2024-04-28 17:12:19 +02:00
|
|
|
const { t } = useTranslation();
|
2025-01-30 17:09:21 +01:00
|
|
|
const params = useParams();
|
2024-04-24 08:48:31 +02:00
|
|
|
const account = useAccount();
|
2025-01-30 17:09:21 +01:00
|
|
|
const [url, setUrl] = useState('');
|
2024-08-06 20:12:07 +02:00
|
|
|
const author = account?.author || {};
|
|
|
|
|
const { displayName } = author || {};
|
2025-01-30 17:09:21 +01:00
|
|
|
const accountComment = useAccountComment({ commentIndex: params?.accountCommentIndex as any });
|
2025-11-07 12:50:58 +01:00
|
|
|
const resolvedAddress = useResolvedSubplebbitAddress();
|
|
|
|
|
const subplebbitAddress = resolvedAddress || accountComment?.subplebbitAddress;
|
2025-01-30 17:09:21 +01:00
|
|
|
const { setPublishPostOptions, postIndex, publishPost, publishPostOptions, resetPublishPostOptions } = usePublishPost({ subplebbitAddress });
|
2026-02-17 17:35:53 +08:00
|
|
|
const effectiveBoardAddress = subplebbitAddress || publishPostOptions.subplebbitAddress;
|
2024-04-26 19:13:23 +02:00
|
|
|
|
2024-05-06 22:49:23 +02:00
|
|
|
const textRef = useRef<HTMLTextAreaElement>(null);
|
|
|
|
|
const urlRef = useRef<HTMLInputElement>(null);
|
|
|
|
|
const subjectRef = useRef<HTMLInputElement>(null);
|
|
|
|
|
|
2024-05-17 14:56:09 +02:00
|
|
|
const location = useLocation();
|
2024-10-29 17:40:09 +01:00
|
|
|
const isInAllView = isAllView(location.pathname);
|
2025-06-04 16:37:17 +02:00
|
|
|
const isInModView = isModView(location.pathname);
|
2024-06-17 12:17:36 +02:00
|
|
|
const isInSubscriptionsView = isSubscriptionsView(location.pathname, useParams());
|
2024-05-17 14:56:09 +02:00
|
|
|
const subscriptions = account?.subscriptions || [];
|
2026-01-28 16:51:27 +08:00
|
|
|
const directories = useDirectories();
|
2026-02-17 17:35:53 +08:00
|
|
|
const directoryEntry = useDirectoryByAddress(effectiveBoardAddress);
|
|
|
|
|
const showSpoilerForPost = directoryEntry?.features?.noSpoilers !== true;
|
|
|
|
|
const showSpoilerForReply = directoryEntry?.features?.noSpoilerReplies !== true;
|
2024-05-17 14:56:09 +02:00
|
|
|
|
2025-06-04 16:37:17 +02:00
|
|
|
const { accountSubplebbits } = useAccountSubplebbits();
|
|
|
|
|
const accountSubplebbitAddresses = Object.keys(accountSubplebbits);
|
|
|
|
|
|
2025-01-31 23:53:24 +01:00
|
|
|
const [lengthError, setLengthError] = useState<string | null>(null);
|
|
|
|
|
|
|
|
|
|
const checkContentLength = useRef(
|
2026-02-11 19:01:09 +08:00
|
|
|
debounce((content: string, t: Function) => {
|
2025-01-31 23:53:24 +01:00
|
|
|
const length = content.trim().length;
|
|
|
|
|
if (length > 2000) {
|
|
|
|
|
setLengthError(`${t('error')}: ${t('comment_field_too_long', { length })}`);
|
|
|
|
|
} else {
|
|
|
|
|
setLengthError(null);
|
|
|
|
|
}
|
|
|
|
|
}, 1000),
|
|
|
|
|
).current;
|
|
|
|
|
|
2024-05-06 22:49:23 +02:00
|
|
|
const resetFields = () => {
|
|
|
|
|
if (textRef.current) {
|
|
|
|
|
textRef.current.value = '';
|
|
|
|
|
}
|
|
|
|
|
if (urlRef.current) {
|
|
|
|
|
urlRef.current.value = '';
|
|
|
|
|
}
|
|
|
|
|
if (subjectRef.current) {
|
|
|
|
|
subjectRef.current.value = '';
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2024-08-29 17:48:34 +02:00
|
|
|
const onPublishPost = () => {
|
|
|
|
|
const currentTitle = subjectRef.current?.value.trim() || '';
|
|
|
|
|
const currentContent = textRef.current?.value.trim() || '';
|
|
|
|
|
const currentUrl = urlRef.current?.value.trim() || '';
|
|
|
|
|
|
2025-01-31 23:53:24 +01:00
|
|
|
checkContentLength.cancel();
|
|
|
|
|
setLengthError(null);
|
|
|
|
|
|
2024-08-29 17:48:34 +02:00
|
|
|
if (!currentTitle && !currentContent && !currentUrl) {
|
2024-09-20 18:05:33 +02:00
|
|
|
alert(t('empty_comment_alert'));
|
2024-04-26 19:13:23 +02:00
|
|
|
return;
|
|
|
|
|
}
|
2024-09-20 17:57:25 +02:00
|
|
|
if (currentUrl && !isValidURL(currentUrl)) {
|
2024-09-20 18:05:33 +02:00
|
|
|
alert(t('invalid_url_alert'));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2025-01-31 23:53:24 +01:00
|
|
|
if (currentContent.length > 2000) {
|
|
|
|
|
alert(t('error') + ': ' + t('field_too_long'));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2025-06-04 16:37:17 +02:00
|
|
|
if ((isInAllView || isInSubscriptionsView || isInModView) && !publishPostOptions.subplebbitAddress) {
|
2024-09-20 18:05:33 +02:00
|
|
|
alert(t('no_board_selected_warning'));
|
2024-04-26 19:13:23 +02:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-20 17:57:25 +02:00
|
|
|
if (!isInPostView) {
|
|
|
|
|
const linkMediaInfo = getLinkMediaInfo(currentUrl);
|
|
|
|
|
const hasThumbnail = getHasThumbnail(linkMediaInfo, currentUrl);
|
|
|
|
|
|
|
|
|
|
if (!hasThumbnail) {
|
|
|
|
|
const confirmMessage = t('missing_link_confirm');
|
|
|
|
|
if (!window.confirm(confirmMessage)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-01-30 17:09:21 +01:00
|
|
|
publishPost();
|
2024-04-26 19:13:23 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// redirect to pending page when pending comment is created
|
|
|
|
|
const navigate = useNavigate();
|
|
|
|
|
useEffect(() => {
|
2025-01-30 17:09:21 +01:00
|
|
|
if (typeof postIndex === 'number') {
|
|
|
|
|
resetPublishPostOptions();
|
2024-05-06 22:49:23 +02:00
|
|
|
resetFields();
|
2025-11-07 12:50:58 +01:00
|
|
|
navigate(`/pending/${postIndex}`);
|
2024-04-26 19:13:23 +02:00
|
|
|
}
|
2025-01-30 17:09:21 +01:00
|
|
|
}, [postIndex, resetPublishPostOptions, navigate]);
|
2024-04-24 08:48:31 +02:00
|
|
|
|
2024-04-27 12:41:54 +02:00
|
|
|
// in post page, publish a reply to the post
|
2024-05-17 15:29:03 +02:00
|
|
|
const isInPostView = isPostPageView(location.pathname, params);
|
2024-04-27 12:41:54 +02:00
|
|
|
const cid = params?.commentCid as string;
|
2024-08-06 21:57:28 +02:00
|
|
|
const { setPublishReplyOptions, resetPublishReplyOptions, replyIndex, publishReply } = usePublishReply({ cid, subplebbitAddress });
|
2024-08-06 20:12:07 +02:00
|
|
|
|
2024-08-27 18:46:42 +02:00
|
|
|
const handleContentChange = (e: React.ChangeEvent<HTMLTextAreaElement>) => {
|
|
|
|
|
const formattedContent = formatMarkdown(e.target.value);
|
2025-01-30 17:09:21 +01:00
|
|
|
isInPostView ? setPublishReplyOptions({ content: formattedContent }) : setPublishPostOptions({ content: formattedContent });
|
2025-01-31 23:53:24 +01:00
|
|
|
checkContentLength(formattedContent, t);
|
2024-08-27 18:46:42 +02:00
|
|
|
};
|
|
|
|
|
|
2024-04-27 12:41:54 +02:00
|
|
|
const onPublishReply = () => {
|
2024-08-29 17:48:34 +02:00
|
|
|
const currentContent = textRef.current?.value.trim() || '';
|
|
|
|
|
const currentUrl = urlRef.current?.value.trim() || '';
|
2024-04-27 12:41:54 +02:00
|
|
|
|
2025-01-31 23:53:24 +01:00
|
|
|
checkContentLength.cancel();
|
|
|
|
|
setLengthError(null);
|
|
|
|
|
|
2024-08-29 17:48:34 +02:00
|
|
|
if (!currentContent && !currentUrl) {
|
2024-09-20 18:05:33 +02:00
|
|
|
alert(t('empty_comment_alert'));
|
2024-04-27 12:41:54 +02:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (currentUrl && !isValidURL(currentUrl)) {
|
2024-09-20 18:05:33 +02:00
|
|
|
alert(t('invalid_url_alert'));
|
2024-04-27 12:41:54 +02:00
|
|
|
return;
|
|
|
|
|
}
|
2024-08-06 20:12:07 +02:00
|
|
|
|
2025-01-31 23:53:24 +01:00
|
|
|
if (currentContent.length > 2000) {
|
|
|
|
|
alert(t('error') + ': ' + t('field_too_long'));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-06 21:51:45 +02:00
|
|
|
publishReply();
|
2024-04-27 12:41:54 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
if (typeof replyIndex === 'number') {
|
2024-08-06 20:12:07 +02:00
|
|
|
resetPublishReplyOptions();
|
2024-05-06 22:49:23 +02:00
|
|
|
resetFields();
|
|
|
|
|
closeForm();
|
2024-04-27 12:41:54 +02:00
|
|
|
}
|
2024-08-06 20:12:07 +02:00
|
|
|
}, [replyIndex, resetPublishReplyOptions, closeForm]);
|
2024-04-27 12:41:54 +02:00
|
|
|
|
2026-02-17 16:44:16 +08:00
|
|
|
const { isUploading, uploadedFileName, handleUpload } = useFileUpload({
|
|
|
|
|
onUploadComplete: (uploadedUrl: string) => {
|
|
|
|
|
if (uploadedUrl) {
|
|
|
|
|
setUrl(uploadedUrl);
|
2024-11-02 18:42:52 +01:00
|
|
|
if (urlRef.current) {
|
2026-02-17 16:44:16 +08:00
|
|
|
urlRef.current.value = uploadedUrl;
|
2024-11-02 18:42:52 +01:00
|
|
|
}
|
2026-02-17 16:44:16 +08:00
|
|
|
isInPostView ? setPublishReplyOptions({ link: uploadedUrl }) : setPublishPostOptions({ link: uploadedUrl });
|
2024-11-02 18:42:52 +01:00
|
|
|
}
|
2026-02-17 16:44:16 +08:00
|
|
|
},
|
|
|
|
|
});
|
2024-11-02 18:42:52 +01:00
|
|
|
|
2025-01-26 22:25:56 +01:00
|
|
|
const hasInitializedDisplayName = useRef(false);
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
if (displayName && !hasInitializedDisplayName.current) {
|
|
|
|
|
hasInitializedDisplayName.current = true;
|
|
|
|
|
if (isInPostView) {
|
|
|
|
|
setPublishReplyOptions({ displayName });
|
|
|
|
|
} else {
|
2025-01-30 17:09:21 +01:00
|
|
|
setPublishPostOptions({ displayName });
|
2025-01-26 22:25:56 +01:00
|
|
|
}
|
|
|
|
|
}
|
2025-01-30 17:09:21 +01:00
|
|
|
}, [displayName, isInPostView, setPublishReplyOptions, setPublishPostOptions]);
|
2025-01-26 22:25:56 +01:00
|
|
|
|
2024-04-24 08:48:31 +02:00
|
|
|
return (
|
2024-04-24 15:20:55 +02:00
|
|
|
<table className={styles.postFormTable}>
|
2024-04-24 08:48:31 +02:00
|
|
|
<tbody>
|
|
|
|
|
<tr>
|
2024-04-28 17:12:19 +02:00
|
|
|
<td>{t('name')}</td>
|
2024-04-24 08:48:31 +02:00
|
|
|
<td>
|
2024-04-26 19:13:23 +02:00
|
|
|
<input
|
|
|
|
|
type='text'
|
2026-02-11 19:01:09 +08:00
|
|
|
placeholder={!displayName ? capitalize(t('anonymous')) : undefined}
|
2024-04-26 19:13:23 +02:00
|
|
|
defaultValue={displayName || undefined}
|
2024-08-08 17:48:45 +02:00
|
|
|
onChange={(e) => {
|
2025-01-25 22:07:45 +01:00
|
|
|
const newDisplayName = e.target.value.trim() || undefined;
|
|
|
|
|
setAccount({ ...account, author: { ...account?.author, displayName: newDisplayName } });
|
2024-08-12 21:55:52 +02:00
|
|
|
if (isInPostView) {
|
2025-01-25 22:07:45 +01:00
|
|
|
setPublishReplyOptions({ displayName: newDisplayName });
|
2024-08-12 21:55:52 +02:00
|
|
|
} else {
|
2025-01-30 17:09:21 +01:00
|
|
|
setPublishPostOptions({ displayName: newDisplayName });
|
2024-08-12 21:55:52 +02:00
|
|
|
}
|
2024-08-08 17:48:45 +02:00
|
|
|
}}
|
2024-04-26 19:13:23 +02:00
|
|
|
/>
|
2024-11-02 18:42:52 +01:00
|
|
|
{isInPostView && (
|
|
|
|
|
<button onClick={onPublishReply} disabled={isUploading}>
|
|
|
|
|
{t('post')}
|
|
|
|
|
</button>
|
|
|
|
|
)}
|
2024-04-24 08:48:31 +02:00
|
|
|
</td>
|
|
|
|
|
</tr>
|
2024-05-17 15:29:03 +02:00
|
|
|
{!isInPostView && (
|
2024-04-27 12:41:54 +02:00
|
|
|
<tr>
|
2024-04-28 17:12:19 +02:00
|
|
|
<td>{t('subject')}</td>
|
2024-04-27 12:41:54 +02:00
|
|
|
<td>
|
|
|
|
|
<input
|
|
|
|
|
type='text'
|
2024-05-06 22:49:23 +02:00
|
|
|
ref={subjectRef}
|
2024-04-27 12:41:54 +02:00
|
|
|
onChange={(e) => {
|
2025-01-30 17:09:21 +01:00
|
|
|
setPublishPostOptions({ title: e.target.value });
|
2024-04-27 12:41:54 +02:00
|
|
|
}}
|
|
|
|
|
/>
|
2024-04-28 17:12:19 +02:00
|
|
|
<button onClick={onPublishPost}>{t('post')}</button>
|
2024-04-27 12:41:54 +02:00
|
|
|
</td>
|
|
|
|
|
</tr>
|
|
|
|
|
)}
|
2024-04-24 08:48:31 +02:00
|
|
|
<tr>
|
2024-04-28 17:12:19 +02:00
|
|
|
<td>{t('comment')}</td>
|
2024-04-24 16:47:51 +02:00
|
|
|
<td>
|
2024-08-27 18:46:42 +02:00
|
|
|
<textarea cols={48} rows={4} wrap='soft' ref={textRef} onChange={handleContentChange} />
|
2025-01-31 23:53:24 +01:00
|
|
|
{lengthError && <div className={styles.error}>{lengthError}</div>}
|
2024-04-24 16:47:51 +02:00
|
|
|
</td>
|
2024-04-24 08:48:31 +02:00
|
|
|
</tr>
|
|
|
|
|
<tr>
|
2024-04-28 17:12:19 +02:00
|
|
|
<td>{t('link')}</td>
|
2024-06-11 21:09:48 +02:00
|
|
|
<td className={styles.linkField}>
|
2024-04-26 19:13:23 +02:00
|
|
|
<input
|
|
|
|
|
type='text'
|
|
|
|
|
autoCorrect='off'
|
|
|
|
|
autoComplete='off'
|
|
|
|
|
spellCheck='false'
|
2024-04-27 12:41:54 +02:00
|
|
|
ref={urlRef}
|
2024-11-02 18:42:52 +01:00
|
|
|
disabled={isUploading}
|
2024-04-26 19:13:23 +02:00
|
|
|
onChange={(e) => {
|
|
|
|
|
setUrl(e.target.value);
|
2025-01-30 17:09:21 +01:00
|
|
|
isInPostView ? setPublishReplyOptions({ link: e.target.value }) : setPublishPostOptions({ link: e.target.value });
|
2024-04-26 19:13:23 +02:00
|
|
|
}}
|
|
|
|
|
/>
|
2024-06-11 21:09:48 +02:00
|
|
|
<span className={styles.linkType}> {url && <LinkTypePreviewer link={url} />}</span>
|
2024-05-31 16:10:38 +02:00
|
|
|
</td>
|
|
|
|
|
</tr>
|
2026-02-17 16:44:16 +08:00
|
|
|
<tr className={styles.uploadButton}>
|
|
|
|
|
<td>{t('file')}</td>
|
|
|
|
|
<td>
|
|
|
|
|
<button onClick={handleUpload} disabled={isUploading}>
|
|
|
|
|
{t('choose_file')}
|
|
|
|
|
</button>
|
|
|
|
|
<span>{isUploading ? t('uploading') : uploadedFileName || t('no_file_chosen')}</span>
|
|
|
|
|
</td>
|
|
|
|
|
</tr>
|
2026-02-17 17:35:53 +08:00
|
|
|
{((isInPostView && showSpoilerForReply) || (!isInPostView && showSpoilerForPost)) && (
|
|
|
|
|
<tr className={styles.spoilerButton}>
|
|
|
|
|
<td>{t('options')}</td>
|
|
|
|
|
<td>
|
|
|
|
|
[
|
|
|
|
|
<label>
|
|
|
|
|
<input
|
|
|
|
|
type='checkbox'
|
|
|
|
|
onChange={(e) => (isInPostView ? setPublishReplyOptions({ spoiler: e.target.checked }) : setPublishPostOptions({ spoiler: e.target.checked }))}
|
|
|
|
|
/>
|
|
|
|
|
{capitalize(t('spoiler'))}?
|
|
|
|
|
</label>
|
|
|
|
|
]
|
|
|
|
|
</td>
|
|
|
|
|
</tr>
|
|
|
|
|
)}
|
2025-06-04 16:37:17 +02:00
|
|
|
{(isInAllView || isInSubscriptionsView || isInModView) && (
|
2024-05-17 14:56:09 +02:00
|
|
|
<tr>
|
|
|
|
|
<td>{t('board')}</td>
|
|
|
|
|
<td>
|
2025-01-30 17:09:21 +01:00
|
|
|
<select onChange={(e) => setPublishPostOptions({ subplebbitAddress: e.target.value })} value={subplebbitAddress}>
|
2024-10-13 18:49:45 +02:00
|
|
|
<option value=''>{t('choose_one')}</option>
|
2024-05-17 14:56:09 +02:00
|
|
|
{isInAllView &&
|
2026-01-28 16:51:27 +08:00
|
|
|
directories
|
2025-11-13 22:08:34 +01:00
|
|
|
.filter((subplebbit) => subplebbit.title && subplebbit.address)
|
|
|
|
|
.map((subplebbit) => (
|
|
|
|
|
<option key={subplebbit.address} value={subplebbit.address}>
|
|
|
|
|
{subplebbit.title}
|
|
|
|
|
</option>
|
|
|
|
|
))}
|
2025-06-04 16:37:17 +02:00
|
|
|
{isInModView &&
|
|
|
|
|
accountSubplebbitAddresses.map((address: string) => (
|
|
|
|
|
<option key={address} value={address}>
|
2025-12-24 13:29:09 +01:00
|
|
|
{address && Plebbit.getShortAddress({ address })}
|
2024-05-17 14:56:09 +02:00
|
|
|
</option>
|
|
|
|
|
))}
|
|
|
|
|
{isInSubscriptionsView &&
|
|
|
|
|
subscriptions.map((sub: string) => (
|
|
|
|
|
<option key={sub} value={sub}>
|
|
|
|
|
{sub}
|
|
|
|
|
</option>
|
|
|
|
|
))}
|
|
|
|
|
</select>
|
|
|
|
|
</td>
|
|
|
|
|
</tr>
|
|
|
|
|
)}
|
2024-04-24 08:48:31 +02:00
|
|
|
</tbody>
|
|
|
|
|
</table>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
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();
|
2024-05-17 15:29:03 +02:00
|
|
|
const isInPostView = isPostPageView(location.pathname, params);
|
2024-10-29 17:40:09 +01:00
|
|
|
const isInAllView = isAllView(location.pathname);
|
2025-06-04 16:37:17 +02:00
|
|
|
const isInModView = isModView(location.pathname);
|
2026-01-25 16:29:15 +08:00
|
|
|
const isInModQueueView = isModQueueView(location.pathname);
|
2025-03-06 13:15:33 +01:00
|
|
|
const isInSubscriptionsView = isSubscriptionsView(location.pathname, params);
|
2025-12-29 16:40:33 +01:00
|
|
|
const isInCatalogView = isCatalogView(location.pathname, params);
|
2024-04-08 17:32:12 +02:00
|
|
|
|
2025-03-06 13:15:33 +01:00
|
|
|
const commentCid = params?.commentCid;
|
|
|
|
|
const post = useSubplebbitsPagesStore((state) => state.comments[commentCid as string]);
|
2024-07-19 22:13:51 +02:00
|
|
|
let comment: Comment = post;
|
|
|
|
|
// handle pending mod or author edit
|
|
|
|
|
const { editedComment } = useEditedComment({ comment });
|
|
|
|
|
if (editedComment) {
|
|
|
|
|
comment = editedComment;
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-06 20:12:07 +02:00
|
|
|
const { deleted, locked, removed, postCid } = comment || {};
|
2025-12-23 19:14:25 +01:00
|
|
|
const isThreadClosed = deleted || locked || removed;
|
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
|
|
|
|
2025-01-28 19:04:57 +01:00
|
|
|
const accountComment = useAccountComment({ commentIndex: params?.accountCommentIndex as any });
|
2025-11-07 12:50:58 +01:00
|
|
|
const resolvedAddress = useResolvedSubplebbitAddress();
|
|
|
|
|
const subplebbitAddress = resolvedAddress || accountComment?.subplebbitAddress;
|
2024-06-08 21:22:17 +02:00
|
|
|
|
2024-03-20 13:00:11 +01:00
|
|
|
return (
|
2024-03-21 15:21:33 +01:00
|
|
|
<>
|
2024-04-24 15:20:55 +02:00
|
|
|
<div className={styles.postFormDesktop}>
|
2026-01-02 16:42:16 +01:00
|
|
|
{!(isInAllView || isInSubscriptionsView || isInModView) && showForm && <OfflineAlert subplebbitAddress={subplebbitAddress} />}
|
2026-01-25 16:29:15 +08:00
|
|
|
{isInModQueueView ? (
|
|
|
|
|
<div className={styles.modQueueTitle}>{t('moderation_queue')}</div>
|
|
|
|
|
) : isThreadClosed ? (
|
2024-04-08 17:13:02 +02:00
|
|
|
<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>
|
2024-04-24 08:48:31 +02:00
|
|
|
) : !showForm ? (
|
2024-04-08 17:13:02 +02:00
|
|
|
<div>
|
|
|
|
|
[
|
|
|
|
|
<button className='button' onClick={() => setShowForm(true)}>
|
2024-05-17 15:29:03 +02:00
|
|
|
{isInPostView ? t('post_a_reply') : t('start_new_thread')}
|
2024-04-08 17:13:02 +02:00
|
|
|
</button>
|
|
|
|
|
]
|
|
|
|
|
</div>
|
2024-04-24 08:48:31 +02:00
|
|
|
) : (
|
2024-08-06 20:12:07 +02:00
|
|
|
<PostFormTable closeForm={() => setShowForm(false)} postCid={postCid} />
|
2024-04-08 17:13:02 +02:00
|
|
|
)}
|
2024-03-21 15:21:33 +01:00
|
|
|
</div>
|
2024-04-24 15:20:55 +02:00
|
|
|
<div className={styles.postFormMobile}>
|
2026-01-02 16:42:16 +01:00
|
|
|
{!(isInAllView || isInSubscriptionsView || isInModView) && showForm && <OfflineAlert subplebbitAddress={subplebbitAddress} />}
|
2026-01-25 16:29:15 +08:00
|
|
|
{isInModQueueView ? (
|
|
|
|
|
<div className={styles.modQueueTitle}>{t('moderation_queue')}</div>
|
|
|
|
|
) : isThreadClosed ? (
|
2024-04-08 17:46:36 +02:00
|
|
|
<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>
|
|
|
|
|
) : (
|
2024-04-24 15:20:55 +02:00
|
|
|
<>
|
|
|
|
|
<button className={`${styles.showFormButton} button`} onClick={() => setShowForm(showForm ? false : true)}>
|
2024-05-17 15:29:03 +02:00
|
|
|
{showForm ? t('close_post_form') : isInPostView ? t('post_a_reply') : t('start_new_thread')}
|
2024-04-24 15:20:55 +02:00
|
|
|
</button>
|
2024-08-06 20:12:07 +02:00
|
|
|
{showForm && <PostFormTable closeForm={() => setShowForm(false)} postCid={postCid} />}
|
2024-04-24 15:20:55 +02:00
|
|
|
</>
|
2024-04-08 17:46:36 +02:00
|
|
|
)}
|
2025-12-29 16:40:33 +01:00
|
|
|
{isInCatalogView && <hr />}
|
2024-03-21 15:21:33 +01:00
|
|
|
</div>
|
|
|
|
|
</>
|
2024-03-20 13:00:11 +01:00
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default PostForm;
|