Remove disabled state from useTextEditor

This commit is contained in:
Austin Chen 2022-10-12 16:36:43 -07:00
parent bc9e0778cf
commit 4f7ae3d99d
7 changed files with 2 additions and 23 deletions

View File

@ -45,13 +45,11 @@ function RichEditContract(props: { contract: Contract; isAdmin?: boolean }) {
const { contract, isAdmin } = props
const [editing, setEditing] = useState(false)
const [editingQ, setEditingQ] = useState(false)
const [isSubmitting, setIsSubmitting] = useState(false)
const { editor, upload } = useTextEditor({
// key: `description ${contract.id}`,
max: MAX_DESCRIPTION_LENGTH,
defaultValue: contract.description,
disabled: isSubmitting,
})
async function saveDescription() {
@ -66,10 +64,8 @@ function RichEditContract(props: { contract: Contract; isAdmin?: boolean }) {
<Row className="gap-2">
<Button
onClick={async () => {
setIsSubmitting(true)
await saveDescription()
setEditing(false)
setIsSubmitting(false)
}}
>
Save

View File

@ -22,7 +22,6 @@ export function CreatePost(props: { group?: Group }) {
const { editor, upload } = useTextEditor({
key: `post ${group?.id || ''}`,
disabled: isSubmitting,
})
const isValid =

View File

@ -97,11 +97,10 @@ export function useTextEditor(props: {
placeholder?: string
max?: number
defaultValue?: Content
disabled?: boolean
simple?: boolean
key?: string // unique key for autosave. If set, plz call `clearContent(true)` on submit to clear autosave
}) {
const { placeholder, max, defaultValue, disabled, simple, key } = props
const { placeholder, max, defaultValue, simple, key } = props
const [content, saveContent] = usePersistentState<JSONContent | undefined>(
undefined,
@ -169,10 +168,6 @@ export function useTextEditor(props: {
},
})
useEffect(() => {
editor?.setEditable(!disabled)
}, [editor, disabled])
return { editor, upload }
}

View File

@ -33,11 +33,9 @@ export function GroupOverviewPost(props: {
function RichEditGroupAboutPost(props: { group: Group; post: Post | null }) {
const { group, post } = props
const [editing, setEditing] = useState(false)
const [isSubmitting, setIsSubmitting] = useState(false)
const { editor, upload } = useTextEditor({
defaultValue: post?.content,
disabled: isSubmitting,
})
async function savePost() {
@ -76,10 +74,8 @@ function RichEditGroupAboutPost(props: { group: Group; post: Post | null }) {
<Row className="gap-2">
<Button
onClick={async () => {
setIsSubmitting(true)
await savePost()
setEditing(false)
setIsSubmitting(false)
}}
>
Save

View File

@ -229,7 +229,6 @@ export function NewContract(props: {
key: 'create market',
max: MAX_DESCRIPTION_LENGTH,
placeholder: descriptionPlaceholder,
disabled: isSubmitting,
defaultValue: params?.description
? JSON.parse(params.description)
: undefined,

View File

@ -35,9 +35,7 @@ export default function CreateDateDocPage() {
const [isSubmitting, setIsSubmitting] = useState(false)
const { editor, upload } = useTextEditor({
disabled: isSubmitting,
})
const { editor, upload } = useTextEditor({})
const birthdayTime = birthday ? dayjs(birthday).valueOf() : undefined
const isValid =

View File

@ -171,11 +171,9 @@ export function PostCommentsActivity(props: {
export function RichEditPost(props: { post: Post }) {
const { post } = props
const [editing, setEditing] = useState(false)
const [isSubmitting, setIsSubmitting] = useState(false)
const { editor, upload } = useTextEditor({
defaultValue: post.content,
disabled: isSubmitting,
})
async function savePost() {
@ -193,10 +191,8 @@ export function RichEditPost(props: { post: Post }) {
<Row className="gap-2">
<Button
onClick={async () => {
setIsSubmitting(true)
await savePost()
setEditing(false)
setIsSubmitting(false)
}}
>
Save