@@ -19,6 +19,7 @@ import {
1919} from "../util/list/toast-component/display-toast" ;
2020import idFromUrl from "../util/helpers/id-from-url" ;
2121import localStorageKeys from "../util/local-storage-keys" ;
22+ import { get , set } from "lodash/object" ;
2223
2324/**
2425 * The slide manager component.
@@ -153,7 +154,7 @@ function SlideManager({
153154 */
154155 const handleInput = ( { target } ) => {
155156 const localFormStateObject = { ...formStateObject } ;
156- localFormStateObject [ target . id ] = target . value ;
157+ set ( localFormStateObject , target . id , target . value ) ;
157158 setFormStateObject ( localFormStateObject ) ;
158159 } ;
159160
@@ -206,7 +207,7 @@ function SlideManager({
206207 const value =
207208 target . type === "number" ? target . valueAsNumber : target . value ;
208209 const localFormStateObject = { ...formStateObject } ;
209- localFormStateObject . content [ target . id ] = value ;
210+ set ( localFormStateObject . content , target . id , value ) ;
210211 setFormStateObject ( localFormStateObject ) ;
211212 } ;
212213
@@ -351,12 +352,12 @@ function SlideManager({
351352 // It is an already added temp file.
352353 if ( entry . tempId ) {
353354 newField . push ( entry . tempId ) ;
354- localMediaData [ entry . tempId ] = entry ;
355+ set ( localMediaData , entry . tempId , entry ) ;
355356 }
356357 // It is a new temp file.
357358 else {
358359 if ( ! Array . isArray ( localFormStateObject . content [ fieldId ] ) ) {
359- localFormStateObject . content [ fieldId ] = [ ] ;
360+ set ( localFormStateObject . content , fieldId , [ ] ) ;
360361 }
361362
362363 // Create a tempId for the media.
@@ -367,7 +368,7 @@ function SlideManager({
367368
368369 const newEntry = { ...entry } ;
369370 newEntry . tempId = tempId ;
370- localMediaData [ tempId ] = newEntry ;
371+ set ( localMediaData , tempId , newEntry ) ;
371372 }
372373 }
373374 // Previously selected file.
@@ -381,16 +382,18 @@ function SlideManager({
381382 if (
382383 ! Object . prototype . hasOwnProperty . call ( localMediaData , entry [ "@id" ] )
383384 ) {
384- localMediaData [ entry [ "@id" ] ] = entry ;
385+ set ( localMediaData , entry [ "@id" ] , entry ) ;
385386
386387 localFormStateObject . media . push ( entry [ "@id" ] ) ;
387388 }
388389 }
389390 } ) ;
390391 }
391392
392- localFormStateObject . content [ fieldId ] = newField ;
393- localFormStateObject . media = [ ...new Set ( [ ...localFormStateObject . media ] ) ] ;
393+ set ( localFormStateObject . content , fieldId , newField ) ;
394+ set ( localFormStateObject , "media" , [
395+ ...new Set ( [ ...localFormStateObject . media ] ) ,
396+ ] ) ;
394397
395398 setFormStateObject ( localFormStateObject ) ;
396399 setMediaData ( localMediaData ) ;
@@ -402,7 +405,7 @@ function SlideManager({
402405
403406 // Setup submittingMedia list.
404407 mediaFields . forEach ( ( fieldName ) => {
405- const fieldData = formStateObject . content [ fieldName ] ;
408+ const fieldData = get ( formStateObject . content , fieldName ) ;
406409
407410 if ( fieldData ) {
408411 if ( Array . isArray ( fieldData ) ) {
@@ -552,10 +555,14 @@ function SlideManager({
552555 newFormStateObject . media . push ( savedMediaData [ "@id" ] ) ;
553556
554557 // Replace TEMP-- id with real id.
555- newFormStateObject . content [ submittedMedia . fieldName ] =
556- newFormStateObject . content [ submittedMedia . fieldName ] . map ( ( mediaId ) =>
557- mediaId === submittedMedia . tempId ? savedMediaData [ "@id" ] : mediaId ,
558- ) ;
558+ set (
559+ newFormStateObject . content ,
560+ submittedMedia . fieldName ,
561+ get ( newFormStateObject . content , submittedMedia . fieldName ) . map (
562+ ( mediaId ) =>
563+ mediaId === submittedMedia . tempId ? savedMediaData [ "@id" ] : mediaId ,
564+ ) ,
565+ ) ;
559566
560567 const newMediaData = { ...mediaData } ;
561568 newMediaData [ savedMediaData [ "@id" ] ] = savedMediaData ;
0 commit comments