🎥 Make videos programmatically with React
isCustomDate state removed
Patric Salvisbergde8fc9a6f260
diff --git a/packages/cli/src/editor/components/RenderModal/RenderModalData.tsx b/packages/cli/src/editor/components/RenderModal/RenderModalData.tsxindex 0ce16658ba..1ce34279c6 100644--- a/packages/cli/src/editor/components/RenderModal/RenderModalData.tsx+++ b/packages/cli/src/editor/components/RenderModal/RenderModalData.tsx@@ -22,6 +22,11 @@ import {SegmentedControl} from '../SegmentedControl';import type {TypeCanSaveState} from './get-render-modal-warnings';import {getRenderModalWarnings} from './get-render-modal-warnings';import {RenderModalJSONPropsEditor} from './RenderModalJSONPropsEditor';+import type {SerializedJSONWithDate} from './SchemaEditor/date-serialization';+import {+ deserializeJSONWithDate,+ serializeJSONWithDate,+} from './SchemaEditor/date-serialization';import {SchemaEditor} from './SchemaEditor/SchemaEditor';import {NoDefaultProps,@@ -31,6 +36,18 @@ import {WarningIndicatorButton} from './WarningIndicatorButton';type Mode = 'json' | 'schema';+export type State =+ | {+ str: string;+ value: unknown;+ validJSON: true;+ }+ | {+ str: string;+ validJSON: false;+ error: string;+ };+export type PropsEditType = 'input-props' | 'default-props';const errorExplanation: React.CSSProperties = {@@ -73,6 +90,15 @@ const tabWrapper: React.CSSProperties = {const persistanceKey = 'remotion.show-render-modalwarning';+const parseJSON = (str: string): State => {+ try {+ const value = deserializeJSONWithDate(str);+ return {str, value, validJSON: true};+ } catch (e) {+ return {str, validJSON: false, error: (e as Error).message};+ }+};+const getPersistedShowWarningState = () => {const val = localStorage.getItem(persistanceKey);if (!val) {@@ -103,7 +129,6 @@ export const RenderModalData: React.FC<{}) => {const [mode, setMode] = useState<Mode>('schema');const [valBeforeSafe, setValBeforeSafe] = useState<unknown>(inputProps);- const [isCustomDateUsed, setIsCustomDateUsed] = useState<boolean>();const [saving, setSaving] = useState(false);const zodValidationResult = useMemo(() => {return composition.schema.safeParse(inputProps);@@ -111,6 +136,17 @@ export const RenderModalData: React.FC<{const [showWarning, setShowWarningWithoutPersistance] = useState<boolean>(() => getPersistedShowWarningState());++ const serializedJSON: SerializedJSONWithDate = useMemo(() => {+ const value = inputProps ?? {};+ return serializeJSONWithDate(value, 2);+ }, [inputProps]);++ const isCustomDateUsed = serializedJSON.customDateUsed;+ const [localValue, setLocalValue] = React.useState<State>(() => {+ return parseJSON(serializedJSON.serializedString);+ });+const cliProps = getInputProps();const [canSaveDefaultProps, setCanSaveDefaultProps] =useState<TypeCanSaveState>({@@ -293,7 +329,9 @@ export const RenderModalData: React.FC<{onSave={onUpdate}valBeforeSafe={valBeforeSafe}showSaveButton={showSaveButton}- setIsCustomDateUsed={setIsCustomDateUsed}+ localValue={localValue}+ setLocalValue={setLocalValue}+ parseJSON={parseJSON}/>)}</div>diff --git a/packages/cli/src/editor/components/RenderModal/RenderModalJSONPropsEditor.tsx b/packages/cli/src/editor/components/RenderModal/RenderModalJSONPropsEditor.tsxindex 0922edc39f..f7d643550d 100644--- a/packages/cli/src/editor/components/RenderModal/RenderModalJSONPropsEditor.tsx+++ b/packages/cli/src/editor/components/RenderModal/RenderModalJSONPropsEditor.tsx@@ -5,32 +5,7 @@ import {useKeybinding} from '../../helpers/use-keybinding';import {Row, Spacing} from '../layout';import {RemTextarea} from '../NewComposition/RemTextarea';import {ValidationMessage} from '../NewComposition/ValidationMessage';-import type {SerializedJSONWithDate} from './SchemaEditor/date-serialization';-import {- deserializeJSONWithDate,- serializeJSONWithDate,-} from './SchemaEditor/date-serialization';--type State =- | {- str: string;- value: unknown;- validJSON: true;- }- | {- str: string;- validJSON: false;- error: string;- };--const parseJSON = (str: string): State => {- try {- const value = deserializeJSONWithDate(str);- return {str, value, validJSON: true};- } catch (e) {- return {str, validJSON: false, error: (e as Error).message};- }-};+import type {State} from './RenderModalData';const style: React.CSSProperties = {fontFamily: 'monospace',@@ -63,9 +38,9 @@ export const RenderModalJSONPropsEditor: React.FC<{onSave: () => void;valBeforeSafe: unknown;showSaveButton: boolean;- setIsCustomDateUsed: React.Dispatch<- React.SetStateAction<boolean | undefined>- >;+ localValue: State;+ setLocalValue: React.Dispatch<React.SetStateAction<State>>;+ parseJSON: (str: string) => State;}> = ({setValue,value,@@ -74,19 +49,12 @@ export const RenderModalJSONPropsEditor: React.FC<{onSave,valBeforeSafe,showSaveButton,- setIsCustomDateUsed,+ localValue,+ setLocalValue,+ parseJSON,}) => {const keybindings = useKeybinding();- const [localValue, setLocalValue] = React.useState<State>(() => {- const serializedJSON: SerializedJSONWithDate = serializeJSONWithDate(- value,- 2- );- setIsCustomDateUsed(serializedJSON.customDateUsed);- return parseJSON(serializedJSON.serializedString);- });-const onPretty = useCallback(() => {if (!localValue.validJSON) {return;@@ -94,7 +62,7 @@ export const RenderModalJSONPropsEditor: React.FC<{const parsed = JSON.parse(localValue.str);setLocalValue({...localValue, str: JSON.stringify(parsed, null, 2)});- }, [localValue]);+ }, [localValue, setLocalValue]);const onChange: React.ChangeEventHandler<HTMLTextAreaElement> = useCallback((e) => {@@ -107,6 +75,7 @@ export const RenderModalJSONPropsEditor: React.FC<{validJSON: parsed.validJSON,});} else {+ console.log(parsed.error);setLocalValue({str: e.target.value,validJSON: parsed.validJSON,@@ -118,7 +87,7 @@ export const RenderModalJSONPropsEditor: React.FC<{setValue(parsed.value);}},- [setValue]+ [parseJSON, setLocalValue, setValue]);const hasChanged = useMemo(() => {