Skip to content

Commit

Permalink
feat: wan interface auto detect
Browse files Browse the repository at this point in the history
  • Loading branch information
kunish committed Jul 2, 2023
1 parent 90f33d5 commit 5b9ee55
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 22 deletions.
34 changes: 20 additions & 14 deletions src/components/ConfigFormModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -171,23 +171,29 @@ export const ConfigFormDrawer = forwardRef(({ opened, onClose }: { opened: boole

const { data: generalQuery } = useGeneralQuery()

const wanInterfacesData: { value: string; label: string }[] = useMemo(() => {
const wanInterfacesData = useMemo(() => {
const interfaces = generalQuery?.general.interfaces

if (interfaces) {
return interfaces
.filter(({ flag }) => !!flag.default)
.map(({ name, ip }) => ({
label: name,
value: name,
description: (
<Stack spacing="xs">
{ip.map((addr, i) => (
<Text key={i}>{addr}</Text>
))}
</Stack>
),
}))
return [
{
label: '自动',
value: 'auto',
},
...interfaces
.filter(({ flag }) => !!flag.default)
.map(({ name, ip }) => ({
label: name,
value: name,
description: (
<Stack spacing="xs">
{ip.map((addr, i) => (
<Text key={i}>{addr}</Text>
))}
</Stack>
),
})),
]
}

return []
Expand Down
18 changes: 10 additions & 8 deletions src/components/SelectItemWithDescription.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { forwardRef } from 'react'

interface SelectItemWithDescriptionProps extends React.ComponentPropsWithoutRef<'div'> {
label: React.ReactNode
description: React.ReactNode
description?: React.ReactNode
selected?: boolean
}

Expand All @@ -12,13 +12,15 @@ export const SelectItemWithDescription = forwardRef<HTMLDivElement, SelectItemWi
<Stack ref={ref} spacing={4} {...props}>
<Text>{label}</Text>

<Input.Description
sx={{
color: props.selected ? 'white' : undefined,
}}
>
{description}
</Input.Description>
{description && (
<Input.Description
sx={{
color: props.selected ? 'white' : undefined,
}}
>
{description}
</Input.Description>
)}
</Stack>
)
)
1 change: 1 addition & 0 deletions src/i18n/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"address": "address",
"allowInsecure": "Allow Insecure",
"autoConfigKernelParameter": "Auto Config Kernel Parameter",
"autoDetect": "Auto Detect",
"avatar": "avatar",
"checkInterval": "Check Interval",
"checkTolerance": "Check Tolerance",
Expand Down
1 change: 1 addition & 0 deletions src/i18n/locales/zh-Hans.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"address": "地址",
"allowInsecure": "允许不安全",
"autoConfigKernelParameter": "自动配置内核参数",
"autoDetect": "自动识别",
"avatar": "头像",
"checkInterval": "检测间隔",
"checkTolerance": "检测公差",
Expand Down

0 comments on commit 5b9ee55

Please sign in to comment.