Add autosave for comments
This commit is contained in:
parent
881e480819
commit
8d945b4c55
|
@ -17,13 +17,21 @@ export function CommentInput(props: {
|
||||||
// Reply to another comment
|
// Reply to another comment
|
||||||
parentCommentId?: string
|
parentCommentId?: string
|
||||||
onSubmitComment?: (editor: Editor) => void
|
onSubmitComment?: (editor: Editor) => void
|
||||||
|
// unique id for autosave
|
||||||
|
pageId: string
|
||||||
className?: string
|
className?: string
|
||||||
}) {
|
}) {
|
||||||
const { parentAnswerOutcome, parentCommentId, replyTo, onSubmitComment } =
|
const {
|
||||||
props
|
parentAnswerOutcome,
|
||||||
|
parentCommentId,
|
||||||
|
replyTo,
|
||||||
|
onSubmitComment,
|
||||||
|
pageId,
|
||||||
|
} = props
|
||||||
const user = useUser()
|
const user = useUser()
|
||||||
|
|
||||||
const { editor, upload } = useTextEditor({
|
const { editor, upload } = useTextEditor({
|
||||||
|
key: `comment ${pageId} ${parentCommentId ?? parentAnswerOutcome ?? ''}`,
|
||||||
simple: true,
|
simple: true,
|
||||||
max: MAX_COMMENT_LENGTH,
|
max: MAX_COMMENT_LENGTH,
|
||||||
placeholder:
|
placeholder:
|
||||||
|
@ -107,7 +115,7 @@ export function CommentInputTextArea(props: {
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
// insert at mention and focus
|
// insert at mention and focus
|
||||||
if (replyTo) {
|
if (replyTo && editor.isEmpty) {
|
||||||
editor
|
editor
|
||||||
.chain()
|
.chain()
|
||||||
.setContent({
|
.setContent({
|
||||||
|
|
|
@ -105,7 +105,9 @@ export function useTextEditor(props: {
|
||||||
)
|
)
|
||||||
|
|
||||||
const editor = useEditor({
|
const editor = useEditor({
|
||||||
editorProps: { attributes: { class: editorClass, spellcheck: 'false' } },
|
editorProps: {
|
||||||
|
attributes: { class: editorClass, spellcheck: simple ? 'true' : 'false' },
|
||||||
|
},
|
||||||
onUpdate: key ? ({ editor }) => save(editor.getJSON()) : undefined,
|
onUpdate: key ? ({ editor }) => save(editor.getJSON()) : undefined,
|
||||||
extensions: [
|
extensions: [
|
||||||
StarterKit.configure({
|
StarterKit.configure({
|
||||||
|
|
|
@ -262,6 +262,7 @@ export function ContractCommentInput(props: {
|
||||||
parentAnswerOutcome={parentAnswerOutcome}
|
parentAnswerOutcome={parentAnswerOutcome}
|
||||||
parentCommentId={parentCommentId}
|
parentCommentId={parentCommentId}
|
||||||
onSubmitComment={onSubmitComment}
|
onSubmitComment={onSubmitComment}
|
||||||
|
pageId={contract.id}
|
||||||
className={className}
|
className={className}
|
||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
|
|
|
@ -94,6 +94,7 @@ export function PostCommentInput(props: {
|
||||||
replyTo={replyToUser}
|
replyTo={replyToUser}
|
||||||
parentCommentId={parentCommentId}
|
parentCommentId={parentCommentId}
|
||||||
onSubmitComment={onSubmitComment}
|
onSubmitComment={onSubmitComment}
|
||||||
|
pageId={post.id}
|
||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user