From c6b9089c6a496c7b2297165979fbd8a51442c3b5 Mon Sep 17 00:00:00 2001 From: Patrick O'Sullivan Date: Thu, 12 May 2022 10:31:29 -0500 Subject: [PATCH] groups: add submitted state for notebook form --- .../publish/components/MarkdownEditor.tsx | 8 ++- .../apps/publish/components/MarkdownField.tsx | 12 ++-- .../apps/publish/components/NoteForm.tsx | 72 ++++++++++++------- 3 files changed, 61 insertions(+), 31 deletions(-) diff --git a/pkg/interface/src/views/apps/publish/components/MarkdownEditor.tsx b/pkg/interface/src/views/apps/publish/components/MarkdownEditor.tsx index 450bc96825..c0c4f07d2f 100644 --- a/pkg/interface/src/views/apps/publish/components/MarkdownEditor.tsx +++ b/pkg/interface/src/views/apps/publish/components/MarkdownEditor.tsx @@ -23,6 +23,7 @@ interface MarkdownEditorProps { value: string; onChange: (s: string) => void; onBlur?: (e: any) => void; + disabled?: boolean; } const PromptIfDirty = () => { @@ -39,7 +40,7 @@ const PromptIfDirty = () => { export function MarkdownEditor( props: MarkdownEditorProps & PropFunc ) { - const { onBlur, placeholder, value, onChange, ...boxProps } = props; + const { onBlur, placeholder, value, onChange, disabled, ...boxProps } = props; const options = { mode: MARKDOWN_CONFIG, @@ -56,7 +57,9 @@ export function MarkdownEditor( const handleChange = useCallback( (_e, _d, v: string) => { - onChange(v); + if (!disabled) { + onChange(v); + } }, [onChange] ); @@ -93,6 +96,7 @@ export function MarkdownEditor( p={1} border={1} borderColor="lightGray" + backgroundColor={disabled ? '#eee' : '#fff'} borderRadius={2} height={['calc(100% - 22vh)', '100%']} {...boxProps} diff --git a/pkg/interface/src/views/apps/publish/components/MarkdownField.tsx b/pkg/interface/src/views/apps/publish/components/MarkdownField.tsx index f779b1c6a4..20ff071daf 100644 --- a/pkg/interface/src/views/apps/publish/components/MarkdownField.tsx +++ b/pkg/interface/src/views/apps/publish/components/MarkdownField.tsx @@ -6,14 +6,17 @@ import { MarkdownEditor } from './MarkdownEditor'; export const MarkdownField = ({ id, + disabled, ...rest -}: { id: string } & Parameters[0]) => { +}: { id: string; disabled?: boolean } & Parameters[0]) => { const [{ value, onBlur }, { error, touched }, { setValue }] = useField(id); const handleBlur = useCallback( (e: any) => { - _.set(e, 'target.id', id); - onBlur && onBlur(e); + if (!disabled) { + _.set(e, 'target.id', id); + onBlur && onBlur(e); + } }, [onBlur, id] ); @@ -23,7 +26,7 @@ export const MarkdownField = ({ return ( {error} diff --git a/pkg/interface/src/views/apps/publish/components/NoteForm.tsx b/pkg/interface/src/views/apps/publish/components/NoteForm.tsx index 42fa905d2a..ca484c036b 100644 --- a/pkg/interface/src/views/apps/publish/components/NoteForm.tsx +++ b/pkg/interface/src/views/apps/publish/components/NoteForm.tsx @@ -1,5 +1,7 @@ import { - Button, Col, ManagedTextInputField as Input, + Button, + Col, + ManagedTextInputField as Input, Row } from '@tlon/indigo-react'; import { Form, Formik, FormikHelpers } from 'formik'; @@ -31,7 +33,8 @@ export interface PostFormSchema { } export function PostForm(props: PostFormProps) { - const { initial, onSubmit, submitLabel, loadingText, cancel, history } = props; + const { initial, onSubmit, submitLabel, loadingText, cancel, history } = + props; return ( @@ -40,30 +43,49 @@ export function PostForm(props: PostFormProps) { initialValues={initial} onSubmit={onSubmit} > -
- - - - - {submitLabel} - - {cancel && } + {({ isSubmitting }) => ( + + + + + + {submitLabel} + + {cancel && ( + + )} + - - - + + + )} );