Add autosave for comments

This commit is contained in:
Sinclair Chen 2022-10-07 18:40:23 -07:00
parent 881e480819
commit 8d945b4c55
4 changed files with 16 additions and 4 deletions

View File

@ -17,13 +17,21 @@ export function CommentInput(props: {
// Reply to another comment
parentCommentId?: string
onSubmitComment?: (editor: Editor) => void
// unique id for autosave
pageId: string
className?: string
}) {
const { parentAnswerOutcome, parentCommentId, replyTo, onSubmitComment } =
props
const {
parentAnswerOutcome,
parentCommentId,
replyTo,
onSubmitComment,
pageId,
} = props
const user = useUser()
const { editor, upload } = useTextEditor({
key: `comment ${pageId} ${parentCommentId ?? parentAnswerOutcome ?? ''}`,
simple: true,
max: MAX_COMMENT_LENGTH,
placeholder:
@ -107,7 +115,7 @@ export function CommentInputTextArea(props: {
},
})
// insert at mention and focus
if (replyTo) {
if (replyTo && editor.isEmpty) {
editor
.chain()
.setContent({

View File

@ -105,7 +105,9 @@ export function useTextEditor(props: {
)
const editor = useEditor({
editorProps: { attributes: { class: editorClass, spellcheck: 'false' } },
editorProps: {
attributes: { class: editorClass, spellcheck: simple ? 'true' : 'false' },
},
onUpdate: key ? ({ editor }) => save(editor.getJSON()) : undefined,
extensions: [
StarterKit.configure({

View File

@ -262,6 +262,7 @@ export function ContractCommentInput(props: {
parentAnswerOutcome={parentAnswerOutcome}
parentCommentId={parentCommentId}
onSubmitComment={onSubmitComment}
pageId={contract.id}
className={className}
/>
)

View File

@ -94,6 +94,7 @@ export function PostCommentInput(props: {
replyTo={replyToUser}
parentCommentId={parentCommentId}
onSubmitComment={onSubmitComment}
pageId={post.id}
/>
)
}