mirror of
https://gh.catmak.name/https://github.com/mihomo-party-org/mihomo-party
synced 2026-02-10 19:50:28 +08:00
fix closed connections update
This commit is contained in:
parent
d681ed762d
commit
ddcf370ffa
@ -67,15 +67,15 @@ const Connections: React.FC = () => {
|
|||||||
})
|
})
|
||||||
}, [activeConnections, closedConnections, filter, connectionDirection, connectionOrderBy])
|
}, [activeConnections, closedConnections, filter, connectionDirection, connectionOrderBy])
|
||||||
|
|
||||||
const closeAllConnections = () => {
|
const closeAllConnections = (): void => {
|
||||||
tab === 'active' ? mihomoCloseAllConnections() : trashAllClosedConnection()
|
tab === 'active' ? mihomoCloseAllConnections() : trashAllClosedConnection()
|
||||||
}
|
}
|
||||||
|
|
||||||
const closeConnection = (id: string) => {
|
const closeConnection = (id: string): void => {
|
||||||
tab === 'active' ? mihomoCloseConnection(id) : trashClosedConnection(id)
|
tab === 'active' ? mihomoCloseConnection(id) : trashClosedConnection(id)
|
||||||
}
|
}
|
||||||
|
|
||||||
const trashAllClosedConnection = () => {
|
const trashAllClosedConnection = (): void => {
|
||||||
const trashIds = closedConnections.map((conn) => conn.id)
|
const trashIds = closedConnections.map((conn) => conn.id)
|
||||||
setAllConnections((allConns) => allConns.filter((conn) => !trashIds.includes(conn.id)))
|
setAllConnections((allConns) => allConns.filter((conn) => !trashIds.includes(conn.id)))
|
||||||
setClosedConnections([])
|
setClosedConnections([])
|
||||||
@ -83,7 +83,7 @@ const Connections: React.FC = () => {
|
|||||||
cachedConnections = allConnections
|
cachedConnections = allConnections
|
||||||
}
|
}
|
||||||
|
|
||||||
const trashClosedConnection = (id: string) => {
|
const trashClosedConnection = (id: string): void => {
|
||||||
setAllConnections((allConns) => allConns.filter((conn) => conn.id != id))
|
setAllConnections((allConns) => allConns.filter((conn) => conn.id != id))
|
||||||
setClosedConnections((closedConns) => closedConns.filter((conn) => conn.id != id))
|
setClosedConnections((closedConns) => closedConns.filter((conn) => conn.id != id))
|
||||||
|
|
||||||
@ -95,7 +95,7 @@ const Connections: React.FC = () => {
|
|||||||
setConnectionsInfo(info)
|
setConnectionsInfo(info)
|
||||||
|
|
||||||
if (!info.connections) return
|
if (!info.connections) return
|
||||||
const allConns = unionWith(allConnections, activeConnections, (a, b) => a.id === b.id)
|
const allConns = unionWith(activeConnections, allConnections, (a, b) => a.id === b.id)
|
||||||
|
|
||||||
const activeConns = info.connections.map((conn) => {
|
const activeConns = info.connections.map((conn) => {
|
||||||
const preConn = activeConnections.find((c) => c.id === conn.id)
|
const preConn = activeConnections.find((c) => c.id === conn.id)
|
||||||
@ -105,17 +105,19 @@ const Connections: React.FC = () => {
|
|||||||
...conn,
|
...conn,
|
||||||
isActive: true,
|
isActive: true,
|
||||||
downloadSpeed: downloadSpeed,
|
downloadSpeed: downloadSpeed,
|
||||||
uploadSpeed: uploadSpeed,
|
uploadSpeed: uploadSpeed
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
const closedConns = differenceWith(allConns, activeConns, (a, b) => a.id === b.id).map((conn) => {
|
const closedConns = differenceWith(allConns, activeConns, (a, b) => a.id === b.id).map(
|
||||||
return {
|
(conn) => {
|
||||||
...conn,
|
return {
|
||||||
isActive: false,
|
...conn,
|
||||||
downloadSpeed: 0,
|
isActive: false,
|
||||||
uploadSpeed: 0,
|
downloadSpeed: 0,
|
||||||
|
uploadSpeed: 0
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
)
|
||||||
|
|
||||||
setActiveConnections(activeConns)
|
setActiveConnections(activeConns)
|
||||||
setClosedConnections(closedConns)
|
setClosedConnections(closedConns)
|
||||||
@ -165,7 +167,7 @@ const Connections: React.FC = () => {
|
|||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{tab === 'active' ? (<CgClose className="text-lg"/>) : (<CgTrash className="text-lg"/>)}
|
{tab === 'active' ? <CgClose className="text-lg" /> : <CgTrash className="text-lg" />}
|
||||||
</Button>
|
</Button>
|
||||||
</Badge>
|
</Badge>
|
||||||
</div>
|
</div>
|
||||||
@ -176,9 +178,9 @@ const Connections: React.FC = () => {
|
|||||||
)}
|
)}
|
||||||
<div className="overflow-x-auto sticky top-0 z-40">
|
<div className="overflow-x-auto sticky top-0 z-40">
|
||||||
<div className="flex p-2 gap-2">
|
<div className="flex p-2 gap-2">
|
||||||
<Tabs
|
<Tabs
|
||||||
size="sm"
|
size="sm"
|
||||||
color={`${tab === 'active' ? "primary" : "danger" }`}
|
color={`${tab === 'active' ? 'primary' : 'danger'}`}
|
||||||
selectedKey={tab}
|
selectedKey={tab}
|
||||||
variant="underlined"
|
variant="underlined"
|
||||||
className="w-fit h-[32px]"
|
className="w-fit h-[32px]"
|
||||||
@ -190,12 +192,12 @@ const Connections: React.FC = () => {
|
|||||||
key="active"
|
key="active"
|
||||||
title={
|
title={
|
||||||
<Badge
|
<Badge
|
||||||
color={`${tab === 'active' ? "primary" : "default"}`}
|
color={`${tab === 'active' ? 'primary' : 'default'}`}
|
||||||
size="sm"
|
size="sm"
|
||||||
shape="circle"
|
shape="circle"
|
||||||
variant="flat"
|
variant="flat"
|
||||||
content={activeConnections.length}
|
content={activeConnections.length}
|
||||||
showOutline={false}
|
showOutline={false}
|
||||||
>
|
>
|
||||||
<span className="p-1">活动中</span>
|
<span className="p-1">活动中</span>
|
||||||
</Badge>
|
</Badge>
|
||||||
@ -205,12 +207,12 @@ const Connections: React.FC = () => {
|
|||||||
key="closed"
|
key="closed"
|
||||||
title={
|
title={
|
||||||
<Badge
|
<Badge
|
||||||
color={`${tab === 'closed' ? "danger" : "default"}`}
|
color={`${tab === 'closed' ? 'danger' : 'default'}`}
|
||||||
size="sm"
|
size="sm"
|
||||||
shape="circle"
|
shape="circle"
|
||||||
variant="flat"
|
variant="flat"
|
||||||
content={closedConnections.length}
|
content={closedConnections.length}
|
||||||
showOutline={false}
|
showOutline={false}
|
||||||
>
|
>
|
||||||
<span className="p-1">已关闭</span>
|
<span className="p-1">已关闭</span>
|
||||||
</Badge>
|
</Badge>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user