From 3aa87cc26fd58836b82c067b58a47e08e30a7784 Mon Sep 17 00:00:00 2001 From: crupest Date: Thu, 4 Jun 2020 00:18:50 +0800 Subject: refactor(front): Make codes lint-clean! --- Timeline/ClientApp/src/common/OperationDialog.tsx | 35 ++++++++++++----------- 1 file changed, 18 insertions(+), 17 deletions(-) (limited to 'Timeline/ClientApp/src/common/OperationDialog.tsx') diff --git a/Timeline/ClientApp/src/common/OperationDialog.tsx b/Timeline/ClientApp/src/common/OperationDialog.tsx index e7b6612c..501a353e 100644 --- a/Timeline/ClientApp/src/common/OperationDialog.tsx +++ b/Timeline/ClientApp/src/common/OperationDialog.tsx @@ -1,4 +1,4 @@ -import React, { useState, InputHTMLAttributes } from 'react'; +import React, { useState } from 'react'; import { useTranslation } from 'react-i18next'; import { Spinner, @@ -12,10 +12,12 @@ import { Button, Modal, ModalHeader, - FormText + FormText, } from 'reactstrap'; -const DefaultProcessPrompt: React.FC = _ => { +import { UiLogicError } from '../common'; + +const DefaultProcessPrompt: React.FC = (_) => { return ( @@ -27,7 +29,7 @@ interface DefaultErrorPromptProps { error?: string; } -const DefaultErrorPrompt: React.FC = props => { +const DefaultErrorPrompt: React.FC = (props) => { const { t } = useTranslation(); let result =

{t('operationDialog.error')}

; @@ -111,7 +113,7 @@ interface OperationDialogProps { onSuccessAndClose?: () => void; } -const OperationDialog: React.FC = props => { +const OperationDialog: React.FC = (props) => { const inputScheme = props.inputScheme ?? []; const { t } = useTranslation(); @@ -119,13 +121,13 @@ const OperationDialog: React.FC = props => { type Step = 'input' | 'process' | OperationResult; const [step, setStep] = useState('input'); const [values, setValues] = useState<(boolean | string)[]>( - inputScheme.map(i => { + inputScheme.map((i) => { if (i.type === 'bool') { return i.initValue ?? false; } else if (i.type === 'text' || i.type === 'select') { return i.initValue ?? ''; } else { - throw new Error('Unknown input scheme.'); + throw new UiLogicError('Unknown input scheme.'); } }) ); @@ -149,16 +151,16 @@ const OperationDialog: React.FC = props => { const onConfirm = (): void => { setStep('process'); props.onProcess(values).then( - d => { + (d: unknown) => { setStep({ type: 'success', - data: d + data: d, }); }, - e => { + (e: unknown) => { setStep({ type: 'failure', - data: e + data: e, }); } ); @@ -205,8 +207,7 @@ const OperationDialog: React.FC = props => { const newInputError: OperationInputErrorInfo = { ...oldError }; for (const [index, error] of Object.entries(newError)) { if (error !== undefined) { - // eslint-disable-next-line @typescript-eslint/no-explicit-any - (newInputError as any)[index] = error; + newInputError[+index] = error as OperationInputOptionalError; } } return newInputError; @@ -236,7 +237,7 @@ const OperationDialog: React.FC = props => { {inputPrompt} {inputScheme.map((item, index) => { const value = values[index]; - const error: string | undefined = (e => + const error: string | undefined = ((e) => typeof e === 'string' ? t(e) : undefined)(inputError?.[index]); if (item.type === 'text') { @@ -246,7 +247,7 @@ const OperationDialog: React.FC = props => { { + onChange={(e) => { const v = e.target.value; const newValues = updateValue(index, v); setInputError( @@ -270,7 +271,7 @@ const OperationDialog: React.FC = props => { { + onChange={(e) => { updateValue( index, (e.target as HTMLInputElement).checked @@ -287,7 +288,7 @@ const OperationDialog: React.FC = props => { { + onChange={(event) => { updateValue(index, event.target.value); }} > -- cgit v1.2.3