diff --git a/src/renderer/src/components/connections/connection-item.tsx b/src/renderer/src/components/connections/connection-item.tsx index cef80aa..d79121b 100644 --- a/src/renderer/src/components/connections/connection-item.tsx +++ b/src/renderer/src/components/connections/connection-item.tsx @@ -1,28 +1,34 @@ import { Button, Card, CardFooter, CardHeader, Chip } from '@nextui-org/react' import { calcTraffic } from '@renderer/utils/calc' import dayjs from 'dayjs' -import React, { useState } from 'react' +import React, { useEffect } from 'react' import { CgClose } from 'react-icons/cg' -import ConnectionDetailModal from './connection-detail-modal' interface Props { index: number info: IMihomoConnectionDetail + selected: IMihomoConnectionDetail | undefined + setSelected: React.Dispatch> + setIsDetailModalOpen: React.Dispatch> close: (id: string) => Promise } const ConnectionItem: React.FC = (props) => { - const { index, info } = props - const [isDetailModalOpen, setIsDetailModalOpen] = useState(false) + const { index, info, close, selected, setSelected, setIsDetailModalOpen } = props + + useEffect(() => { + if (selected?.id === info.id) { + setSelected(info) + } + }, [info]) + return (
- {isDetailModalOpen && ( - setIsDetailModalOpen(false)} connection={info} /> - )} { + setSelected(info) setIsDetailModalOpen(true) }} > @@ -75,7 +81,7 @@ const ConnectionItem: React.FC = (props) => { isIconOnly className="mr-2 my-auto" onPress={() => { - props.close(info.id) + close(info.id) }} > diff --git a/src/renderer/src/pages/connections.tsx b/src/renderer/src/pages/connections.tsx index 090851d..bcf4e64 100644 --- a/src/renderer/src/pages/connections.tsx +++ b/src/renderer/src/pages/connections.tsx @@ -11,6 +11,7 @@ import { calcTraffic } from '@renderer/utils/calc' import ConnectionItem from '@renderer/components/connections/connection-item' import { Virtuoso } from 'react-virtuoso' import dayjs from 'dayjs' +import ConnectionDetailModal from '@renderer/components/connections/connection-detail-modal' let preData: IMihomoConnectionDetail[] = [] @@ -18,6 +19,8 @@ const Connections: React.FC = () => { const [filter, setFilter] = useState('') const [connectionsInfo, setConnectionsInfo] = useState() const [connections, setConnections] = useState([]) + const [isDetailModalOpen, setIsDetailModalOpen] = useState(false) + const [selected, setSelected] = useState() const [direction, setDirection] = useState(true) const [sortBy, setSortBy] = useState('time') const filteredConnections = useMemo(() => { @@ -117,6 +120,9 @@ const Connections: React.FC = () => {
} > + {isDetailModalOpen && selected && ( + setIsDetailModalOpen(false)} connection={selected} /> + )}
{ data={filteredConnections} itemContent={(i, connection) => (