@@ -127,7 +127,7 @@ function ScreenManager({
127127 * @returns {Array | null } A mapped array with group ids or null
128128 */
129129 function mapGroups ( ) {
130- if ( formStateObject . inScreenGroups ) {
130+ if ( formStateObject ? .inScreenGroups instanceof Array ) {
131131 return formStateObject . inScreenGroups . map ( ( group ) => {
132132 return idFromUrl ( group ) ;
133133 } ) ;
@@ -167,16 +167,17 @@ function ScreenManager({
167167 *
168168 * @returns {Array | null } A mapped array with playlist, regions and weight or null
169169 */
170- function mapPlaylistsWithRegion ( ) {
170+ function mapPlaylistsWithRegion ( playlists , regions ) {
171171 const returnArray = [ ] ;
172- const { playlists, regions } = formStateObject ;
173- const regionIds = regions . map ( ( r ) => idFromUrl ( r [ "@id" ] ) ) ;
172+ const regionIds = regions . map ( ( r ) =>
173+ typeof r === "string" ? idFromUrl ( r , 1 ) : idFromUrl ( r [ "@id" ] )
174+ ) ;
174175
175176 // The playlists all have a regionId, the following creates a unique list of relevant regions If there are not
176177 // playlists, then an empty playlist is to be saved per region
177178 let playlistRegions = [ ] ;
178179 if ( playlists ?. length > 0 ) {
179- playlistRegions = [ ...new Set ( playlists . map ( ( { region } ) => region ) ) ] ;
180+ playlistRegions = [ ...new Set ( playlists . map ( ( { region } ) => idFromUrl ( region ) ) ) ] ;
180181 }
181182
182183 // Then the playlists are mapped by region Looping through the regions that have a playlist connected...
@@ -191,6 +192,7 @@ function ScreenManager({
191192 regionId : idFromUrl ( regionId ) ,
192193 } ) ;
193194 } ) ;
195+
194196 // The remaining regions are added with empty playlist arrays.
195197 if ( regionIds . length > 0 ) {
196198 regionIds . forEach ( ( regionId ) =>
@@ -252,7 +254,7 @@ function ScreenManager({
252254 resolution : getResolution ( ) ,
253255 groups : mapGroups ( ) ,
254256 orientation : getOrientation ( ) ,
255- regions : mapPlaylistsWithRegion ( ) ,
257+ regions : mapPlaylistsWithRegion ( localFormStateObject . playlists , localFormStateObject . regions ) ,
256258 } ) ,
257259 } ;
258260
0 commit comments