From 2a421573de1cd0f518f64de7204d8929a96c8124 Mon Sep 17 00:00:00 2001 From: kunish Date: Tue, 28 Feb 2023 15:49:53 +0800 Subject: fix: i18n not following system language setting --- src/components/Config.tsx | 46 ++++++++++++++++++++++------------------ src/components/Input.tsx | 10 +-------- src/components/shared/Select.tsx | 7 +++--- 3 files changed, 29 insertions(+), 34 deletions(-) (limited to 'src/components') diff --git a/src/components/Config.tsx b/src/components/Config.tsx index 67843f6..84be48e 100644 --- a/src/components/Config.tsx +++ b/src/components/Config.tsx @@ -102,6 +102,8 @@ function ConfigImpl({ latencyTestUrl, apiConfig, }: ConfigImplProps) { + const { t, i18n } = useTranslation(); + const [configState, setConfigStateInternal] = useState(configs); const refConfigs = useRef(configs); useEffect(() => { @@ -116,7 +118,7 @@ function ConfigImpl({ }, [dispatch]); const setConfigState = useCallback( - (name: any, val: any) => { + (name: string, val: any) => { setConfigStateInternal({ ...configState, [name]: val }); }, [configState] @@ -130,7 +132,7 @@ function ConfigImpl({ [configState] ); - const handleChangeValue = useCallback( + const handleInputOnChange = useCallback( ({ name, value }) => { switch (name) { case 'mode': @@ -166,17 +168,16 @@ function ConfigImpl({ [apiConfig, dispatch, setConfigState, setTunConfigState] ); - const handleInputOnChange = useCallback( - (e: { target: { name: any; value: any } }) => handleChangeValue(e.target), - [handleChangeValue] - ); - const { selectChartStyleIndex, updateAppConfig } = useStoreActions(); const handleInputOnBlur = useCallback( - (e: { target: any }) => { - const target = e.target; - const { name, value } = target; + ( + e: + | React.FocusEvent + | React.ChangeEvent + ) => { + const { name, value } = e.target; + switch (name) { case 'port': case 'socks-port': @@ -217,8 +218,6 @@ function ConfigImpl({ fetchVersion('/version', apiConfig) ); - const { t, i18n } = useTranslation(); - return (
@@ -230,8 +229,7 @@ function ConfigImpl({ handleInputOnChange({ name, value })} onBlur={handleInputOnBlur} />
@@ -243,7 +241,7 @@ function ConfigImpl({ handleChangeValue({ name: 'log-level', value: e.target.value })} + onChange={(e) => handleInputOnChange({ name: 'log-level', value: e.target.value })} /> @@ -262,7 +260,9 @@ function ConfigImpl({ handleChangeValue({ name: 'allow-lan', value: value })} + onChange={(value: boolean) => + handleInputOnChange({ name: 'allow-lan', value: value }) + } /> @@ -273,7 +273,9 @@ function ConfigImpl({ handleChangeValue({ name: 'sniffing', value: value })} + onChange={(value: boolean) => + handleInputOnChange({ name: 'sniffing', value: value }) + } /> @@ -290,7 +292,9 @@ function ConfigImpl({
handleChangeValue({ name: 'enable', value: value })} + onChange={(value: boolean) => + handleInputOnChange({ name: 'enable', value: value }) + } />
@@ -299,7 +303,7 @@ function ConfigImpl({ diff --git a/src/components/Input.tsx b/src/components/Input.tsx index 1f3458b..ade19b2 100644 --- a/src/components/Input.tsx +++ b/src/components/Input.tsx @@ -4,15 +4,7 @@ import s0 from './Input.module.scss'; const { useState, useRef, useEffect, useCallback } = React; -type InputProps = { - value?: string | number; - type?: string; - onChange?: (...args: any[]) => any; - name?: string; - placeholder?: string; -}; - -export default function Input(props: InputProps) { +export default function Input(props: React.InputHTMLAttributes) { return ; } diff --git a/src/components/shared/Select.tsx b/src/components/shared/Select.tsx index de409cb..8d00f43 100644 --- a/src/components/shared/Select.tsx +++ b/src/components/shared/Select.tsx @@ -5,13 +5,12 @@ import s from './Select.module.scss'; type Props = { options: Array; selected: string; - onChange: (event: React.ChangeEvent) => any; -}; +} & React.SelectHTMLAttributes; -export default function Select({ options, selected, onChange }: Props) { +export default function Select({ options, selected, onChange, ...props }: Props) { return ( // eslint-disable-next-line jsx-a11y/no-onchange - {options.map(([value, name]) => (