mirror of
https://github.com/datahub-project/datahub.git
synced 2025-10-14 02:16:13 +00:00
19 lines
858 B
TypeScript
19 lines
858 B
TypeScript
import { useContext, useEffect } from 'react';
|
|
import { EducationStepsContext } from '../../providers/EducationStepsContext';
|
|
import { useUpdateEducationStepsAllowList } from './useUpdateEducationStepsAllowList';
|
|
|
|
export function useToggleEducationStepIdsAllowList(condition: boolean, id: string) {
|
|
const { educationStepIdsAllowlist } = useContext(EducationStepsContext);
|
|
const { addIdToAllowList, removeIdFromAllowList } = useUpdateEducationStepsAllowList();
|
|
|
|
useEffect(() => {
|
|
const allowlistIncludesStepId = educationStepIdsAllowlist.has(id);
|
|
|
|
if (condition && !allowlistIncludesStepId) {
|
|
addIdToAllowList(id);
|
|
} else if (!condition && allowlistIncludesStepId) {
|
|
removeIdFromAllowList(id);
|
|
}
|
|
}, [condition, id, addIdToAllowList, removeIdFromAllowList, educationStepIdsAllowlist]);
|
|
}
|