From 669ad67ddc6be2b8bd78aa10cc08412aef01ed2b Mon Sep 17 00:00:00 2001 From: ekzyis Date: Fri, 24 May 2024 14:21:26 -0500 Subject: [PATCH] Fix reply stays prefilled after submit --- components/notifications.js | 3 ++- components/reply.js | 13 +++---------- 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/components/notifications.js b/components/notifications.js index 180e06b13..af4cece07 100644 --- a/components/notifications.js +++ b/components/notifications.js @@ -167,7 +167,8 @@ const onClickFailedItem = ({ n }) => { } const rootId = commentSubTreeRootId(n.item) - const query = { id: rootId, text } + window.localStorage.setItem('reply-' + parentId + '-' + 'text', text) + const query = { id: rootId } if (Number(rootId) !== Number(parentId)) { query.commentId = parentId } diff --git a/components/reply.js b/components/reply.js index b3320d21c..2d6be210f 100644 --- a/components/reply.js +++ b/components/reply.js @@ -15,7 +15,6 @@ import { useShowModal } from './modal' import { Button } from 'react-bootstrap' import { useRoot } from './root' import { commentSubTreeRootId } from '@/lib/item' -import { useRouter } from 'next/router' export function ReplyOnAnotherPage ({ item }) { const rootId = commentSubTreeRootId(item) @@ -41,18 +40,12 @@ export default forwardRef(function Reply ({ item, onSuccess, replyOpen, children const showModal = useShowModal() const root = useRoot() const sub = item?.sub || root?.sub - const router = useRouter() - - const prefill = router.query.text && - (router.query.commentId - ? router.query.commentId === parentId - : router.query.id === parentId) useEffect(() => { - if (replyOpen || quote || !!window.localStorage.getItem('reply-' + parentId + '-' + 'text') || prefill) { + if (replyOpen || quote || !!window.localStorage.getItem('reply-' + parentId + '-' + 'text')) { setReply(true) } - }, [replyOpen, quote, parentId, prefill]) + }, [replyOpen, quote, parentId]) const [upsertComment] = useMutation( gql` @@ -179,7 +172,7 @@ export default forwardRef(function Reply ({ item, onSuccess, replyOpen, children >