From dd951bd4fc2bca48f44d9b4e6ef1faf764d815ee Mon Sep 17 00:00:00 2001 From: David Lechner Date: Sat, 30 Jan 2021 11:54:43 -0600 Subject: [PATCH] make about dialog open/close local --- src/about/AboutDialog.tsx | 27 +++++++-------------------- src/app/actions.ts | 24 +----------------------- src/app/reducers.test.ts | 14 -------------- src/app/reducers.ts | 12 ------------ src/settings/SettingsDrawer.tsx | 24 ++++++++++++------------ 5 files changed, 20 insertions(+), 81 deletions(-) diff --git a/src/about/AboutDialog.tsx b/src/about/AboutDialog.tsx index 2a3070df..8eab2970 100644 --- a/src/about/AboutDialog.tsx +++ b/src/about/AboutDialog.tsx @@ -7,7 +7,6 @@ import { AnchorButton, Button, Classes, Dialog } from '@blueprintjs/core'; import { WithI18nProps, withI18n } from '@shopify/react-i18n'; import React from 'react'; import { connect } from 'react-redux'; -import { closeAboutDialog } from '../app/actions'; import { appName, legoDisclaimer, @@ -15,7 +14,6 @@ import { pybricksWebsiteUrl, } from '../app/constants'; import LicenseDialog from '../licenses/LicenseDialog'; -import { RootState } from '../reducers'; import ExternalLinkIcon from '../utils/ExternalLinkIcon'; import { AboutStringId } from './i18n'; import en from './i18n.en.json'; @@ -24,11 +22,9 @@ import './about.scss'; const version = process.env.REACT_APP_VERSION; -type StateProps = { showAboutDialog: boolean }; +type OwnProps = { isOpen: boolean; onClose: () => void }; -type DispatchProps = { onClose: () => void }; - -type AboutDialogProps = StateProps & DispatchProps & WithI18nProps; +type AboutDialogProps = OwnProps & WithI18nProps; class AboutDialog extends React.Component { public state = { @@ -36,11 +32,11 @@ class AboutDialog extends React.Component { }; render(): JSX.Element { - const { i18n, showAboutDialog, onClose } = this.props; + const { isOpen, onClose, i18n } = this.props; return ( onClose()} >
@@ -77,15 +73,6 @@ class AboutDialog extends React.Component { } } -const mapStateToProps = (state: RootState): StateProps => ({ - showAboutDialog: state.app.showAboutDialog, -}); - -const mapDispatchToProps: DispatchProps = { - onClose: closeAboutDialog, -}; - -export default connect( - mapStateToProps, - mapDispatchToProps, -)(withI18n({ id: 'about', fallback: en, translations: { en } })(AboutDialog)); +export default connect()( + withI18n({ id: 'about', fallback: en, translations: { en } })(AboutDialog), +); diff --git a/src/app/actions.ts b/src/app/actions.ts index 7ef88ee9..578a6c13 100644 --- a/src/app/actions.ts +++ b/src/app/actions.ts @@ -28,10 +28,6 @@ export enum AppActionType { OpenSettings = 'app.action.openSettings', /** Close settings dialog. */ CloseSettings = 'app.action.closeSettings', - /** Open about dialog. */ - OpenAboutDialog = 'app.action.openAboutDialog', - /** Close about dialog. */ - CloseAboutDialog = 'app.action.closeAboutDialog', } /** Action that requests the app to reload. */ @@ -128,22 +124,6 @@ export function closeSettings(): AppCloseSettingsAction { return { type: AppActionType.CloseSettings }; } -/** Action to open the about dialog. */ -export type AppOpenAboutDialogAction = Action; - -/** Creates an action to open the about dialog. */ -export function openAboutDialog(): AppOpenAboutDialogAction { - return { type: AppActionType.OpenAboutDialog }; -} - -/** Action to close the about dialog. */ -export type AppCloseAboutDialogAction = Action; - -/** Creates an action to close the about dialog. */ -export function closeAboutDialog(): AppCloseAboutDialogAction { - return { type: AppActionType.CloseAboutDialog }; -} - /** common type for all app actions. */ export type AppAction = | AppReloadAction @@ -155,6 +135,4 @@ export type AppAction = | AppDidInstallAction | AppDidStartAction | AppOpenSettingsAction - | AppCloseSettingsAction - | AppOpenAboutDialogAction - | AppCloseAboutDialogAction; + | AppCloseSettingsAction; diff --git a/src/app/reducers.test.ts b/src/app/reducers.test.ts index 8f4c8bb1..1350b89a 100644 --- a/src/app/reducers.test.ts +++ b/src/app/reducers.test.ts @@ -6,14 +6,12 @@ import { didSucceed, didUpdate } from '../service-worker/actions'; import { BeforeInstallPromptEvent } from '../utils/dom'; import { checkForUpdate, - closeAboutDialog, closeSettings, didBeforeInstallPrompt, didCheckForUpdate, didInstall, didInstallPrompt, installPrompt, - openAboutDialog, openSettings, } from './actions'; import reducers from './reducers'; @@ -28,7 +26,6 @@ test('initial state', () => { "promptingInstall": false, "readyForOfflineUse": false, "serviceWorker": null, - "showAboutDialog": false, "showSettings": false, "updateAvailable": false, } @@ -44,17 +41,6 @@ test('showSettings', () => { ).toBe(false); }); -test('showAboutDialog', () => { - expect( - reducers({ showAboutDialog: false } as State, openAboutDialog()) - .showAboutDialog, - ).toBe(true); - expect( - reducers({ showAboutDialog: true } as State, closeAboutDialog()) - .showAboutDialog, - ).toBe(false); -}); - test('serviceWorker', () => { const registration = {} as ServiceWorkerRegistration; expect( diff --git a/src/app/reducers.ts b/src/app/reducers.ts index cbb8cc3d..ce053b99 100644 --- a/src/app/reducers.ts +++ b/src/app/reducers.ts @@ -20,17 +20,6 @@ const showSettings: Reducer = (state = false, action) => { } }; -const showAboutDialog: Reducer = (state = false, action) => { - switch (action.type) { - case AppActionType.OpenAboutDialog: - return true; - case AppActionType.CloseAboutDialog: - return false; - default: - return state; - } -}; - const serviceWorker: Reducer = ( state = null, action, @@ -105,7 +94,6 @@ const readyForOfflineUse: Reducer = (state = false, action) => export default combineReducers({ showSettings, - showAboutDialog, serviceWorker, checkingForUpdate, updateAvailable, diff --git a/src/settings/SettingsDrawer.tsx b/src/settings/SettingsDrawer.tsx index 557d5d64..dbc5ca46 100644 --- a/src/settings/SettingsDrawer.tsx +++ b/src/settings/SettingsDrawer.tsx @@ -19,13 +19,7 @@ import { WithI18nProps, withI18n } from '@shopify/react-i18n'; import React from 'react'; import { connect } from 'react-redux'; import AboutDialog from '../about/AboutDialog'; -import { - checkForUpdate, - closeSettings, - installPrompt, - openAboutDialog, - reload, -} from '../app/actions'; +import { checkForUpdate, closeSettings, installPrompt, reload } from '../app/actions'; import { pybricksBugReportsUrl, pybricksGitterUrl, @@ -61,7 +55,6 @@ type DispatchProps = { onShowDocsChanged: (checked: boolean) => void; onDarkModeChanged: (checked: boolean) => void; onFlashCurrentProgramChanged: (checked: boolean) => void; - onAbout: () => void; onToggleDocs: () => void; onCheckForUpdate: (registration: ServiceWorkerRegistration) => void; onReload: (registration: ServiceWorkerRegistration) => void; @@ -72,6 +65,10 @@ type SettingsProps = StateProps & DispatchProps & WithI18nProps; @HotkeysTarget class SettingsDrawer extends React.PureComponent { + public state = { + aboutDialogIsOpen: false, + }; + render(): JSX.Element { const { open, @@ -88,7 +85,6 @@ class SettingsDrawer extends React.PureComponent { onShowDocsChanged, onDarkModeChanged, onFlashCurrentProgramChanged, - onAbout, onCheckForUpdate, onReload, onInstallPrompt: onInstall, @@ -224,7 +220,12 @@ class SettingsDrawer extends React.PureComponent {   - + + this.setState({ aboutDialogIsOpen: false }) + } + /> {