1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-11-01 19:07:38 +01:00
unleash.unleash/frontend/src/hooks/useHiddenEnvironments.ts
sjaanus d13401b6ed
Plausible for hidden environments (#2837)
Plausible for hidden environments
2023-01-09 15:36:10 +02:00

44 lines
1.5 KiB
TypeScript

import { useGlobalLocalStorage } from './useGlobalLocalStorage';
import { useState } from 'react';
import { usePlausibleTracker } from 'hooks/usePlausibleTracker';
export const useHiddenEnvironments = () => {
const { trackEvent } = usePlausibleTracker();
const { value: globalStore, setValue: setGlobalStore } =
useGlobalLocalStorage();
const [hiddenEnvironments, setStoredHiddenEnvironments] = useState<
Set<string>
>(new Set(globalStore.hiddenEnvironments));
const setHiddenEnvironments = (environment: string) => {
setGlobalStore(params => {
const hiddenEnvironments = new Set(params.hiddenEnvironments);
if (hiddenEnvironments.has(environment)) {
hiddenEnvironments.delete(environment);
trackEvent('hidden_environment', {
props: {
eventType: `environment unhidden`,
},
});
} else {
hiddenEnvironments.add(environment);
trackEvent('hidden_environment', {
props: {
eventType: `environment hidden`,
},
});
}
setStoredHiddenEnvironments(hiddenEnvironments);
return {
...globalStore,
hiddenEnvironments: hiddenEnvironments,
};
});
};
return {
hiddenEnvironments,
setHiddenEnvironments,
};
};