@@ -9,20 +9,22 @@ import { Global } from '@emotion/react'
99import cc from 'chrome-call'
1010
1111import Client from '../../common/api'
12- import { Config } from '../../common/types'
12+ import { APIRegions , Config } from '../../common/types'
1313
1414import OptionSection from './components/OptionSection'
1515
1616const Options : React . FC = ( ) => {
1717 const [ targetLang , setTargetLang ] = useState ( 'ZH' )
1818 const [ token , setToken ] = useState ( '' )
19+ const [ region , setRegion ] = useState < APIRegions > ( 'default' )
1920
2021 const onSubmit : FormEventHandler = ( e ) => {
2122 e . preventDefault ( )
2223 ; ( async ( ) => {
2324 await cc ( chrome . storage . sync , 'set' , {
2425 targetLang,
2526 token,
27+ region,
2628 } )
2729
2830 window . alert ( '保存成功' )
@@ -37,7 +39,7 @@ const Options: React.FC = () => {
3739 return
3840 }
3941
40- const client = new Client ( token )
42+ const client = new Client ( token , region )
4143
4244 client
4345 . translate ( 'This is a test message.' , 'ZH' )
@@ -53,6 +55,7 @@ const Options: React.FC = () => {
5355 cc ( chrome . storage . sync , 'get' ) . then ( ( config : Config ) => {
5456 setTargetLang ( config . targetLang )
5557 setToken ( config . token )
58+ setRegion ( config . region )
5659 } )
5760 } , [ ] )
5861
@@ -90,7 +93,7 @@ const Options: React.FC = () => {
9093 < OptionSection title = { '目标语言' } >
9194 < select
9295 tw = "px-4 py-3 rounded-md"
93- name = "target-language "
96+ name = "target-lang "
9497 value = { targetLang }
9598 onChange = { ( e ) => setTargetLang ( e . target . value ) } >
9699 < option value = "ZH" > 中文</ option >
@@ -118,6 +121,20 @@ const Options: React.FC = () => {
118121 onChange = { ( e ) => setToken ( e . target . value ) }
119122 />
120123 </ OptionSection >
124+
125+ < OptionSection title = { 'API Region' } >
126+ < select
127+ tw = "px-4 py-3 rounded-md"
128+ name = "region"
129+ value = { region }
130+ onChange = { ( e ) => setRegion ( e . target . value as APIRegions ) } >
131+ < option value = "default" > 默认</ option >
132+ < option value = "global" > 全球(非亚洲地区)</ option >
133+ { process . env . NODE_ENV !== 'production' ? (
134+ < option value = "dev" > DEV</ option >
135+ ) : undefined }
136+ </ select >
137+ </ OptionSection >
121138 </ div >
122139
123140 < div tw = "p-5 space-x-4 justify-self-end" >
0 commit comments