|
| 1 | +import { Button, Card, CardBody, CardFooter } from '@nextui-org/react' |
| 2 | +import { useControledMihomoConfig } from '@renderer/hooks/use-controled-mihomo-config' |
| 3 | +import BorderSwitch from '@renderer/components/base/border-swtich' |
| 4 | +import { MdOutlineDns } from 'react-icons/md' |
| 5 | +import { useLocation, useNavigate } from 'react-router-dom' |
| 6 | +import { patchMihomoConfig } from '@renderer/utils/ipc' |
| 7 | + |
| 8 | +const DNSCard: React.FC = () => { |
| 9 | + const navigate = useNavigate() |
| 10 | + const location = useLocation() |
| 11 | + const match = location.pathname.includes('/dns') |
| 12 | + const { controledMihomoConfig, patchControledMihomoConfig } = useControledMihomoConfig(true) |
| 13 | + const { dns, tun } = controledMihomoConfig || {} |
| 14 | + const { enable } = dns || {} |
| 15 | + |
| 16 | + const onChange = async (enable: boolean): Promise<void> => { |
| 17 | + await patchControledMihomoConfig({ dns: { enable } }) |
| 18 | + await patchMihomoConfig({ dns: { enable } }) |
| 19 | + } |
| 20 | + |
| 21 | + return ( |
| 22 | + <Card |
| 23 | + className={`w-[50%] mr-1 mb-2 ${match ? 'bg-primary' : ''}`} |
| 24 | + isPressable |
| 25 | + onPress={() => navigate('/dns')} |
| 26 | + > |
| 27 | + <CardBody className="pb-1 pt-0 px-0"> |
| 28 | + <div className="flex justify-between"> |
| 29 | + <Button |
| 30 | + isIconOnly |
| 31 | + className="bg-transparent pointer-events-none" |
| 32 | + variant="flat" |
| 33 | + color="default" |
| 34 | + > |
| 35 | + <MdOutlineDns |
| 36 | + className={`${match ? 'text-white' : 'text-foreground'} text-[24px] font-bold`} |
| 37 | + /> |
| 38 | + </Button> |
| 39 | + <BorderSwitch |
| 40 | + isShowBorder={match && enable} |
| 41 | + isSelected={enable} |
| 42 | + isDisabled={tun?.enable} |
| 43 | + onValueChange={onChange} |
| 44 | + /> |
| 45 | + </div> |
| 46 | + </CardBody> |
| 47 | + <CardFooter className="pt-1"> |
| 48 | + <h3 className={`select-none text-md font-bold ${match ? 'text-white' : 'text-foreground'}`}> |
| 49 | + DNS |
| 50 | + </h3> |
| 51 | + </CardFooter> |
| 52 | + </Card> |
| 53 | + ) |
| 54 | +} |
| 55 | + |
| 56 | +export default DNSCard |
0 commit comments