Skip to content

Commit

Permalink
fix: connection page NaN and first enter animation
Browse files Browse the repository at this point in the history
  • Loading branch information
greenhat616 committed Apr 2, 2024
1 parent 08a5319 commit 20e3897
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 17 deletions.
14 changes: 7 additions & 7 deletions src/components/connection/connection-table.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import parseTraffic from "@/utils/parse-traffic";
import { truncateStr } from "@/utils/truncate-str";
import { DataGrid, GridColDef } from "@mui/x-data-grid";
import dayjs from "dayjs";
import { useMemo, useState } from "react";
import { DataGrid, GridColDef } from "@mui/x-data-grid";
import { truncateStr } from "@/utils/truncate-str";
import parseTraffic from "@/utils/parse-traffic";

interface Props {
connections: IConnectionsItem[];
Expand All @@ -24,31 +24,31 @@ export const ConnectionTable = (props: Props) => {
width: 88,
align: "right",
headerAlign: "right",
valueFormatter: ({ value }) => parseTraffic(value).join(" "),
valueFormatter: (value) => parseTraffic(value).join(" "),
},
{
field: "upload",
headerName: "Upload",
width: 88,
align: "right",
headerAlign: "right",
valueFormatter: ({ value }) => parseTraffic(value).join(" "),
valueFormatter: (value) => parseTraffic(value).join(" "),
},
{
field: "dlSpeed",
headerName: "DL Speed",
width: 88,
align: "right",
headerAlign: "right",
valueFormatter: ({ value }) => parseTraffic(value).join(" ") + "/s",
valueFormatter: (value) => parseTraffic(value).join(" ") + "/s",
},
{
field: "ulSpeed",
headerName: "UL Speed",
width: 88,
align: "right",
headerAlign: "right",
valueFormatter: ({ value }) => parseTraffic(value).join(" ") + "/s",
valueFormatter: (value) => parseTraffic(value).join(" ") + "/s",
},
{ field: "chains", headerName: "Chains", flex: 360, minWidth: 360 },
{ field: "rule", headerName: "Rule", flex: 300, minWidth: 250 },
Expand Down
3 changes: 1 addition & 2 deletions src/components/log/log-item.module.scss.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import globalClassNames from "../../style.d";
declare const classNames: typeof globalClassNames & {
declare const classNames: {
readonly item: "item";
readonly shiki: "shiki";
readonly dark: "dark";
Expand Down
3 changes: 1 addition & 2 deletions src/components/proxy/proxy-group.module.scss.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import globalClassNames from "../../style.d";
declare const classNames: typeof globalClassNames & {
declare const classNames: {
readonly proxyVirtuoso: "proxyVirtuoso";
};
export = classNames;
2 changes: 1 addition & 1 deletion src/pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ export default function App() {

<div className="drag-mask" data-windrag />

<AnimatePresence mode="wait">
<AnimatePresence mode="wait" initial={false}>
{/* {React.cloneElement(routes, { key: location.pathname })} */}
<PageTransition />
</AnimatePresence>
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import globalClassNames from "../style.d";
declare const classNames: typeof globalClassNames & {
declare const classNames: {
readonly TopPanelPaper: "TopPanelPaper";
readonly label: "label";
readonly value: "value";
Expand Down
2 changes: 1 addition & 1 deletion src/pages/connections.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import { useEffect, useMemo, useRef, useState } from "react";
import { useTranslation } from "react-i18next";
import { Virtuoso } from "react-virtuoso";
import { useRecoilState } from "recoil";
import styles from "./connections..module.scss";
import styles from "./connections.module.scss";

const initConn = { uploadTotal: 0, downloadTotal: 0, connections: [] };

Expand Down
9 changes: 7 additions & 2 deletions src/utils/parse-traffic.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
const UNITS = ["B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"];

const parseTraffic = (num?: number) => {
if (typeof num !== "number") return ["NaN", ""];
const parseTraffic = (num?: string | number) => {
if (typeof num !== "number") {
const tmp = Number(num);
if (isNaN(tmp)) return ["NaN", ""];
num = tmp;
}

if (num < 1000) return [`${Math.round(num)}`, "B"];
const exp = Math.min(Math.floor(Math.log2(num) / 10), UNITS.length - 1);
const dat = num / Math.pow(1024, exp);
Expand Down

0 comments on commit 20e3897

Please sign in to comment.