diff --git a/assets/admin/components/screen/util/grid-generation-and-select.jsx b/assets/admin/components/screen/util/grid-generation-and-select.jsx index 4c5e2aeaf..eb59c46d2 100644 --- a/assets/admin/components/screen/util/grid-generation-and-select.jsx +++ b/assets/admin/components/screen/util/grid-generation-and-select.jsx @@ -1,9 +1,6 @@ import { useState, useEffect } from "react"; import { Tabs, Tab, Alert } from "react-bootstrap"; -import { - createGridArea, - createGrid, -} from "../../../../shared/grid-generator/grid-generator"; +import Grid from "./grid"; import { useTranslation } from "react-i18next"; import { useDispatch } from "react-redux"; import idFromUrl from "../../util/helpers/id-from-url"; @@ -31,15 +28,10 @@ function GridGenerationAndSelect({ }) { const { t } = useTranslation("common"); const dispatch = useDispatch(); - const [key, setKey] = useState(regions.length > 0 ? regions[0]["@id"] : ""); + const [selectedRegion, setSelectedRegion] = useState( + regions.length > 0 ? regions[0]["@id"] : "", + ); const [selectedPlaylists, setSelectedPlaylists] = useState([]); - const gridClasses = `grid ${vertical ? "vertical" : "horizontal"}`; - // Rows and columns in grid defaults to 1. - const configColumns = grid?.columns || 1; - const configRows = grid?.rows || 1; - const gridTemplateAreas = { - gridTemplateAreas: createGrid(configColumns, configRows), - }; /** * @param {object} props The props @@ -149,87 +141,67 @@ function GridGenerationAndSelect({ setSelectedPlaylists(playlists); }; - /** @param {string} id - The id of the selected tab */ - const handleSelect = (id) => { - setKey(id); - }; - /** - * Removes playlist from list of playlists, and closes modal. + * Removes playlist from list of playlists. * - * @param {object} inputPlaylist - InputPlaylist to remove - * @param {object} inputRegion - InputRegion to remove from + * @param {object} inputPlaylistId - InputPlaylistId to remove + * @param {object} inputRegionId - InputRegionId to remove from */ - const removeFromList = (inputPlaylist, inputRegion) => { - const indexOfItemToRemove = selectedPlaylists.findIndex( - ({ "@id": id, region }) => { - return region === inputRegion && id === inputPlaylist; - }, + const removeFromList = (inputPlaylistId, inputRegionId) => { + setSelectedPlaylists((prev) => + prev.filter( + ({ "@id": id, region: regionId }) => + !(regionId === inputRegionId && id === inputPlaylistId), + ), ); - const selectedPlaylistsCopy = [...selectedPlaylists]; - selectedPlaylistsCopy.splice(indexOfItemToRemove, 1); - setSelectedPlaylists(selectedPlaylistsCopy); }; + if (regions?.length === 0) return null; + return ( <>