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();
|
2024-01-26 17:03:10 +01:00
|
|
|
|
2023-01-03 14:41:34 +01:00
|
|
|
const { value: globalStore, setValue: setGlobalStore } =
|
|
|
|
useGlobalLocalStorage();
|
|
|
|
const [hiddenEnvironments, setStoredHiddenEnvironments] = useState<
|
|
|
|
Set<string>
|
2024-01-29 12:33:01 +01:00
|
|
|
>(new Set(globalStore.hiddenEnvironments));
|
2023-01-03 14:41:34 +01:00
|
|
|
|
|
|
|
const setHiddenEnvironments = (environment: string) => {
|
2023-10-02 14:25:46 +02:00
|
|
|
setGlobalStore((params) => {
|
2024-01-26 17:03:10 +01:00
|
|
|
const hiddenEnvironments = new Set(
|
2024-01-29 12:33:01 +01:00
|
|
|
Array.from(params.hiddenEnvironments || []),
|
2024-01-26 17:03:10 +01:00
|
|
|
);
|
2023-01-03 14:41:34 +01:00
|
|
|
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);
|
2024-01-26 17:03:10 +01:00
|
|
|
|
2023-01-03 14:41:34 +01:00
|
|
|
return {
|
|
|
|
...globalStore,
|
2024-01-26 17:03:10 +01:00
|
|
|
hiddenEnvironments: [...hiddenEnvironments],
|
2023-01-03 14:41:34 +01:00
|
|
|
};
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
return {
|
|
|
|
hiddenEnvironments,
|
|
|
|
setHiddenEnvironments,
|
|
|
|
};
|
|
|
|
};
|