rule page

This commit is contained in:
pompurin404 2024-08-03 21:44:07 +08:00
parent 46a1f8ee45
commit 091b92cc50
No known key found for this signature in database
2 changed files with 62 additions and 1 deletions

View File

@ -0,0 +1,19 @@
import { Card, CardBody } from '@nextui-org/react'
import React from 'react'
const RuleItem: React.FC<IMihomoRulesDetail> = (props) => {
const { type, payload, proxy } = props
return (
<Card className="m-2">
<CardBody className="flex justify-between">
<div className="flex justify-between">
<div className="select-none">{type}</div>
<div className="select-none">{payload}</div>
<div className="select-none">{proxy}</div>
</div>
</CardBody>
</Card>
)
}
export default RuleItem

View File

@ -1,7 +1,49 @@
import BasePage from '@renderer/components/base/base-page'
import RuleItem from '@renderer/components/rules/rule-item'
import { useMemo, useState } from 'react'
import { Input } from '@nextui-org/react'
import useSWR from 'swr'
import { mihomoRules } from '@renderer/utils/ipc'
const Rules: React.FC = () => {
return <BasePage title="分流规则"></BasePage>
const { data: rules = { rules: [] } } = useSWR<IMihomoRulesInfo>('/rules', mihomoRules, {
refreshInterval: 5000
})
const [filter, setFilter] = useState('')
const filteredRules = useMemo(() => {
if (filter === '') return rules.rules
return rules.rules.filter((rule) => {
return (
rule.payload.includes(filter) || rule.type.includes(filter) || rule.proxy.includes(filter)
)
})
}, [rules, filter])
return (
<BasePage title="分流规则">
<div className="sticky top-[48px] z-40 backdrop-blur bg-background/40 flex p-2">
<Input
variant="bordered"
size="sm"
value={filter}
placeholder="筛选过滤"
onValueChange={setFilter}
/>
</div>
{filteredRules.map((rule, index) => {
return (
<RuleItem
key={rule.payload + index}
type={rule.type}
payload={rule.payload}
proxy={rule.proxy}
size={rule.size}
/>
)
})}
</BasePage>
)
}
export default Rules