reply cancel confirm
This commit is contained in:
parent
21c1fd11ba
commit
a74c5201bc
@ -12,6 +12,8 @@ import { COMMENT_DEPTH_LIMIT } from '../lib/constants'
|
|||||||
import { useToast } from './toast'
|
import { useToast } from './toast'
|
||||||
import { toastDeleteScheduled } from '../lib/form'
|
import { toastDeleteScheduled } from '../lib/form'
|
||||||
import { ItemButtonBar } from './post'
|
import { ItemButtonBar } from './post'
|
||||||
|
import { useShowModal } from './modal'
|
||||||
|
import { Button } from 'react-bootstrap'
|
||||||
|
|
||||||
export function ReplyOnAnotherPage ({ item }) {
|
export function ReplyOnAnotherPage ({ item }) {
|
||||||
const path = item.path.split('.')
|
const path = item.path.split('.')
|
||||||
@ -35,6 +37,7 @@ export default forwardRef(function Reply ({ item, onSuccess, replyOpen, children
|
|||||||
const parentId = item.id
|
const parentId = item.id
|
||||||
const replyInput = useRef(null)
|
const replyInput = useRef(null)
|
||||||
const toaster = useToast()
|
const toaster = useToast()
|
||||||
|
const showModal = useShowModal()
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (replyOpen || quote || !!window.localStorage.getItem('reply-' + parentId + '-' + 'text')) {
|
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()
|
if (replyInput.current && reply && !replyOpen) replyInput.current.focus()
|
||||||
}, [reply])
|
}, [reply])
|
||||||
|
|
||||||
|
const onCancel = useCallback(() => {
|
||||||
|
window.localStorage.removeItem('reply-' + parentId + '-' + 'text')
|
||||||
|
setReply(false)
|
||||||
|
onCancelQuote?.()
|
||||||
|
}, [setReply, parentId, onCancelQuote])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
{replyOpen
|
{replyOpen
|
||||||
@ -112,9 +121,25 @@ export default forwardRef(function Reply ({ item, onSuccess, replyOpen, children
|
|||||||
className='pe-3'
|
className='pe-3'
|
||||||
onClick={e => {
|
onClick={e => {
|
||||||
if (reply) {
|
if (reply) {
|
||||||
window.localStorage.removeItem('reply-' + parentId + '-' + 'text')
|
const text = window.localStorage.getItem('reply-' + parentId + '-' + 'text')
|
||||||
setReply(false)
|
if (text?.trim()) {
|
||||||
onCancelQuote?.()
|
showModal(onClose => (
|
||||||
|
<>
|
||||||
|
<p className='fw-bolder'>Are you sure? You will lose your work</p>
|
||||||
|
<div className='d-flex justify-content-end'>
|
||||||
|
<Button
|
||||||
|
variant='info' onClick={() => {
|
||||||
|
onCancel()
|
||||||
|
onClose()
|
||||||
|
}}
|
||||||
|
>yep
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
))
|
||||||
|
} else {
|
||||||
|
onCancel()
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
onQuoteReply({ selectionOnly: true })
|
onQuoteReply({ selectionOnly: true })
|
||||||
|
Loading…
x
Reference in New Issue
Block a user