diff --git a/src/commands/StatusListener.ts b/src/commands/StatusListener.ts index c665eac6..6e21cf27 100644 --- a/src/commands/StatusListener.ts +++ b/src/commands/StatusListener.ts @@ -72,10 +72,10 @@ export class StatusListener { } } - const panel = PanelProvider.getInstance(); - if (panel && panel.visible) { - DataListener.pushMetadata(article?.data); - } + // const panel = PanelProvider.getInstance(); + // if (panel && panel.visible) { + // DataListener.pushMetadata(article?.data); + // } return; } catch (e) { diff --git a/src/panelWebView/components/Fields/TextField.tsx b/src/panelWebView/components/Fields/TextField.tsx index f69400d5..6080a730 100644 --- a/src/panelWebView/components/Fields/TextField.tsx +++ b/src/panelWebView/components/Fields/TextField.tsx @@ -127,10 +127,10 @@ export const TextField: React.FunctionComponent = ({ }, [value]); useEffect(() => { - if (debouncedText !== undefined) { + if (debouncedText !== undefined && value !== debouncedText) { onChange(debouncedText || ''); } - }, [debouncedText]); + }, [debouncedText, value]); return (
diff --git a/src/panelWebView/components/Fields/WrapperField.tsx b/src/panelWebView/components/Fields/WrapperField.tsx index dcff0466..43d30226 100644 --- a/src/panelWebView/components/Fields/WrapperField.tsx +++ b/src/panelWebView/components/Fields/WrapperField.tsx @@ -96,6 +96,8 @@ export const WrapperField: React.FunctionComponent = ({ return parsedDate || (date as Date | null); }; + const onFieldChange = useCallback((value: any) => onSendUpdate(field.name, value, parentFields), [field.name, parentFields, onSendUpdate]); + useEffect(() => { let value: any = parent[field.name]; @@ -185,7 +187,7 @@ export const WrapperField: React.FunctionComponent = ({ value={fieldValue} required={!!field.required} format={field.dateFormat || settings?.date?.format} - onChange={(date) => onSendUpdate(field.name, date, parentFields)} + onChange={onFieldChange} /> ); @@ -198,7 +200,7 @@ export const WrapperField: React.FunctionComponent = ({ description={field.description} value={fieldValue} required={!!field.required} - onChanged={(checked) => onSendUpdate(field.name, checked, parentFields)} + onChanged={onFieldChange} /> ); @@ -220,7 +222,7 @@ export const WrapperField: React.FunctionComponent = ({ limit={limit} wysiwyg={field.wysiwyg} rows={3} - onChange={(value) => onSendUpdate(field.name, value, parentFields)} + onChange={onFieldChange} value={(fieldValue as string) || null} required={!!field.required} settings={settings} @@ -239,7 +241,7 @@ export const WrapperField: React.FunctionComponent = ({ label={field.title || field.name} description={field.description} options={field.numberOptions} - onChange={(value) => onSendUpdate(field.name, value, parentFields)} + onChange={onFieldChange} value={nrValue} required={!!field.required} /> @@ -258,7 +260,7 @@ export const WrapperField: React.FunctionComponent = ({ required={!!field.required} multiple={field.multiple} blockData={blockData} - onChange={(value) => onSendUpdate(field.name, value, parentFields)} + onChange={onFieldChange} /> ); @@ -276,7 +278,7 @@ export const WrapperField: React.FunctionComponent = ({ required={!!field.required} parents={parentFields} blockData={blockData} - onChange={(value) => onSendUpdate(field.name, value, parentFields)} + onChange={onFieldChange} /> ); @@ -292,7 +294,7 @@ export const WrapperField: React.FunctionComponent = ({ required={!!field.required} choices={choices} multiSelect={field.multiple} - onChange={(value) => onSendUpdate(field.name, value, parentFields)} + onChange={onFieldChange} /> ); @@ -383,7 +385,7 @@ export const WrapperField: React.FunctionComponent = ({ choices={draftField?.choices || []} value={draftValue as boolean | string | null | undefined} required={!!field.required} - onChanged={(value: boolean | string) => onSendUpdate(field.name, value, parentFields)} + onChanged={onFieldChange} /> ); @@ -431,7 +433,7 @@ export const WrapperField: React.FunctionComponent = ({ settings={settings} field={field} value={collectionData} - onSubmit={(value) => onSendUpdate(field.name, value, parentFields)} + onSubmit={onFieldChange} /> ); @@ -452,7 +454,7 @@ export const WrapperField: React.FunctionComponent = ({ filePath={metadata.filePath as string} parentBlock={parentBlock} required={!!field.required} - onSubmit={(value) => onSendUpdate(field.name, value, parentFields)} + onSubmit={onFieldChange} /> ); @@ -468,7 +470,7 @@ export const WrapperField: React.FunctionComponent = ({ selected={fieldValue as string} required={!!field.required} multiSelect={field.multiple} - onChange={(value) => onSendUpdate(field.name, value, parentFields)} + onChange={onFieldChange} /> ); @@ -480,7 +482,7 @@ export const WrapperField: React.FunctionComponent = ({ description={field.description} value={fieldValue} required={!!field.required} - onChange={(value) => onSendUpdate(field.name, value, parentFields)} + onChange={onFieldChange} /> ); @@ -495,7 +497,7 @@ export const WrapperField: React.FunctionComponent = ({ contentTypeName={field.contentTypeName} contentTypeValue={field.contentTypeValue} multiSelect={field.multiple} - onChange={(value) => onSendUpdate(field.name, value, parentFields)} + onChange={onFieldChange} /> ); @@ -509,7 +511,7 @@ export const WrapperField: React.FunctionComponent = ({ value={fieldValue} required={!!field.required} editable={field.editable} - onChange={(value) => onSendUpdate(field.name, value, parentFields)} + onChange={onFieldChange} /> ); @@ -523,7 +525,7 @@ export const WrapperField: React.FunctionComponent = ({ description={field.description} value={fieldValue} required={!!field.required} - onChange={(value: any) => onSendUpdate(field.name, value, parentFields)} + onChange={onFieldChange} fieldData={fieldData} /> ); } else { diff --git a/src/panelWebView/components/Metadata.tsx b/src/panelWebView/components/Metadata.tsx index e9d02276..0f029611 100644 --- a/src/panelWebView/components/Metadata.tsx +++ b/src/panelWebView/components/Metadata.tsx @@ -33,7 +33,7 @@ const Metadata: React.FunctionComponent = ({ }: React.PropsWithChildren) => { const contentType = useContentType(settings, metadata); - const sendUpdate = React.useCallback((field: string | undefined, value: any, parents: string[]) => { + const onSendUpdate = React.useCallback((field: string | undefined, value: any, parents: string[]) => { if (!field) { return; } @@ -46,10 +46,6 @@ const Metadata: React.FunctionComponent = ({ }); }, [metadata.filePath]); - if (!settings) { - return null; - } - const renderFields = ( ctFields: Field[], parent: IMetadata, @@ -58,18 +54,10 @@ const Metadata: React.FunctionComponent = ({ onFieldUpdate?: (field: string | undefined, value: any, parents: string[]) => void, parentBlock?: string | null ): (JSX.Element | null)[] | undefined => { - if (!ctFields) { + if (!ctFields || !settings) { return; } - const onSendUpdate = (field: string | undefined, value: any, parents: string[]) => { - if (onFieldUpdate) { - onFieldUpdate(field, value, parents); - } else { - sendUpdate(field, value, parents); - } - }; - return ctFields.map((field) => ( = ({ blockData={blockData} parentBlock={parentBlock} focusElm={focusElm} - onSendUpdate={onSendUpdate} + onSendUpdate={onFieldUpdate || onSendUpdate} unsetFocus={unsetFocus} renderFields={renderFields} /> )); }; + const allFields = React.useMemo(() => renderFields(contentType?.fields || [], metadata), [contentType?.fields, JSON.stringify(metadata)]); + + if (!settings) { + return null; + } + return ( - + - {renderFields(contentType?.fields || [], metadata)} + {allFields} ); };