Skip to content

Commit

Permalink
fix(comments): use current editor value over snapshot to update comment
Browse files Browse the repository at this point in the history
  • Loading branch information
skogsmaskin committed Oct 24, 2023
1 parent 8c6ee1b commit 4ca954e
Showing 1 changed file with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ export const CommentInput = forwardRef<CommentInputHandle, CommentInputProps>(

const handleChange = useCallback(
(change: EditorChange) => {
// Focus the editor when ready if focusOnMount is true
if (change.type === 'ready') {
if (focusOnMount && editorRef.current) {
PortableTextEditor.focus(editorRef.current)
Expand All @@ -82,8 +83,12 @@ export const CommentInput = forwardRef<CommentInputHandle, CommentInputProps>(
setFocused(false)
}

if (change.type === 'mutation' && change.snapshot) {
onChange(change.snapshot)
// Update the comment value whenever the comment is edited by the user.
if (change.type === 'patch' && editorRef.current) {
const editorStateValue = PortableTextEditor.getValue(editorRef.current)
if (editorStateValue) {
onChange(editorStateValue)
}
}
},
[focusOnMount, onChange],
Expand Down

0 comments on commit 4ca954e

Please sign in to comment.