diff --git a/app/react/Markdown/components/MarkdownMedia.tsx b/app/react/Markdown/components/MarkdownMedia.tsx index 8895eb848a..a65afb7183 100644 --- a/app/react/Markdown/components/MarkdownMedia.tsx +++ b/app/react/Markdown/components/MarkdownMedia.tsx @@ -134,28 +134,17 @@ const MarkdownMedia = (props: MarkdownMediaProps) => { }); }; - const updateTimelinks = ( - payload: { action: 'append' | 'remove'; index?: number; timelink?: TimeLink }, - url: string - ) => { - switch (payload.action) { - case 'append': - if (payload.timelink) { - append(payload.timelink); - } else { - append(newTimeline); - } - setNewTimeline({ timeHours: '00', timeMinutes: '00', timeSeconds: '00', label: '' }); - break; - case 'remove': - remove(payload.index); - break; - default: - } + const updateParentForm = (url: string) => { const fullTimelinksString = constructTimelinksString(getValues().timelines, url); if (props.onTimeLinkAdded) props.onTimeLinkAdded(fullTimelinksString); }; + const appendTimelinkAndUpdateParent = (url: string, timelink?: TimeLink) => { + const currentTimelink = timelink || newTimeline; + append(currentTimelink); + updateParentForm(url); + }; + const renderNewTimeLinkForm = (url: string) => (
@@ -205,7 +194,7 @@ const MarkdownMedia = (props: MarkdownMediaProps) => { type="button" className="new-timestamp-btn" onClick={() => { - updateTimelinks({ action: 'append' }, url); + appendTimelinkAndUpdateParent(url); }} > @@ -225,7 +214,9 @@ const MarkdownMedia = (props: MarkdownMediaProps) => { className="timestamp-hours" placeholder="00" key={field.id} - {...register(`timelines.${index}.timeHours`)} + {...register(`timelines.${index}.timeHours`, { + onChange: _ => updateParentForm(url), + })} /> : { className="timestamp-minutes" placeholder="00" key={field.id} - {...register(`timelines.${index}.timeMinutes`)} + {...register(`timelines.${index}.timeMinutes`, { + onChange: _ => updateParentForm(url), + })} /> : { className="timestamp-seconds" placeholder="00" key={field.id} - {...register(`timelines.${index}.timeSeconds`)} + {...register(`timelines.${index}.timeSeconds`, { + onChange: _ => updateParentForm(url), + })} />
{ className="timestamp-label" placeholder="Enter title" key={field.id} - {...register(`timelines.${index}.label`)} + {...register(`timelines.${index}.label`, { + onChange: _ => updateParentForm(url), + })} />