mirror of
https://gh.catmak.name/https://github.com/mihomo-party-org/mihomo-party
synced 2025-12-27 21:20:29 +08:00
keep detail
This commit is contained in:
parent
df41310237
commit
18d901673c
@ -1,28 +1,34 @@
|
|||||||
import { Button, Card, CardFooter, CardHeader, Chip } from '@nextui-org/react'
|
import { Button, Card, CardFooter, CardHeader, Chip } from '@nextui-org/react'
|
||||||
import { calcTraffic } from '@renderer/utils/calc'
|
import { calcTraffic } from '@renderer/utils/calc'
|
||||||
import dayjs from 'dayjs'
|
import dayjs from 'dayjs'
|
||||||
import React, { useState } from 'react'
|
import React, { useEffect } from 'react'
|
||||||
import { CgClose } from 'react-icons/cg'
|
import { CgClose } from 'react-icons/cg'
|
||||||
import ConnectionDetailModal from './connection-detail-modal'
|
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
index: number
|
index: number
|
||||||
info: IMihomoConnectionDetail
|
info: IMihomoConnectionDetail
|
||||||
|
selected: IMihomoConnectionDetail | undefined
|
||||||
|
setSelected: React.Dispatch<React.SetStateAction<IMihomoConnectionDetail | undefined>>
|
||||||
|
setIsDetailModalOpen: React.Dispatch<React.SetStateAction<boolean>>
|
||||||
close: (id: string) => Promise<void>
|
close: (id: string) => Promise<void>
|
||||||
}
|
}
|
||||||
|
|
||||||
const ConnectionItem: React.FC<Props> = (props) => {
|
const ConnectionItem: React.FC<Props> = (props) => {
|
||||||
const { index, info } = props
|
const { index, info, close, selected, setSelected, setIsDetailModalOpen } = props
|
||||||
const [isDetailModalOpen, setIsDetailModalOpen] = useState(false)
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (selected?.id === info.id) {
|
||||||
|
setSelected(info)
|
||||||
|
}
|
||||||
|
}, [info])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={`px-2 pb-2 ${index === 0 ? 'pt-2' : ''}`}>
|
<div className={`px-2 pb-2 ${index === 0 ? 'pt-2' : ''}`}>
|
||||||
{isDetailModalOpen && (
|
|
||||||
<ConnectionDetailModal onClose={() => setIsDetailModalOpen(false)} connection={info} />
|
|
||||||
)}
|
|
||||||
<Card
|
<Card
|
||||||
isPressable
|
isPressable
|
||||||
className="w-full"
|
className="w-full"
|
||||||
onPress={() => {
|
onPress={() => {
|
||||||
|
setSelected(info)
|
||||||
setIsDetailModalOpen(true)
|
setIsDetailModalOpen(true)
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
@ -75,7 +81,7 @@ const ConnectionItem: React.FC<Props> = (props) => {
|
|||||||
isIconOnly
|
isIconOnly
|
||||||
className="mr-2 my-auto"
|
className="mr-2 my-auto"
|
||||||
onPress={() => {
|
onPress={() => {
|
||||||
props.close(info.id)
|
close(info.id)
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<CgClose className="text-lg" />
|
<CgClose className="text-lg" />
|
||||||
|
|||||||
@ -11,6 +11,7 @@ import { calcTraffic } from '@renderer/utils/calc'
|
|||||||
import ConnectionItem from '@renderer/components/connections/connection-item'
|
import ConnectionItem from '@renderer/components/connections/connection-item'
|
||||||
import { Virtuoso } from 'react-virtuoso'
|
import { Virtuoso } from 'react-virtuoso'
|
||||||
import dayjs from 'dayjs'
|
import dayjs from 'dayjs'
|
||||||
|
import ConnectionDetailModal from '@renderer/components/connections/connection-detail-modal'
|
||||||
|
|
||||||
let preData: IMihomoConnectionDetail[] = []
|
let preData: IMihomoConnectionDetail[] = []
|
||||||
|
|
||||||
@ -18,6 +19,8 @@ const Connections: React.FC = () => {
|
|||||||
const [filter, setFilter] = useState('')
|
const [filter, setFilter] = useState('')
|
||||||
const [connectionsInfo, setConnectionsInfo] = useState<IMihomoConnectionsInfo>()
|
const [connectionsInfo, setConnectionsInfo] = useState<IMihomoConnectionsInfo>()
|
||||||
const [connections, setConnections] = useState<IMihomoConnectionDetail[]>([])
|
const [connections, setConnections] = useState<IMihomoConnectionDetail[]>([])
|
||||||
|
const [isDetailModalOpen, setIsDetailModalOpen] = useState(false)
|
||||||
|
const [selected, setSelected] = useState<IMihomoConnectionDetail>()
|
||||||
const [direction, setDirection] = useState(true)
|
const [direction, setDirection] = useState(true)
|
||||||
const [sortBy, setSortBy] = useState('time')
|
const [sortBy, setSortBy] = useState('time')
|
||||||
const filteredConnections = useMemo(() => {
|
const filteredConnections = useMemo(() => {
|
||||||
@ -117,6 +120,9 @@ const Connections: React.FC = () => {
|
|||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
|
{isDetailModalOpen && selected && (
|
||||||
|
<ConnectionDetailModal onClose={() => setIsDetailModalOpen(false)} connection={selected} />
|
||||||
|
)}
|
||||||
<div className="overflow-x-auto sticky top-[49px] z-40">
|
<div className="overflow-x-auto sticky top-[49px] z-40">
|
||||||
<div className="flex p-2 gap-2">
|
<div className="flex p-2 gap-2">
|
||||||
<Input
|
<Input
|
||||||
@ -158,6 +164,9 @@ const Connections: React.FC = () => {
|
|||||||
data={filteredConnections}
|
data={filteredConnections}
|
||||||
itemContent={(i, connection) => (
|
itemContent={(i, connection) => (
|
||||||
<ConnectionItem
|
<ConnectionItem
|
||||||
|
setSelected={setSelected}
|
||||||
|
setIsDetailModalOpen={setIsDetailModalOpen}
|
||||||
|
selected={selected}
|
||||||
close={mihomoCloseConnection}
|
close={mihomoCloseConnection}
|
||||||
index={i}
|
index={i}
|
||||||
key={connection.id}
|
key={connection.id}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user