Remove some anys

Change-type: patch
This commit is contained in:
Alexis Svinartchouk 2020-04-29 19:37:31 +02:00
parent 44fc429f64
commit e62add6893
6 changed files with 48 additions and 46 deletions

View File

@ -41,8 +41,8 @@ const TargetDetail = styled((props) => <Txt.span {...props}></Txt.span>)`
interface TargetSelectorProps {
targets: any[];
disabled: boolean;
openDriveSelector: () => any;
reselectDrive: () => any;
openDriveSelector: () => void;
reselectDrive: () => void;
flashing: boolean;
show: boolean;
tooltip: string;

View File

@ -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 }) {
<FlashResults results={results} errors={formattedErrors()} />
<FlashAnother
onClick={(options: any) => restart(options, goToMain)}
></FlashAnother>
onClick={() => {
restart(goToMain);
}}
/>
</div>
<div className="box center">

View File

@ -26,17 +26,14 @@ const Div = styled.div<any>`
`;
export interface FlashAnotherProps {
onClick: (options: { preserveImage: boolean }) => void;
onClick: () => void;
}
export const FlashAnother = (props: FlashAnotherProps) => {
return (
<ThemedProvider>
<Div position="absolute" right="152px">
<BaseButton
primary
onClick={props.onClick.bind(null, { preserveImage: true })}
>
<BaseButton primary onClick={props.onClick}>
Flash Another
</BaseButton>
</Div>

View File

@ -46,7 +46,7 @@ interface ProgressButtonProps {
percentage: number;
label: string;
disabled: boolean;
callback: () => any;
callback: () => void;
}
const colors = {

View File

@ -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<Setting[]> {
];
}
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.SetStateAction<Setting[]>>,
] = React.useState([]);
const [settingsList, setCurrentSettingsList] = React.useState<Setting[]>([]);
React.useEffect(() => {
(async () => {
if (settingsList.length === 0) {
@ -125,10 +132,9 @@ export function SettingsModal({ toggleModal }: SettingsModalProps) {
}
})();
});
const [currentSettings, setCurrentSettings]: [
_.Dictionary<boolean>,
React.Dispatch<React.SetStateAction<_.Dictionary<boolean>>>,
] = React.useState({});
const [currentSettings, setCurrentSettings] = React.useState<
_.Dictionary<boolean>
>({});
React.useEffect(() => {
(async () => {
if (_.isEmpty(currentSettings)) {
@ -136,14 +142,14 @@ export function SettingsModal({ toggleModal }: SettingsModalProps) {
}
})();
});
const [warning, setWarning]: [
any,
React.Dispatch<React.SetStateAction<any>>,
] = React.useState({});
const [warning, setWarning] = React.useState<Warning | undefined>(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) {
</div>
</div>
{_.isEmpty(warning) ? null : (
{warning === undefined ? null : (
<WarningModal
message={warning.description}
confirmLabel={warning.confirmLabel}
@ -216,10 +222,10 @@ export function SettingsModal({ toggleModal }: SettingsModalProps) {
...currentSettings,
[warning.setting]: true,
});
setWarning({});
setWarning(undefined);
}}
cancel={() => {
setWarning({});
setWarning(undefined);
}}
/>
)}

View File

@ -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<any>, props: string[]): boolean {
return _.every(props, (prop) => {
return _.has(obj, prop);
});