Remove disabled state from useTextEditor
This commit is contained in:
parent
bc9e0778cf
commit
4f7ae3d99d
|
@ -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
|
||||
|
|
|
@ -22,7 +22,6 @@ export function CreatePost(props: { group?: Group }) {
|
|||
|
||||
const { editor, upload } = useTextEditor({
|
||||
key: `post ${group?.id || ''}`,
|
||||
disabled: isSubmitting,
|
||||
})
|
||||
|
||||
const isValid =
|
||||
|
|
|
@ -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 }
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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 =
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue
Block a user