From e62add68938fa6449943bf9822e0ca6f50e2d68f Mon Sep 17 00:00:00 2001 From: Alexis Svinartchouk Date: Wed, 29 Apr 2020 19:37:31 +0200 Subject: [PATCH] Remove some `any`s Change-type: patch --- .../drive-selector/target-selector.tsx | 4 +- lib/gui/app/components/finish/finish.tsx | 19 +++--- .../flash-another/flash-another.tsx | 7 +-- .../progress-button/progress-button.tsx | 2 +- lib/gui/app/components/settings/settings.tsx | 60 ++++++++++--------- lib/shared/utils.ts | 2 +- 6 files changed, 48 insertions(+), 46 deletions(-) diff --git a/lib/gui/app/components/drive-selector/target-selector.tsx b/lib/gui/app/components/drive-selector/target-selector.tsx index ea2fe8db..fe35b9b9 100644 --- a/lib/gui/app/components/drive-selector/target-selector.tsx +++ b/lib/gui/app/components/drive-selector/target-selector.tsx @@ -41,8 +41,8 @@ const TargetDetail = styled((props) => )` interface TargetSelectorProps { targets: any[]; disabled: boolean; - openDriveSelector: () => any; - reselectDrive: () => any; + openDriveSelector: () => void; + reselectDrive: () => void; flashing: boolean; show: boolean; tooltip: string; diff --git a/lib/gui/app/components/finish/finish.tsx b/lib/gui/app/components/finish/finish.tsx index 4ee04336..c2df38b8 100644 --- a/lib/gui/app/components/finish/finish.tsx +++ b/lib/gui/app/components/finish/finish.tsx @@ -27,12 +27,9 @@ import { FlashAnother } from '../flash-another/flash-another'; import { FlashResults } from '../flash-results/flash-results'; import { SVGIcon } from '../svg-icon/svg-icon'; -const restart = (options: any, goToMain: () => void) => { - if (!options.preserveImage) { - selectionState.deselectImage(); - } +function restart(goToMain: () => void) { selectionState.deselectAllDrives(); - analytics.logEvent('Restart', options); + analytics.logEvent('Restart'); // Reset the flashing workflow uuid store.dispatch({ @@ -41,9 +38,9 @@ const restart = (options: any, goToMain: () => void) => { }); goToMain(); -}; +} -const formattedErrors = () => { +function formattedErrors() { const errors = _.map( _.get(flashState.getFlashResults(), ['results', 'errors']), (error) => { @@ -51,7 +48,7 @@ const formattedErrors = () => { }, ); return errors.join('\n'); -}; +} function FinishPage({ goToMain }: { goToMain: () => void }) { const results = flashState.getFlashResults().results || {}; @@ -62,8 +59,10 @@ function FinishPage({ goToMain }: { goToMain: () => void }) { restart(options, goToMain)} - > + onClick={() => { + restart(goToMain); + }} + />
diff --git a/lib/gui/app/components/flash-another/flash-another.tsx b/lib/gui/app/components/flash-another/flash-another.tsx index 7083ace3..a3c36874 100644 --- a/lib/gui/app/components/flash-another/flash-another.tsx +++ b/lib/gui/app/components/flash-another/flash-another.tsx @@ -26,17 +26,14 @@ const Div = styled.div` `; export interface FlashAnotherProps { - onClick: (options: { preserveImage: boolean }) => void; + onClick: () => void; } export const FlashAnother = (props: FlashAnotherProps) => { return (
- + Flash Another
diff --git a/lib/gui/app/components/progress-button/progress-button.tsx b/lib/gui/app/components/progress-button/progress-button.tsx index deed25fb..1d2080bb 100644 --- a/lib/gui/app/components/progress-button/progress-button.tsx +++ b/lib/gui/app/components/progress-button/progress-button.tsx @@ -46,7 +46,7 @@ interface ProgressButtonProps { percentage: number; label: string; disabled: boolean; - callback: () => any; + callback: () => void; } const colors = { diff --git a/lib/gui/app/components/settings/settings.tsx b/lib/gui/app/components/settings/settings.tsx index ef0f2d1a..1811d0e5 100644 --- a/lib/gui/app/components/settings/settings.tsx +++ b/lib/gui/app/components/settings/settings.tsx @@ -61,7 +61,10 @@ const WarningModal = ({ interface Setting { name: string; label: string | JSX.Element; - options?: any; + options?: { + description: string; + confirmLabel: string; + }; hide?: boolean; } @@ -109,15 +112,19 @@ async function getSettingsList(): Promise { ]; } +interface Warning { + setting: string; + settingValue: boolean; + description: string; + confirmLabel: string; +} + interface SettingsModalProps { toggleModal: (value: boolean) => void; } export function SettingsModal({ toggleModal }: SettingsModalProps) { - const [settingsList, setCurrentSettingsList]: [ - Setting[], - React.Dispatch>, - ] = React.useState([]); + const [settingsList, setCurrentSettingsList] = React.useState([]); React.useEffect(() => { (async () => { if (settingsList.length === 0) { @@ -125,10 +132,9 @@ export function SettingsModal({ toggleModal }: SettingsModalProps) { } })(); }); - const [currentSettings, setCurrentSettings]: [ - _.Dictionary, - React.Dispatch>>, - ] = React.useState({}); + const [currentSettings, setCurrentSettings] = React.useState< + _.Dictionary + >({}); React.useEffect(() => { (async () => { if (_.isEmpty(currentSettings)) { @@ -136,14 +142,14 @@ export function SettingsModal({ toggleModal }: SettingsModalProps) { } })(); }); - const [warning, setWarning]: [ - any, - React.Dispatch>, - ] = React.useState({}); + const [warning, setWarning] = React.useState(undefined); - const toggleSetting = async (setting: string, options?: any) => { + const toggleSetting = async ( + setting: string, + options?: Setting['options'], + ) => { const value = currentSettings[setting]; - const dangerous = !_.isUndefined(options); + const dangerous = options !== undefined; analytics.logEvent('Toggle setting', { setting, @@ -151,22 +157,22 @@ export function SettingsModal({ toggleModal }: SettingsModalProps) { dangerous, }); - if (value || !dangerous) { + if (value || options === undefined) { await settings.set(setting, !value); setCurrentSettings({ ...currentSettings, [setting]: !value, }); - setWarning({}); + setWarning(undefined); return; + } else { + // Show warning since it's a dangerous setting + setWarning({ + setting, + settingValue: value, + ...options, + }); } - - // Show warning since it's a dangerous setting - setWarning({ - setting, - settingValue: value, - ...options, - }); }; return ( @@ -206,7 +212,7 @@ export function SettingsModal({ toggleModal }: SettingsModalProps) {
- {_.isEmpty(warning) ? null : ( + {warning === undefined ? null : ( { - setWarning({}); + setWarning(undefined); }} /> )} diff --git a/lib/shared/utils.ts b/lib/shared/utils.ts index 557cb934..f9d34143 100755 --- a/lib/shared/utils.ts +++ b/lib/shared/utils.ts @@ -41,7 +41,7 @@ export function percentageToFloat(percentage: any) { /** * @summary Check if obj has one or many specific props */ -export function hasProps(obj: any, props: string[]): boolean { +export function hasProps(obj: _.Dictionary, props: string[]): boolean { return _.every(props, (prop) => { return _.has(obj, prop); });