Skip to content

Commit da68e91

Browse files
committed
6871: Fixed issues with screen manager
1 parent 3e035da commit da68e91

1 file changed

Lines changed: 33 additions & 35 deletions

File tree

assets/admin/components/screen/screen-manager.jsx

Lines changed: 33 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,15 @@ import {
1313
import idFromUrl from "../util/helpers/id-from-url";
1414
import { set } from "lodash/object";
1515

16+
const orientationOptions = [
17+
{ title: "Vertikal", "@id": "vertical" },
18+
{ title: "Horisontal", "@id": "horizontal" },
19+
];
20+
const resolutionOptions = [
21+
{ title: "4K", "@id": "4K" },
22+
{ title: "HD", "@id": "HD" },
23+
];
24+
1625
/**
1726
* The screen manager component.
1827
*
@@ -36,14 +45,6 @@ function ScreenManager({
3645
const { t } = useTranslation("common", { keyPrefix: "screen-manager" });
3746
const saveWithoutCloseRef = useRef(false);
3847
const navigate = useNavigate();
39-
const orientationOptions = [
40-
{ title: "Vertikal", "@id": "vertical" },
41-
{ title: "Horisontal", "@id": "horizontal" },
42-
];
43-
const resolutionOptions = [
44-
{ title: "4K", "@id": "4K" },
45-
{ title: "HD", "@id": "HD" },
46-
];
4748
const headerText =
4849
saveMethod === "PUT" ? t("edit-screen-header") : t("create-screen-header");
4950
const [loadingMessage, setLoadingMessage] = useState("");
@@ -86,8 +87,7 @@ function ScreenManager({
8687
* @param {object} props.target - Event target.
8788
*/
8889
const handleInput = ({ target }) => {
89-
let localFormStateObject = { ...formStateObject };
90-
localFormStateObject = JSON.parse(JSON.stringify(localFormStateObject));
90+
const localFormStateObject = JSON.parse(JSON.stringify(formStateObject));
9191
set(localFormStateObject, target.id, target.value);
9292
setFormStateObject(localFormStateObject);
9393
};
@@ -118,9 +118,9 @@ function ScreenManager({
118118
*
119119
* @returns {Array | null} A mapped array with group ids or null
120120
*/
121-
function mapGroups() {
122-
if (formStateObject?.inScreenGroups instanceof Array) {
123-
return formStateObject.inScreenGroups.map((group) => {
121+
function mapGroups(screenState) {
122+
if (screenState?.inScreenGroups instanceof Array) {
123+
return screenState.inScreenGroups.map((group) => {
124124
return idFromUrl(group);
125125
});
126126
}
@@ -136,7 +136,7 @@ function ScreenManager({
136136
*/
137137
function getPlaylistsByRegionId(playlists, regionId) {
138138
return playlists
139-
.filter(({ region }) => idFromUrl(region) === idFromUrl(regionId))
139+
.filter(({ region }) => idFromUrl(region) === regionId)
140140
.map((playlist, index) => {
141141
return { id: idFromUrl(playlist["@id"]), weight: index };
142142
});
@@ -147,8 +147,9 @@ function ScreenManager({
147147
* @param {Array} array The array to remove from.
148148
*/
149149
function removeFromArray(itemId, array) {
150-
if (array.indexOf(itemId) >= 0) {
151-
array.splice(array.indexOf(itemId), 1);
150+
const index = array.indexOf(itemId);
151+
if (index >= 0) {
152+
array.splice(index, 1);
152153
}
153154
}
154155

@@ -179,19 +180,17 @@ function ScreenManager({
179180
// Add regionsId and connected playlists to the returnarray
180181
returnArray.push({
181182
playlists: getPlaylistsByRegionId(playlists, regionId),
182-
regionId: idFromUrl(regionId),
183+
regionId,
183184
});
184185
});
185186

186187
// The remaining regions are added with empty playlist arrays.
187-
if (regionIds.length > 0) {
188-
regionIds.forEach((regionId) =>
189-
returnArray.push({
190-
playlists: [],
191-
regionId: idFromUrl(regionId),
192-
}),
193-
);
194-
}
188+
regionIds.forEach((regionId) =>
189+
returnArray.push({
190+
playlists: [],
191+
regionId,
192+
}),
193+
);
195194
return returnArray;
196195
}
197196

@@ -200,8 +199,8 @@ function ScreenManager({
200199
*
201200
* @returns {string} Orientation or empty string
202201
*/
203-
function getOrientation() {
204-
const { orientation } = formStateObject;
202+
function getOrientation(screenState) {
203+
const { orientation } = screenState;
205204
return orientation ? orientation[0]["@id"] : "";
206205
}
207206

@@ -210,15 +209,16 @@ function ScreenManager({
210209
*
211210
* @returns {string} Resolution or empty string
212211
*/
213-
function getResolution() {
214-
const { resolution } = formStateObject;
212+
function getResolution(screenState) {
213+
const { resolution } = screenState;
215214
return resolution && resolution.length > 0 ? resolution[0]["@id"] : "";
216215
}
217216

218217
/** Handles submit. */
219218
const handleSubmit = () => {
220219
setSavingScreen(true);
221220
setLoadingMessage(t("loading-messages.saving-screen"));
221+
222222
const localFormStateObject = JSON.parse(JSON.stringify(formStateObject));
223223
const {
224224
title,
@@ -241,15 +241,13 @@ function ScreenManager({
241241
layout,
242242
location,
243243
enableColorSchemeChange,
244-
resolution: getResolution(),
245-
groups: mapGroups(),
246-
orientation: getOrientation(),
244+
resolution: getResolution(localFormStateObject),
245+
groups: mapGroups(localFormStateObject),
246+
orientation: getOrientation(localFormStateObject),
247247
regions: mapPlaylistsWithRegion(localFormStateObject.playlists, localFormStateObject.regions),
248248
}),
249249
};
250250

251-
setLoadingMessage(t("loading-messages.saving-screen"));
252-
253251
if (saveMethod === "POST") {
254252
PostV2Screens(saveData);
255253
} else if (saveMethod === "PUT") {
@@ -278,7 +276,7 @@ function ScreenManager({
278276
navigate("/screen/list");
279277
}
280278
}
281-
}, [isSaveSuccessPut, isSaveSuccessPost]);
279+
}, [isSaveSuccessPut, isSaveSuccessPost, postData]);
282280

283281
return (
284282
<>

0 commit comments

Comments
 (0)