From d1f488ea9a16134b6f3388b274e53f1b2fe7781d Mon Sep 17 00:00:00 2001 From: Csillag Kristof Date: Wed, 19 Oct 2022 23:20:16 +0200 Subject: [PATCH] Support opening the settings dialog directly from dangerous modal dialogs --- src/app/components/Modal/index.tsx | 60 ++++++++++++++++--- src/app/components/SettingsButton/index.tsx | 21 +++++-- .../components/SettingsDialog/slice/index.ts | 4 ++ .../SettingsDialog/slice/selectors.ts | 1 + .../components/SettingsDialog/slice/types.ts | 1 + 5 files changed, 72 insertions(+), 15 deletions(-) diff --git a/src/app/components/Modal/index.tsx b/src/app/components/Modal/index.tsx index fd1d313c75..e30ee22540 100644 --- a/src/app/components/Modal/index.tsx +++ b/src/app/components/Modal/index.tsx @@ -1,11 +1,12 @@ import { createContext, useCallback, useContext, useEffect, useState } from 'react' -import { Box, Button, Layer, Heading, Paragraph } from 'grommet' +import { Box, Button, Layer, Paragraph } from 'grommet' import { useTranslation } from 'react-i18next' -import { Alert, Checkmark, Close } from 'grommet-icons' +import { Alert, Checkmark, Close, Configure } from 'grommet-icons' import { ModalHeader } from 'app/components/Header' import { AlertBox } from '../AlertBox' import { selectAllowDangerousSetting } from '../SettingsDialog/slice/selectors' -import { useSelector } from 'react-redux' +import { useDispatch, useSelector } from 'react-redux' +import { settingsActions } from '../SettingsDialog/slice' interface Modal { title: string @@ -30,11 +31,29 @@ interface Modal { interface ModalContainerProps { modal: Modal closeModal: () => void + hideModal: () => void } interface ModalContextProps { + /** + * Show a new modal + */ launchModal: (modal: Modal) => void + + /** + * Close the current modal + */ closeModal: () => void + + /** + * Hide the current modal (with the intention of showing in again later) + */ + hideModal: () => void + + /** + * Show the previously hidden modal again + */ + showModal: () => void } interface ModalProviderProps { @@ -43,7 +62,8 @@ interface ModalProviderProps { const ModalContext = createContext({} as ModalContextProps) -const ModalContainer = ({ modal, closeModal }: ModalContainerProps) => { +const ModalContainer = ({ modal, closeModal, hideModal }: ModalContainerProps) => { + const dispatch = useDispatch() const { t } = useTranslation() const confirm = useCallback(() => { modal.handleConfirm() @@ -59,6 +79,10 @@ const ModalContainer = ({ modal, closeModal }: ModalContainerProps) => { : mustWaitSecs ?? 0 // For normal, non-dangerous operations, just use what was specified const [secsLeft, setSecsLeft] = useState(0) + const openSettings = () => { + hideModal() + setTimeout(() => dispatch(settingsActions.setOpen(true)), 100) + } useEffect(() => { if (waitingTime) { @@ -99,9 +123,6 @@ const ModalContainer = ({ modal, closeModal }: ModalContainerProps) => { )} - {/* This is a placeholder, so that if we have only one valid button, - the Cancel, it should be on the right side, not the left side.*/} - {!!forbidden && }