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 AllowedMutations = () => { const dispatch = useDispatch(); const allowedMutationsSettings = useSelector((state: RootState) => state.settings.allowedMutations); let allowedCount = 0; let totalMutations = 0; const AllowedMutationsCollection = Object.keys(allowedMutationsSettings) .map((mutation) => { const mutationValue = allowedMutationsSettings[mutation]; if (mutationValue) { allowedCount++; } totalMutations++; return ( dispatch( updateAllowedCollection({ collectionName: 'allowedMutations', collectionKey: mutation, collectionValue: !!(e.target.checked) }) )} className="toggle" /> ); }); const label = `Allowed Mutations: ${allowedCount} of ${totalMutations}`; return (
{label}
{AllowedMutationsCollection}
); } export default AllowedMutations;