Files
5chan/src/components/reply-modal/reply-modal.tsx
T

633 lines
25 KiB
TypeScript
Raw Normal View History

2025-11-25 13:13:38 +01:00
import { useEffect, useRef, useState } from 'react';
import { useLocation, useNavigate, useParams } from 'react-router-dom';
import { useTranslation } from 'react-i18next';
import type { TFunction } from 'i18next';
import { setAccount, useAccount } from '@bitsocial/bitsocial-react-hooks';
2026-05-16 16:11:22 +07:00
import { getExpiringMediaLinkAlert } from '../../lib/utils/media-link-validation-utils';
import { getCommentFlagOptionsForDirectory, getCommentFlagPublishOptionsForDirectory } from '../../lib/comment-flag-selection';
import {
type DiceRoll,
type FortuneEntry,
type PostOptionsValidationError,
POST_OPTIONS_VALIDATION_DELAY_MS,
getContentWithPostOptionState as getContentWithOptions,
getPostOptionsDirectoryCode,
getPostOptionsValidationError,
hasNonokoOption,
isPostOptionsValidationError,
} from '../../lib/utils/post-options-utils';
2026-05-01 18:03:04 +07:00
import { getPublishURLFilename, isValidPublishURL } from '../../lib/utils/url-utils';
2026-05-19 15:45:22 +07:00
import { hasModQueueAccessRole } from '../../lib/utils/mod-access';
import { getModerationPostingRoleLabel } from '../../lib/utils/author-display-utils';
import { isAllView, isModView, isSubscriptionsView } from '../../lib/utils/view-utils';
import useSelectedTextStore from '../../stores/use-selected-text-store';
import useReplyModalStore from '../../stores/use-reply-modal-store';
import { getShowUploadControls, isWebRuntime } from '../../lib/media-hosting/show-upload-controls';
import useMediaHostingStore from '../../stores/use-media-hosting-store';
import { findDirectoryByAddress, useDirectories } from '../../hooks/use-directories';
2024-08-06 21:57:28 +02:00
import usePublishReply from '../../hooks/use-publish-reply';
import useIsMobile from '../../hooks/use-is-mobile';
import { useFileUpload } from '../../hooks/use-file-upload';
2026-05-19 15:45:22 +07:00
import { useCommunityField } from '../../hooks/use-stable-community';
import { OEKAKI_WEB_WARNING_TEXT } from '../../lib/oekaki/oekaki-copy';
2026-05-19 15:45:22 +07:00
import BbcodeEditorToolbar, { BbcodePreview } from '../bbcode-editor-toolbar/bbcode-editor-toolbar';
import BoardOfflineAlert from '../board-offline-alert/board-offline-alert';
2026-05-01 21:12:39 +07:00
import LoadingEllipsis from '../loading-ellipsis';
import OekakiDrawingControls from '../oekaki-drawing-controls';
import PostOptionsErrorMessage from '../post-options-error-message/post-options-error-message';
2024-04-28 20:08:41 +02:00
import styles from './reply-modal.module.css';
import capitalize from 'lodash/capitalize';
import debounce from 'lodash/debounce';
import { useSpring, animated } from '@react-spring/web';
import { useDrag } from '@use-gesture/react';
2026-05-01 18:03:04 +07:00
const FILE_LINK_PLACEHOLDER = 'https://website.com/image.jpg';
2024-04-28 20:08:41 +02:00
interface ReplyModalProps {
closeModal: () => void;
2024-08-09 12:08:22 +02:00
showReplyModal: boolean;
2024-04-28 20:08:41 +02:00
parentCid: string;
parentNumber: number | null;
2025-12-28 22:16:38 +01:00
threadNumber: number | null;
postCid: string;
scrollY: number;
communityAddress: string;
2024-04-28 20:08:41 +02:00
}
const ReplyModal = ({ closeModal, showReplyModal, parentCid, parentNumber, threadNumber, postCid, scrollY, communityAddress }: ReplyModalProps) => {
2024-04-28 20:08:41 +02:00
const { t } = useTranslation();
const location = useLocation();
const navigate = useNavigate();
const params = useParams();
const isInAllView = isAllView(location.pathname);
const isInModView = isModView(location.pathname);
const isInSubscriptionsView = isSubscriptionsView(location.pathname, params);
const directories = useDirectories();
const directoryEntry = findDirectoryByAddress(directories, communityAddress);
const showSpoilerForReply = directoryEntry?.features?.noSpoilerReplies !== true;
const postOptionsDirectoryCode = getPostOptionsDirectoryCode(directoryEntry, location.pathname);
const showOekakiControls = postOptionsDirectoryCode === 'i' || directoryEntry?.directoryCode === 'i';
const requirePostLinkIsMediaFeature = directoryEntry?.features?.requirePostLinkIsMedia;
const requirePostLinkIsMedia = requirePostLinkIsMediaFeature === true || (requirePostLinkIsMediaFeature === undefined && (isInAllView || isInSubscriptionsView));
2026-05-24 23:14:36 +07:00
const flagOptions = getCommentFlagOptionsForDirectory(directoryEntry);
const { isResolvingExternalQuotes, publishReply, publishReplyError, publishReplyStateMessage, resetPublishReplyOptions, replyIndex, setPublishReplyOptions } =
usePublishReply({
cid: parentCid,
communityAddress,
postCid,
});
2024-04-28 20:08:41 +02:00
const account = useAccount();
const { displayName } = account?.author || {};
2026-05-19 15:45:22 +07:00
const accountAddress = account?.author?.address;
const roles = useCommunityField(communityAddress, (community) => community?.roles);
const accountRole = accountAddress ? roles?.[accountAddress]?.role : undefined;
const showBbcodeToolbar = hasModQueueAccessRole(accountRole);
const moderationPostingRoleLabel = getModerationPostingRoleLabel({ address: accountAddress, role: accountRole });
const moderationPostingWarning = showBbcodeToolbar && moderationPostingRoleLabel ? `warning: posting as ${moderationPostingRoleLabel}` : undefined;
const textRef = useRef<HTMLTextAreaElement | null>(null);
const setTextRef = useRef((element: HTMLTextAreaElement | null) => {
textRef.current = element;
if (!element) return;
window.setTimeout(() => {
if (textRef.current === element) {
element.focus();
}
}, 0);
});
2024-04-28 20:08:41 +02:00
const urlRef = useRef<HTMLInputElement>(null);
const optionsRef = useRef<HTMLInputElement>(null);
2026-05-24 23:14:36 +07:00
const flagRef = useRef<HTMLSelectElement>(null);
const fortuneEntryRef = useRef<FortuneEntry | null>(null);
const diceRollRef = useRef<DiceRoll | null>(null);
const nonokoRedirectPathRef = useRef<string | null>(null);
const lastSelectionStartRef = useRef(0);
const lastSelectionEndRef = useRef(0);
2026-05-29 17:09:07 +07:00
const initializedReplyContentKeyRef = useRef('');
const lastProcessedQuoteInsertRequestIdRef = useRef(0);
const { selectedText } = useSelectedTextStore();
const openEmpty = useReplyModalStore((state) => state.openEmpty);
const quoteInsertRequestId = useReplyModalStore((state) => state.quoteInsertRequestId);
const quoteInsertNumber = useReplyModalStore((state) => state.quoteInsertNumber);
const quoteInsertSelectedText = useReplyModalStore((state) => state.quoteInsertSelectedText);
2024-04-28 20:08:41 +02:00
const [error, setError] = useState<string | PostOptionsValidationError | null>(null);
const [lengthError, setLengthError] = useState<string | null>(null);
2026-05-01 18:03:04 +07:00
const [url, setUrl] = useState('');
2026-05-19 15:45:22 +07:00
const [isBbcodePreviewing, setIsBbcodePreviewing] = useState(false);
const [bbcodePreviewContent, setBbcodePreviewContent] = useState('');
const checkContentLengthRef = useRef(
debounce((content: string, t: TFunction) => {
const length = content.trim().length;
if (length > 2000) {
setError(null);
setLengthError(`${t('error')}: ${t('comment_field_too_long', { length })}`);
} else {
setLengthError(null);
}
}, 1000),
);
2024-11-04 17:55:51 +01:00
const checkPostOptionsRef = useRef(
debounce((options: string, directoryCode: string | undefined) => {
const nextOptionsError = getPostOptionsValidationError(options, directoryCode);
if (nextOptionsError) {
setLengthError(null);
setError(nextOptionsError);
}
}, POST_OPTIONS_VALIDATION_DELAY_MS),
);
2024-04-28 20:08:41 +02:00
const onPublishReply = () => {
const currentContent = textRef.current?.value || '';
const currentUrl = urlRef.current?.value.trim() || '';
const currentOptions = optionsRef.current?.value || '';
const currentOptionsError = getPostOptionsValidationError(currentOptions, postOptionsDirectoryCode);
const publishContent = getContentWithOptions(currentContent, currentOptions, fortuneEntryRef, diceRollRef, postOptionsDirectoryCode);
checkContentLengthRef.current.cancel();
checkPostOptionsRef.current.cancel();
setLengthError(null);
nonokoRedirectPathRef.current = null;
if (currentOptionsError) {
setError(currentOptionsError);
return;
}
if (!publishContent.trim() && !currentUrl) {
setError(t('error') + ': ' + t('empty_comment_alert'));
2024-04-28 20:08:41 +02:00
return;
}
if (currentUrl && !isValidPublishURL(currentUrl)) {
setError(t('error') + ': ' + t('invalid_url_alert'));
return;
}
2026-05-16 16:11:22 +07:00
const expiringMediaLinkAlert = currentUrl ? getExpiringMediaLinkAlert(currentUrl, t) : null;
if (expiringMediaLinkAlert) {
setError(expiringMediaLinkAlert);
return;
}
if (publishContent.trim().length > 2000) {
setError(t('error') + ': ' + t('field_too_long'));
2024-04-28 20:08:41 +02:00
return;
}
const flagPublishOptions = getCommentFlagPublishOptionsForDirectory(directoryEntry, flagRef.current?.value);
2026-05-24 23:14:36 +07:00
2024-11-04 17:55:51 +01:00
setError(null);
nonokoRedirectPathRef.current = hasNonokoOption(currentOptions) ? `/${postOptionsDirectoryCode || params.boardIdentifier || communityAddress}` : null;
2026-05-24 23:14:36 +07:00
publishReply({ content: publishContent, ...flagPublishOptions });
2024-04-28 20:08:41 +02:00
};
2024-08-21 11:11:19 +02:00
useEffect(() => {
if (typeof replyIndex === 'number') {
const nonokoRedirectPath = nonokoRedirectPathRef.current;
nonokoRedirectPathRef.current = null;
2024-08-21 11:11:19 +02:00
resetPublishReplyOptions();
closeModal();
if (nonokoRedirectPath) {
navigate(nonokoRedirectPath);
}
2024-08-21 11:11:19 +02:00
}
}, [replyIndex, resetPublishReplyOptions, closeModal, navigate]);
2024-08-21 11:11:19 +02:00
const nodeRef = useRef<HTMLDivElement>(null);
const isMobile = useIsMobile();
2024-04-28 20:08:41 +02:00
2026-03-29 16:40:09 +07:00
const [{ left, top }, api] = useSpring(
() => ({
from: {
left: Math.round(window.innerWidth / 2 - 150),
top: Math.round(window.innerHeight / 2 - 200),
},
}),
[],
);
const bodySelectionStyleBeforeDragRef = useRef<{ userSelect: string; webkitUserSelect: string } | null>(null);
const disableBodyTextSelection = () => {
if (!bodySelectionStyleBeforeDragRef.current) {
bodySelectionStyleBeforeDragRef.current = {
userSelect: document.body.style.userSelect,
webkitUserSelect: document.body.style.webkitUserSelect,
};
}
Object.assign(document.body.style, { userSelect: 'none', webkitUserSelect: 'none' });
};
const restoreBodyTextSelection = () => {
const previousStyle = bodySelectionStyleBeforeDragRef.current;
Object.assign(document.body.style, {
userSelect: previousStyle?.userSelect ?? '',
webkitUserSelect: previousStyle?.webkitUserSelect ?? '',
});
bodySelectionStyleBeforeDragRef.current = null;
};
const bind = useDrag(
({ active, event, offset: [ox, oy] }) => {
const nextLeft = Math.round(ox);
const nextTop = Math.round(oy);
if (active) {
event.preventDefault();
disableBodyTextSelection();
} else {
restoreBodyTextSelection();
}
api.start({ left: nextLeft, top: nextTop, immediate: true });
},
{
from: () => [left.get(), top.get()],
filterTaps: true,
2025-03-02 16:04:45 +01:00
bounds: undefined,
},
);
useEffect(() => {
2026-05-29 17:09:07 +07:00
const checkContentLength = checkContentLengthRef.current;
const checkPostOptions = checkPostOptionsRef.current;
return () => {
2026-05-29 17:09:07 +07:00
checkContentLength.cancel();
checkPostOptions.cancel();
restoreBodyTextSelection();
};
}, []);
useEffect(() => {
if (nodeRef.current && isMobile) {
const viewportHeight = window.innerHeight;
const centeredPosition = Math.round(scrollY + viewportHeight / 2 - 300);
api.start({ top: centeredPosition, immediate: true });
}
}, [api, isMobile, scrollY]);
const parentCidRef = useRef<HTMLSpanElement>(null);
useEffect(() => {
if (!showReplyModal || isMobile) {
return;
}
const closeReplyModalOnEscape = (event: KeyboardEvent) => {
if (event.key === 'Escape') {
closeModal();
}
};
document.addEventListener('keydown', closeReplyModalOnEscape);
return () => document.removeEventListener('keydown', closeReplyModalOnEscape);
}, [showReplyModal, isMobile, closeModal]);
useEffect(() => {
if (parentCidRef.current) {
const cidWidth = parentCidRef.current.offsetWidth;
parentCidRef.current.style.width = `${cidWidth}px`;
}
}, [parentCid]);
useEffect(() => {
if (textRef.current) {
const len = textRef.current.value.length;
textRef.current.setSelectionRange(len, len);
}
}, []);
const defaultParentQuote = `>>${parentNumber ?? '?'}\n`;
// Enable spellcheck after initial content is injected into the textarea.
useEffect(() => {
2026-05-29 17:09:07 +07:00
if (!showReplyModal || !textRef.current) {
initializedReplyContentKeyRef.current = '';
return;
}
2026-05-29 17:09:07 +07:00
const initialContent = openEmpty ? selectedText || '' : `${defaultParentQuote}${selectedText || ''}`;
const initialContentKey = `${parentCid}:${openEmpty ? 'empty' : 'quoted'}:${initialContent}`;
if (initializedReplyContentKeyRef.current === initialContentKey) {
return;
}
initializedReplyContentKeyRef.current = initialContentKey;
textRef.current.spellcheck = false;
textRef.current.value = initialContent;
const len = textRef.current.value.length;
lastSelectionStartRef.current = len;
lastSelectionEndRef.current = len;
const publishContent = getContentWithOptions(initialContent, optionsRef.current?.value || '', fortuneEntryRef, diceRollRef, postOptionsDirectoryCode);
setPublishReplyOptions({ content: publishContent });
checkContentLengthRef.current(publishContent, t);
const spellcheckTimeout = window.setTimeout(() => {
if (textRef.current) {
textRef.current.spellcheck = true;
}
}, 100);
return () => {
window.clearTimeout(spellcheckTimeout);
};
}, [showReplyModal, parentCid, openEmpty, defaultParentQuote, selectedText, postOptionsDirectoryCode, setPublishReplyOptions, t]);
2026-05-19 15:45:22 +07:00
useEffect(() => {
if (!showReplyModal) {
checkContentLengthRef.current.cancel();
checkPostOptionsRef.current.cancel();
2026-05-19 15:45:22 +07:00
setIsBbcodePreviewing(false);
setBbcodePreviewContent('');
}
}, [showReplyModal]);
useEffect(() => {
if (!showReplyModal) {
fortuneEntryRef.current = null;
diceRollRef.current = null;
}
}, [showReplyModal]);
const handleContentInput = (e: React.ChangeEvent<HTMLTextAreaElement>) => {
lastSelectionStartRef.current = e.target.selectionStart ?? e.target.value.length;
lastSelectionEndRef.current = e.target.selectionEnd ?? lastSelectionStartRef.current;
};
const handleContentValueChange = (content: string, selectionStart?: number, selectionEnd?: number, options = optionsRef.current?.value || '') => {
2026-05-19 15:45:22 +07:00
if (isBbcodePreviewing) {
setBbcodePreviewContent(content);
}
if (typeof selectionStart === 'number') {
lastSelectionStartRef.current = selectionStart;
lastSelectionEndRef.current = selectionEnd ?? selectionStart;
}
const publishContent = getContentWithOptions(content, options, fortuneEntryRef, diceRollRef, postOptionsDirectoryCode);
setPublishReplyOptions({ content: publishContent });
checkContentLengthRef.current(publishContent, t);
};
const handleOptionsChange = (e: React.ChangeEvent<HTMLInputElement>) => {
const options = e.target.value;
handleContentValueChange(textRef.current?.value || '', undefined, undefined, options);
setError((currentError) => (isPostOptionsValidationError(currentError) ? null : currentError));
checkPostOptionsRef.current(options, postOptionsDirectoryCode);
};
2026-05-19 15:45:22 +07:00
const handleContentChange = (e: React.ChangeEvent<HTMLTextAreaElement>) => {
handleContentValueChange(e.target.value);
};
const handleBbcodePreviewToggle = () => {
if (isBbcodePreviewing) {
setIsBbcodePreviewing(false);
window.requestAnimationFrame(() => textRef.current?.focus());
return;
}
setBbcodePreviewContent(textRef.current?.value ?? '');
setIsBbcodePreviewing(true);
};
useEffect(() => {
const canInsertQuote = showReplyModal && quoteInsertRequestId !== 0 && !!textRef.current;
const textarea = textRef.current;
if (!canInsertQuote || !textarea) {
return;
}
// Guard: skip if we already processed this exact request id.
// setPublishReplyOptions identity changes after each call (store update -> new content -> new useCallback),
// which re-triggers this effect. Without this guard, that creates an infinite update loop.
if (quoteInsertRequestId === lastProcessedQuoteInsertRequestIdRef.current) {
return;
}
lastProcessedQuoteInsertRequestIdRef.current = quoteInsertRequestId;
const quote = `>>${quoteInsertNumber ?? '?'}`;
const selectedQuote = quoteInsertSelectedText?.trimEnd() || '';
const isFocused = document.activeElement === textarea;
const rawStart = isFocused ? (textarea.selectionStart ?? textarea.value.length) : lastSelectionStartRef.current;
const selectionEnd = isFocused ? (textarea.selectionEnd ?? rawStart) : lastSelectionEndRef.current;
const start = Math.max(rawStart, 0);
const end = Math.max(selectionEnd, 0);
const before = textarea.value.slice(0, start);
const after = textarea.value.slice(end);
const needsLeadingNewline = before.length > 0 && !before.endsWith('\n');
let insertion = `${needsLeadingNewline ? '\n' : ''}${quote}\n`;
if (selectedQuote) {
insertion += `${selectedQuote}\n`;
}
const nextValue = `${before}${insertion}${after}`;
textarea.value = nextValue;
const nextCursor = before.length + insertion.length;
textarea.focus();
textarea.setSelectionRange(nextCursor, nextCursor);
lastSelectionStartRef.current = nextCursor;
lastSelectionEndRef.current = nextCursor;
const publishContent = getContentWithOptions(nextValue, optionsRef.current?.value || '', fortuneEntryRef, diceRollRef, postOptionsDirectoryCode);
setPublishReplyOptions({ content: publishContent });
checkContentLengthRef.current(publishContent, t);
2026-05-29 17:09:07 +07:00
}, [showReplyModal, quoteInsertRequestId, quoteInsertNumber, quoteInsertSelectedText, postOptionsDirectoryCode, setPublishReplyOptions, t]);
const { isUploading, uploadedFileName, handleUpload, uploadFile } = useFileUpload({
onUploadComplete: (uploadedUrl: string) => {
if (uploadedUrl) {
2026-05-01 18:03:04 +07:00
setUrl(uploadedUrl);
if (urlRef.current) {
urlRef.current.value = uploadedUrl;
}
setPublishReplyOptions({ link: uploadedUrl });
}
},
});
const handleOekakiClearUploadedUrl = (uploadedUrl: string) => {
if ((urlRef.current?.value || url) !== uploadedUrl) return;
setUrl('');
if (urlRef.current) {
urlRef.current.value = '';
}
setPublishReplyOptions({ link: '' });
};
const uploadMode = useMediaHostingStore((state) => state.uploadMode);
const showUploadControls = getShowUploadControls(uploadMode, isWebRuntime());
2026-05-01 18:03:04 +07:00
const displayedFileName = getPublishURLFilename(url) || uploadedFileName;
2025-01-26 22:25:56 +01:00
const hasInitializedDisplayName = useRef(false);
useEffect(() => {
if (displayName && !hasInitializedDisplayName.current) {
hasInitializedDisplayName.current = true;
setPublishReplyOptions({ displayName });
}
2025-01-26 23:06:49 +01:00
}, [displayName, setPublishReplyOptions]);
2025-01-26 22:25:56 +01:00
const modalContent = (
<animated.div
className={styles.container}
ref={nodeRef}
role='dialog'
aria-modal='true'
aria-labelledby='reply-modal-title'
style={{
left,
top,
touchAction: 'none',
}}
>
<div id='reply-modal-title' className={`replyModalHandle ${styles.title}`} {...(!isMobile ? bind() : {})}>
2025-12-28 22:16:38 +01:00
{t('reply_to_no', { no: threadNumber ?? '?' })}
<button
type='button'
className={styles.closeIcon}
onClick={(e) => {
e.stopPropagation();
closeModal();
}}
title='close'
aria-label={t('close')}
/>
</div>
<div className={styles.replyForm}>
<div className={styles.name}>
<input
type='text'
aria-label={t('name')}
defaultValue={displayName}
placeholder={displayName ? undefined : capitalize(t('name'))}
2024-08-08 17:48:45 +02:00
onChange={(e) => {
setAccount({ ...account, author: { ...account?.author, displayName: e.target.value } });
2025-01-30 17:09:21 +01:00
setPublishReplyOptions({ displayName: e.target.value });
2024-08-08 17:48:45 +02:00
}}
/>
</div>
<div className={styles.options}>
<input
type='text'
ref={optionsRef}
aria-label={t('options')}
placeholder={capitalize(t('options'))}
autoCorrect='off'
autoComplete='off'
spellCheck='false'
onChange={handleOptionsChange}
/>
</div>
<div className={styles.content}>
2026-05-19 15:45:22 +07:00
{showBbcodeToolbar && (
<BbcodeEditorToolbar
textareaRef={textRef}
onChange={handleContentValueChange}
isPreviewing={isBbcodePreviewing}
onPreviewToggle={handleBbcodePreviewToggle}
/>
)}
{showBbcodeToolbar && isBbcodePreviewing && <BbcodePreview content={bbcodePreviewContent} postCid={postCid} communityAddress={communityAddress} />}
<textarea
cols={48}
rows={4}
wrap='soft'
ref={setTextRef.current}
aria-label={t('comment')}
spellCheck={true}
2026-05-19 15:45:22 +07:00
hidden={showBbcodeToolbar && isBbcodePreviewing}
onInput={handleContentInput}
onChange={handleContentChange}
onSelect={(e) => {
lastSelectionStartRef.current = e.currentTarget.selectionStart ?? e.currentTarget.value.length;
lastSelectionEndRef.current = e.currentTarget.selectionEnd ?? lastSelectionStartRef.current;
}}
onBlur={(e) => {
lastSelectionStartRef.current = e.currentTarget.selectionStart ?? e.currentTarget.value.length;
lastSelectionEndRef.current = e.currentTarget.selectionEnd ?? lastSelectionStartRef.current;
}}
/>
</div>
<div className={styles.link}>
<input
type='text'
ref={urlRef}
aria-label={requirePostLinkIsMedia ? t('link_to_file') : t('link')}
placeholder={requirePostLinkIsMedia ? FILE_LINK_PLACEHOLDER : capitalize(t('link'))}
disabled={isUploading}
onChange={(e) => {
setUrl(e.target.value);
setPublishReplyOptions({ link: e.target.value });
}}
/>
</div>
{showOekakiControls && (
<div className={styles.oekakiRow}>
<span className={styles.oekakiLabel}>Draw</span>
<OekakiDrawingControls className={styles.oekakiControls} disabled={isUploading} uploadFile={uploadFile} onClearUploadedUrl={handleOekakiClearUploadedUrl} />
</div>
)}
{showOekakiControls && isWebRuntime() ? <div className={styles.oekakiWarning}>{OEKAKI_WEB_WARNING_TEXT}</div> : null}
2026-05-24 23:14:36 +07:00
{flagOptions.length > 0 && (
<div>
<select
key={flagOptions.map((option) => option.value).join('|')}
name='flag'
aria-label={t('flag')}
className={styles.flagSelector}
ref={flagRef}
defaultValue={flagOptions[0]?.value}
>
2026-05-24 23:14:36 +07:00
{flagOptions.map((option) => (
<option key={option.value} value={option.value}>
{option.label}
</option>
))}
</select>
</div>
)}
<div className={styles.footer}>
{showUploadControls && (
<span className={styles.uploadContainer}>
<span className={styles.uploadButton}>
<button type='button' onClick={handleUpload} disabled={isUploading}>
{t('choose_file')}
</button>
</span>
2026-05-01 18:03:04 +07:00
<span className={styles.uploadFileName} title={displayedFileName || t('no_file_chosen')}>
2026-05-01 21:12:39 +07:00
{isUploading ? <LoadingEllipsis string={t('uploading')} /> : displayedFileName || t('no_file_chosen')}
</span>
</span>
)}
{showSpoilerForReply && (
<span className={styles.spoilerButton}>
[
<label>
2026-05-29 17:09:07 +07:00
<input type='checkbox' aria-label={capitalize(t('spoiler'))} onChange={(e) => setPublishReplyOptions({ spoiler: e.target.checked })} />
{capitalize(t('spoiler'))}?
</label>
]
</span>
)}
<button className={styles.publishButton} disabled={isResolvingExternalQuotes} type='button' onClick={onPublishReply}>
{t('post')}
</button>
</div>
{moderationPostingWarning ? <div className={styles.error}>{moderationPostingWarning}</div> : null}
{lengthError ? (
<div className={styles.error}>{lengthError}</div>
) : error ? (
<div className={styles.error}>{isPostOptionsValidationError(error) ? <PostOptionsErrorMessage error={error} directories={directories} /> : error}</div>
) : (
publishReplyError && <div className={styles.error}>{publishReplyError}</div>
)}
{publishReplyStateMessage && <div className={styles.status}>{publishReplyStateMessage}</div>}
<BoardOfflineAlert className={styles.offlineBoard} hidden={isInAllView || isInSubscriptionsView || isInModView} communityAddress={communityAddress} />
</div>
</animated.div>
);
return showReplyModal && modalContent;
2024-04-28 20:08:41 +02:00
};
export default ReplyModal;