feat: add Connections Info to ConnectionsPage

*Add Upload Traffic, Download Traffic and Active Connections to ConnectionsPage.
*IConnections uploadTotal and downloadTotal data missing not displayed, add it to ConnectionsPage interface here.
This commit is contained in:
keiko233 2023-10-10 17:05:31 +08:00
parent 9ef7310fc2
commit c8cf179ed9
3 changed files with 53 additions and 2 deletions

View File

@ -7,6 +7,9 @@
"Label-Settings": "Settings", "Label-Settings": "Settings",
"Connections": "Connections", "Connections": "Connections",
"Upload Total": "Upload Total",
"Download Total": "Download Total",
"Active Connections": "Active Connections",
"Logs": "Logs", "Logs": "Logs",
"Clear": "Clear", "Clear": "Clear",
"Proxies": "Proxies", "Proxies": "Proxies",

View File

@ -7,6 +7,9 @@
"Label-Settings": "设 置", "Label-Settings": "设 置",
"Connections": "连接", "Connections": "连接",
"Upload Total": "上传总量",
"Download Total": "下载总量",
"Active Connections": "活动连接",
"Logs": "日志", "Logs": "日志",
"Clear": "清除", "Clear": "清除",
"Proxies": "代理", "Proxies": "代理",

View File

@ -3,16 +3,24 @@ import { useLockFn } from "ahooks";
import { import {
Box, Box,
Button, Button,
Grid,
IconButton, IconButton,
MenuItem, MenuItem,
Paper, Paper,
Select, Select,
TextField, TextField,
Typography,
} from "@mui/material"; } from "@mui/material";
import { useRecoilState } from "recoil"; import { useRecoilState } from "recoil";
import { Virtuoso } from "react-virtuoso"; import { Virtuoso } from "react-virtuoso";
import { useTranslation } from "react-i18next"; import { useTranslation } from "react-i18next";
import { TableChartRounded, TableRowsRounded } from "@mui/icons-material"; import {
ArrowDownward,
ArrowUpward,
Link,
TableChartRounded,
TableRowsRounded,
} from "@mui/icons-material";
import { closeAllConnections } from "@/services/api"; import { closeAllConnections } from "@/services/api";
import { atomConnectionSetting } from "@/services/states"; import { atomConnectionSetting } from "@/services/states";
import { useClashInfo } from "@/hooks/use-clash"; import { useClashInfo } from "@/hooks/use-clash";
@ -24,6 +32,7 @@ import {
ConnectionDetail, ConnectionDetail,
ConnectionDetailRef, ConnectionDetailRef,
} from "@/components/connection/connection-detail"; } from "@/components/connection/connection-detail";
import parseTraffic from "@/utils/parse-traffic";
const initConn = { uploadTotal: 0, downloadTotal: 0, connections: [] }; const initConn = { uploadTotal: 0, downloadTotal: 0, connections: [] };
@ -48,6 +57,10 @@ const ConnectionsPage = () => {
list.sort((a, b) => b.curDownload! - a.curDownload!), list.sort((a, b) => b.curDownload! - a.curDownload!),
}; };
const uploadTotal = connData.uploadTotal;
const downloadTotal = connData.downloadTotal;
const filterConn = useMemo(() => { const filterConn = useMemo(() => {
const orderFunc = orderOpts[curOrderOpt]; const orderFunc = orderOpts[curOrderOpt];
const connections = connData.connections.filter((conn) => const connections = connData.connections.filter((conn) =>
@ -112,6 +125,24 @@ const ConnectionsPage = () => {
const detailRef = useRef<ConnectionDetailRef>(null!); const detailRef = useRef<ConnectionDetailRef>(null!);
const connectionItems = [
{
icon: <ArrowUpward />,
label: t("Upload Total"),
value: parseTraffic(uploadTotal).join(" "),
},
{
icon: <ArrowDownward />,
label: t("Download Total"),
value: parseTraffic(downloadTotal).join(" "),
},
{
icon: <Link />,
label: t("Active Connections"),
value: filterConn.length,
},
];
return ( return (
<BasePage <BasePage
title={t("Connections")} title={t("Connections")}
@ -142,7 +173,21 @@ const ConnectionsPage = () => {
</Box> </Box>
} }
> >
<Paper sx={{ boxShadow: 2, height: "100%" }}> <Paper sx={{ padding: 2, mb: 2 }}>
<Grid container>
{connectionItems.map((item, index) => (
<Grid item xs={4} key={index}>
<Box display="flex" alignItems="center" whiteSpace="nowrap">
{item.icon}
<Typography sx={{ ml: 1, mr: 1 }}>{item.label}</Typography>
<Typography>{item.value}</Typography>
</Box>
</Grid>
))}
</Grid>
</Paper>
<Paper sx={{ boxShadow: 2, height: "calc(100% - 56px - 16px)" }}>
<Box <Box
sx={{ sx={{
pt: 1, pt: 1,