2023-01-03 14:41:34 +01:00
|
|
|
import { useGlobalLocalStorage } from './useGlobalLocalStorage';
|
|
|
|
import { useState } from 'react';
|
2023-01-09 14:36:10 +01:00
|
|
|
import { usePlausibleTracker } from 'hooks/usePlausibleTracker';
|
2023-01-03 14:41:34 +01:00
|
|
|
|
|
|
|
export const useHiddenEnvironments = () => {
|
2023-01-09 14:36:10 +01:00
|
|
|
const { trackEvent } = usePlausibleTracker();
|
2023-01-03 14:41:34 +01:00
|
|
|
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);
|
2023-01-09 14:36:10 +01:00
|
|
|
trackEvent('hidden_environment', {
|
|
|
|
props: {
|
|
|
|
eventType: `environment unhidden`,
|
|
|
|
},
|
|
|
|
});
|
2023-01-03 14:41:34 +01:00
|
|
|
} else {
|
|
|
|
hiddenEnvironments.add(environment);
|
2023-01-09 14:36:10 +01:00
|
|
|
trackEvent('hidden_environment', {
|
|
|
|
props: {
|
|
|
|
eventType: `environment hidden`,
|
|
|
|
},
|
|
|
|
});
|
2023-01-03 14:41:34 +01:00
|
|
|
}
|
|
|
|
setStoredHiddenEnvironments(hiddenEnvironments);
|
|
|
|
return {
|
|
|
|
...globalStore,
|
|
|
|
hiddenEnvironments: hiddenEnvironments,
|
|
|
|
};
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
return {
|
|
|
|
hiddenEnvironments,
|
|
|
|
setHiddenEnvironments,
|
|
|
|
};
|
|
|
|
};
|