mirror of
https://github.com/bitsocialnet/5chan.git
synced 2026-08-03 07:41:04 +02:00
implement selection to greentext in ReplyModal
This commit is contained in:
@@ -29,12 +29,36 @@ const ReplyModal = ({ isOpen, closeModal }) => {
|
|||||||
const linkRef = useRef();
|
const linkRef = useRef();
|
||||||
|
|
||||||
const [errorMessage, setErrorMessage] = useState(null);
|
const [errorMessage, setErrorMessage] = useState(null);
|
||||||
|
const [triggerPublishComment, setTriggerPublishComment] = useState(false);
|
||||||
|
const [selectedText, setSelectedText] = useState('');
|
||||||
|
|
||||||
useError(errorMessage, [errorMessage]);
|
useError(errorMessage, [errorMessage]);
|
||||||
|
|
||||||
const [triggerPublishComment, setTriggerPublishComment] = useState(false);
|
|
||||||
|
|
||||||
const location = useLocation();
|
const location = useLocation();
|
||||||
|
|
||||||
|
|
||||||
|
const onModalOpen = () => {
|
||||||
|
if (commentRef.current) {
|
||||||
|
commentRef.current.focus();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
const getSelectedText = useCallback(() => {
|
||||||
|
const text = document.getSelection().toString();
|
||||||
|
setSelectedText(text ? `>${text}\n` : '');
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (isOpen) {
|
||||||
|
getSelectedText();
|
||||||
|
} else {
|
||||||
|
setSelectedText('');
|
||||||
|
}
|
||||||
|
}, [isOpen, getSelectedText]);
|
||||||
|
|
||||||
|
|
||||||
const onChallengeVerification = (challengeVerification) => {
|
const onChallengeVerification = (challengeVerification) => {
|
||||||
if (challengeVerification.challengeSuccess === true) {
|
if (challengeVerification.challengeSuccess === true) {
|
||||||
console.log('challenge success');
|
console.log('challenge success');
|
||||||
@@ -168,6 +192,7 @@ const ReplyModal = ({ isOpen, closeModal }) => {
|
|||||||
return (
|
return (
|
||||||
<StyledModal
|
<StyledModal
|
||||||
isOpen={isOpen}
|
isOpen={isOpen}
|
||||||
|
onAfterOpen={onModalOpen}
|
||||||
onRequestClose={closeModal}
|
onRequestClose={closeModal}
|
||||||
contentLabel="Reply Modal"
|
contentLabel="Reply Modal"
|
||||||
shouldCloseOnEsc={false}
|
shouldCloseOnEsc={false}
|
||||||
@@ -189,7 +214,12 @@ const ReplyModal = ({ isOpen, closeModal }) => {
|
|||||||
</div>
|
</div>
|
||||||
<div className="textarea-wrapper">
|
<div className="textarea-wrapper">
|
||||||
<span className="fixed-text">{`c/${selectedShortCid}`}</span>
|
<span className="fixed-text">{`c/${selectedShortCid}`}</span>
|
||||||
<textarea className="textarea" rows="4" placeholder="Comment" wrap="soft" ref={commentRef} />
|
<textarea className="textarea"
|
||||||
|
rows="4"
|
||||||
|
placeholder="Comment"
|
||||||
|
defaultValue={selectedText}
|
||||||
|
wrap="soft"
|
||||||
|
ref={commentRef} />
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<button id="next" onClick={handleSubmit}>Post</button>
|
<button id="next" onClick={handleSubmit}>Post</button>
|
||||||
|
|||||||
Reference in New Issue
Block a user