feat: support replies

This commit is contained in:
Stevan Freeborn
2023-09-14 21:47:40 -05:00
parent 0dc2934e05
commit 820ba6b1e8
14 changed files with 344 additions and 97 deletions
+9 -1
View File
@@ -8,7 +8,7 @@ import { languages } from '@codemirror/language-data';
import { Compartment, EditorState, Text } from '@codemirror/state';
import { EditorView, keymap } from '@codemirror/view';
import { basicSetup } from 'codemirror';
import { FormEvent, useState } from 'react';
import { FormEvent, useEffect, useState } from 'react';
import { Doc, Id } from '../../convex/_generated/dataModel';
import PostContent from './PostContent';
@@ -24,6 +24,7 @@ export default function Editor({
parentPostId,
post,
submitAction,
autofocus = true,
}: {
clerkUserId: string;
parentPostId?: Id<'posts'>;
@@ -34,6 +35,7 @@ export default function Editor({
post,
currentDoc,
}: SubmitActionParams) => Promise<void>;
autofocus?: boolean;
}) {
const editorTheme = new Compartment();
const [currentDoc, setCurrentDoc] = useState(post?.content ?? ['']);
@@ -58,6 +60,12 @@ export default function Editor({
extensions,
});
useEffect(() => {
if (editorView !== null && autofocus) {
editorView.focus();
}
}, [autofocus, editorView]);
async function handleSubmit(e: FormEvent<HTMLFormElement>) {
e.preventDefault();