add optional config for settings modal

This commit is contained in:
Mary Hipp 2023-06-01 10:14:39 -04:00 committed by psychedelicious
parent c9e621093e
commit d66979073b

View File

@ -35,7 +35,13 @@ import {
} from 'features/ui/store/uiSlice'; } from 'features/ui/store/uiSlice';
import { UIState } from 'features/ui/store/uiTypes'; import { UIState } from 'features/ui/store/uiTypes';
import { isEqual } from 'lodash-es'; import { isEqual } from 'lodash-es';
import { ChangeEvent, cloneElement, ReactElement, useCallback } from 'react'; import {
ChangeEvent,
cloneElement,
ReactElement,
useCallback,
useEffect,
} from 'react';
import { useTranslation } from 'react-i18next'; import { useTranslation } from 'react-i18next';
import { VALID_LOG_LEVELS } from 'app/logging/useLogger'; import { VALID_LOG_LEVELS } from 'app/logging/useLogger';
import { LogLevelName } from 'roarr'; import { LogLevelName } from 'roarr';
@ -85,15 +91,33 @@ const modalSectionStyles: ChakraProps['sx'] = {
borderRadius: 'base', borderRadius: 'base',
}; };
type ConfigOptions = {
shouldShowDeveloperSettings: boolean;
shouldShowResetWebUiText: boolean;
shouldShowBetaLayout: boolean;
};
type SettingsModalProps = { type SettingsModalProps = {
/* The button to open the Settings Modal */ /* The button to open the Settings Modal */
children: ReactElement; children: ReactElement;
config?: ConfigOptions;
}; };
const SettingsModal = ({ children }: SettingsModalProps) => { const SettingsModal = ({ children, config }: SettingsModalProps) => {
const dispatch = useAppDispatch(); const dispatch = useAppDispatch();
const { t } = useTranslation(); const { t } = useTranslation();
const shouldShowBetaLayout = config?.shouldShowBetaLayout ?? true;
const shouldShowDeveloperSettings =
config?.shouldShowDeveloperSettings ?? true;
const shouldShowResetWebUiText = config?.shouldShowResetWebUiText ?? true;
useEffect(() => {
if (!shouldShowDeveloperSettings) {
dispatch(shouldLogToConsoleChanged(false));
}
}, [shouldShowDeveloperSettings, dispatch]);
const { const {
isOpen: isSettingsModalOpen, isOpen: isSettingsModalOpen,
onOpen: onSettingsModalOpen, onOpen: onSettingsModalOpen,
@ -189,6 +213,7 @@ const SettingsModal = ({ children }: SettingsModalProps) => {
dispatch(setShouldDisplayGuides(e.target.checked)) dispatch(setShouldDisplayGuides(e.target.checked))
} }
/> />
{shouldShowBetaLayout && (
<IAISwitch <IAISwitch
label={t('settings.useCanvasBeta')} label={t('settings.useCanvasBeta')}
isChecked={shouldUseCanvasBetaLayout} isChecked={shouldUseCanvasBetaLayout}
@ -196,6 +221,7 @@ const SettingsModal = ({ children }: SettingsModalProps) => {
dispatch(setShouldUseCanvasBetaLayout(e.target.checked)) dispatch(setShouldUseCanvasBetaLayout(e.target.checked))
} }
/> />
)}
<IAISwitch <IAISwitch
label={t('settings.useSlidersForAll')} label={t('settings.useSlidersForAll')}
isChecked={shouldUseSliders} isChecked={shouldUseSliders}
@ -221,6 +247,7 @@ const SettingsModal = ({ children }: SettingsModalProps) => {
/> />
</Flex> </Flex>
{shouldShowDeveloperSettings && (
<Flex sx={modalSectionStyles}> <Flex sx={modalSectionStyles}>
<Heading size="sm">{t('settings.developer')}</Heading> <Heading size="sm">{t('settings.developer')}</Heading>
<IAISwitch <IAISwitch
@ -245,14 +272,19 @@ const SettingsModal = ({ children }: SettingsModalProps) => {
} }
/> />
</Flex> </Flex>
)}
<Flex sx={modalSectionStyles}> <Flex sx={modalSectionStyles}>
<Heading size="sm">{t('settings.resetWebUI')}</Heading> <Heading size="sm">{t('settings.resetWebUI')}</Heading>
<IAIButton colorScheme="error" onClick={handleClickResetWebUI}> <IAIButton colorScheme="error" onClick={handleClickResetWebUI}>
{t('settings.resetWebUI')} {t('settings.resetWebUI')}
</IAIButton> </IAIButton>
{shouldShowResetWebUiText && (
<>
<Text>{t('settings.resetWebUIDesc1')}</Text> <Text>{t('settings.resetWebUIDesc1')}</Text>
<Text>{t('settings.resetWebUIDesc2')}</Text> <Text>{t('settings.resetWebUIDesc2')}</Text>
</>
)}
</Flex> </Flex>
</Flex> </Flex>
</ModalBody> </ModalBody>