import {useDispatch, useSelector} from "react-redux"; import {AppDispatch, RootState} from "../store/store"; import {updateAllowedCollection} from "../store/settingsSlice"; import SettingField from "../components/SettingFile"; import React from "react"; const AllowedCrossovers = () => { const dispatch = useDispatch(); const allowedCrossoversSettings = useSelector((state: RootState) => state.settings.allowedCrossovers); let allowedCount = 0; let totalCrossovers = 0; const AllowedCrossoversCollection = Object.keys(allowedCrossoversSettings) .map((crossover) => { const mutationValue = allowedCrossoversSettings[crossover]; if (mutationValue) { allowedCount++; } totalCrossovers++; return ( dispatch( updateAllowedCollection({ collectionName: 'allowedCrossovers', collectionKey: crossover, collectionValue: !!(e.target.checked) }) )} className="toggle" /> ); }); const label = `Allowed Crossover: ${allowedCount} of ${totalCrossovers}`; return (
{label}
{AllowedCrossoversCollection}
); } export default AllowedCrossovers;