diff --git a/components/comment-edit.js b/components/comment-edit.js index 97c59c1d5..7b66edbeb 100644 --- a/components/comment-edit.js +++ b/components/comment-edit.js @@ -37,6 +37,7 @@ export default function CommentEdit ({ comment, editThreshold, onSuccess, onCanc }} schema={commentSchema} onSubmit={onSubmit} + storageKeyPrefix={`comment-edit-${comment.id}`} > } edit={edit} - toggleEdit={e => { setEdit(!edit) }} + toggleEdit={e => { + if (edit) { + const editText = window.localStorage.getItem(`comment-edit-${item.id}-text`) + if (editText && editText.trim() !== item.text.trim()) { + showModal(onClose => ( + { + window.localStorage.removeItem(`comment-edit-${item.id}-text`) + setEdit(false) + }} + onClose={onClose} + /> + )) + } else { + setEdit(false) + } + } else { + setEdit(true) + } + }} editText={edit ? 'cancel' : 'edit'} />} diff --git a/components/confirm-modal.js b/components/confirm-modal.js new file mode 100644 index 000000000..4763b137e --- /dev/null +++ b/components/confirm-modal.js @@ -0,0 +1,38 @@ +import Button from 'react-bootstrap/Button' + +export default function ConfirmModal ({ + onConfirm, + message = 'Are you sure?', + confirmText = 'yep', + confirmVariant = 'info', + onClose +}) { + return ( + <> +

{message}

+
+ +
+ + ) +} + +export function CancelWorkConfirm ({ onConfirm, onClose }) { + return ( + + ) +} diff --git a/components/reply.js b/components/reply.js index b47c97579..f589ccc91 100644 --- a/components/reply.js +++ b/components/reply.js @@ -6,7 +6,7 @@ import { FeeButtonProvider, postCommentBaseLineItems, postCommentUseRemoteLineIt import { commentSchema } from '@/lib/validate' import { ItemButtonBar } from './post' import { useShowModal } from './modal' -import { Button } from 'react-bootstrap' +import { CancelWorkConfirm } from './confirm-modal' import { useRoot } from './root' import { CREATE_COMMENT } from '@/fragments/paidAction' import { injectComment } from '@/lib/comments' @@ -99,18 +99,10 @@ export default forwardRef(function Reply ({ const text = window.localStorage.getItem('reply-' + parentId + '-' + 'text') if (text?.trim()) { showModal(onClose => ( - <> -

Are you sure? You will lose your work

-
- -
- + )) } else { onCancel()