mirror of
https://github.com/bitsocialnet/5chan.git
synced 2026-08-03 07:41:04 +02:00
fix(reply modal): keep textarea empty when opened from Post a Reply footer button
This commit is contained in:
@@ -50,6 +50,7 @@ const ReplyModal = ({ closeModal, showReplyModal, parentCid, parentNumber, threa
|
||||
const lastSelectionEndRef = useRef(0);
|
||||
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);
|
||||
@@ -195,7 +196,7 @@ const ReplyModal = ({ closeModal, showReplyModal, parentCid, parentNumber, threa
|
||||
useEffect(() => {
|
||||
if (showReplyModal && textRef.current) {
|
||||
textRef.current.spellcheck = false;
|
||||
textRef.current.value = `${defaultParentQuote}${selectedText || ''}`;
|
||||
textRef.current.value = openEmpty ? selectedText || '' : `${defaultParentQuote}${selectedText || ''}`;
|
||||
const len = textRef.current.value.length;
|
||||
lastSelectionStartRef.current = len;
|
||||
lastSelectionEndRef.current = len;
|
||||
@@ -209,7 +210,7 @@ const ReplyModal = ({ closeModal, showReplyModal, parentCid, parentNumber, threa
|
||||
}
|
||||
}, 100);
|
||||
}
|
||||
}, [showReplyModal, defaultParentQuote, selectedText]);
|
||||
}, [showReplyModal, openEmpty, defaultParentQuote, selectedText]);
|
||||
|
||||
const handleContentInput = (e: React.ChangeEvent<HTMLTextAreaElement>) => {
|
||||
lastSelectionStartRef.current = e.target.selectionStart ?? e.target.value.length;
|
||||
|
||||
@@ -3,6 +3,8 @@ import useSelectedTextStore from './use-selected-text-store';
|
||||
|
||||
interface ReplyModalState {
|
||||
showReplyModal: boolean;
|
||||
/** True when opened via "Post a Reply" footer button — textarea should be empty, no quote. */
|
||||
openEmpty: boolean;
|
||||
activeCid: string | null;
|
||||
parentNumber: number | null;
|
||||
threadNumber: number | null;
|
||||
@@ -35,6 +37,7 @@ const getQuotedSelection = () => {
|
||||
|
||||
const useReplyModalStore = create<ReplyModalState>((set, get) => ({
|
||||
showReplyModal: false,
|
||||
openEmpty: false,
|
||||
activeCid: null,
|
||||
parentNumber: null,
|
||||
threadNumber: null,
|
||||
@@ -50,6 +53,7 @@ const useReplyModalStore = create<ReplyModalState>((set, get) => ({
|
||||
useSelectedTextStore.getState().resetSelectedText();
|
||||
set({
|
||||
showReplyModal: false,
|
||||
openEmpty: false,
|
||||
activeCid: null,
|
||||
parentNumber: null,
|
||||
threadNumber: null,
|
||||
@@ -80,6 +84,7 @@ const useReplyModalStore = create<ReplyModalState>((set, get) => ({
|
||||
const scrollY = isMobile ? window.scrollY : 0;
|
||||
|
||||
set({
|
||||
openEmpty: false,
|
||||
activeCid: postCid,
|
||||
parentNumber: parentNumber ?? null,
|
||||
threadNumber: threadNumber ?? null,
|
||||
@@ -95,6 +100,7 @@ const useReplyModalStore = create<ReplyModalState>((set, get) => ({
|
||||
const isMobile = window.innerWidth <= 768;
|
||||
const scrollY = isMobile ? window.scrollY : 0;
|
||||
set({
|
||||
openEmpty: true,
|
||||
activeCid: postCid,
|
||||
parentNumber: null,
|
||||
threadNumber: threadNumber ?? null,
|
||||
|
||||
Reference in New Issue
Block a user