From a74c5201bc28cab556f6502f36622ded26b591fc Mon Sep 17 00:00:00 2001 From: keyan Date: Tue, 21 Nov 2023 12:49:22 -0600 Subject: [PATCH] reply cancel confirm --- components/reply.js | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/components/reply.js b/components/reply.js index e809a08e..e4a646e2 100644 --- a/components/reply.js +++ b/components/reply.js @@ -12,6 +12,8 @@ import { COMMENT_DEPTH_LIMIT } from '../lib/constants' import { useToast } from './toast' import { toastDeleteScheduled } from '../lib/form' import { ItemButtonBar } from './post' +import { useShowModal } from './modal' +import { Button } from 'react-bootstrap' export function ReplyOnAnotherPage ({ item }) { const path = item.path.split('.') @@ -35,6 +37,7 @@ export default forwardRef(function Reply ({ item, onSuccess, replyOpen, children const parentId = item.id const replyInput = useRef(null) const toaster = useToast() + const showModal = useShowModal() useEffect(() => { if (replyOpen || quote || !!window.localStorage.getItem('reply-' + parentId + '-' + 'text')) { @@ -102,6 +105,12 @@ export default forwardRef(function Reply ({ item, onSuccess, replyOpen, children if (replyInput.current && reply && !replyOpen) replyInput.current.focus() }, [reply]) + const onCancel = useCallback(() => { + window.localStorage.removeItem('reply-' + parentId + '-' + 'text') + setReply(false) + onCancelQuote?.() + }, [setReply, parentId, onCancelQuote]) + return (
{replyOpen @@ -112,9 +121,25 @@ export default forwardRef(function Reply ({ item, onSuccess, replyOpen, children className='pe-3' onClick={e => { if (reply) { - window.localStorage.removeItem('reply-' + parentId + '-' + 'text') - setReply(false) - onCancelQuote?.() + const text = window.localStorage.getItem('reply-' + parentId + '-' + 'text') + if (text?.trim()) { + showModal(onClose => ( + <> +

Are you sure? You will lose your work

+
+ +
+ + )) + } else { + onCancel() + } } else { e.preventDefault() onQuoteReply({ selectionOnly: true })