Skip to content

Commit

Permalink
Fix reply stays prefilled after submit
Browse files Browse the repository at this point in the history
  • Loading branch information
ekzyis committed May 24, 2024
1 parent 1b6b02a commit 669ad67
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 11 deletions.
3 changes: 2 additions & 1 deletion components/notifications.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
13 changes: 3 additions & 10 deletions components/reply.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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`
Expand Down Expand Up @@ -179,7 +172,7 @@ export default forwardRef(function Reply ({ item, onSuccess, replyOpen, children
>
<Form
initial={{
text: prefill ? router.query.text : ''
text: ''
}}
schema={commentSchema}
prepaid
Expand Down

0 comments on commit 669ad67

Please sign in to comment.