mirror of
https://github.com/Unleash/unleash.git
synced 2024-11-01 19:07:38 +01:00
38 lines
1.2 KiB
TypeScript
38 lines
1.2 KiB
TypeScript
import { createLocalStorage } from 'utils/createLocalStorage';
|
|
import { useGlobalLocalStorage } from './useGlobalLocalStorage';
|
|
import { useState } from 'react';
|
|
|
|
interface IGlobalStore {
|
|
favorites?: boolean;
|
|
hiddenEnvironments?: Set<string>;
|
|
}
|
|
|
|
export const useHiddenEnvironments = () => {
|
|
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);
|
|
} else {
|
|
hiddenEnvironments.add(environment);
|
|
}
|
|
setStoredHiddenEnvironments(hiddenEnvironments);
|
|
return {
|
|
...globalStore,
|
|
hiddenEnvironments: hiddenEnvironments,
|
|
};
|
|
});
|
|
};
|
|
|
|
return {
|
|
hiddenEnvironments,
|
|
setHiddenEnvironments,
|
|
};
|
|
};
|