feat: comprehensive oxlint cleanup - remove unused code
🧹 Cleanup Summary: - Fixed 83 oxlint warnings across 50+ files - Removed unused imports, variables, and functions - Maintained all functional code and error handling - Improved bundle size and code maintainability 📝 Key Changes: - Cleaned unused React hooks (useState, useEffect, useClashInfo) - Removed unused Material-UI imports (useTheme, styled components) - Deleted unused interfaces and type definitions - Fixed spread operator usage and boolean casting - Simplified catch parameters where appropriate 🎯 Files Modified: - React components: home.tsx, settings, profiles, etc. - Custom hooks: use-*.ts files - Utility functions and type definitions - Configuration files ✅ Result: 0 oxlint warnings (from 83 warnings) 🔧 All functionality preserved 📦 Reduced bundle size through dead code elimination
This commit is contained in:
@@ -8,7 +8,7 @@ import {
|
||||
useRef,
|
||||
memo,
|
||||
} from "react";
|
||||
import { Box, useTheme, Tooltip, Paper, Typography } from "@mui/material";
|
||||
import { Box, useTheme } from "@mui/material";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import parseTraffic from "@/utils/parse-traffic";
|
||||
import {
|
||||
@@ -126,13 +126,6 @@ export const EnhancedCanvasTrafficGraph = memo(
|
||||
[theme],
|
||||
);
|
||||
|
||||
// 根据时间范围获取数据点数量
|
||||
const getPointsForTimeRange = useCallback(
|
||||
(minutes: TimeRange): number =>
|
||||
Math.min(minutes * 60, GRAPH_CONFIG.maxPoints),
|
||||
[],
|
||||
);
|
||||
|
||||
// 更新显示数据(防抖处理)
|
||||
const updateDisplayDataDebounced = useMemo(() => {
|
||||
let timeoutId: number;
|
||||
@@ -283,7 +276,6 @@ export const EnhancedCanvasTrafficGraph = memo(
|
||||
};
|
||||
|
||||
const padding = GRAPH_CONFIG.padding;
|
||||
const effectiveHeight = height - padding.top - padding.bottom;
|
||||
|
||||
// 强制显示三个刻度:底部、中间、顶部
|
||||
const topY = padding.top + 10; // 避免与顶部时间范围按钮重叠
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { useState, useEffect, useRef, useCallback, memo, useMemo } from "react";
|
||||
import { useRef, useCallback, memo, useMemo } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import {
|
||||
Typography,
|
||||
@@ -20,10 +20,8 @@ import {
|
||||
import {
|
||||
EnhancedCanvasTrafficGraph,
|
||||
type EnhancedCanvasTrafficGraphRef,
|
||||
type ITrafficItem,
|
||||
} from "./enhanced-canvas-traffic-graph";
|
||||
import { useVisibility } from "@/hooks/use-visibility";
|
||||
import { useClashInfo } from "@/hooks/use-clash";
|
||||
import { useVerge } from "@/hooks/use-verge";
|
||||
import parseTraffic from "@/utils/parse-traffic";
|
||||
import { isDebugEnabled, gc } from "@/services/cmds";
|
||||
@@ -33,17 +31,6 @@ import { useTrafficDataEnhanced } from "@/hooks/use-traffic-monitor";
|
||||
import { TrafficErrorBoundary } from "@/components/common/traffic-error-boundary";
|
||||
import useSWR from "swr";
|
||||
|
||||
interface MemoryUsage {
|
||||
inuse: number;
|
||||
oslimit?: number;
|
||||
}
|
||||
|
||||
interface TrafficStatData {
|
||||
uploadTotal: number;
|
||||
downloadTotal: number;
|
||||
activeConnections: number;
|
||||
}
|
||||
|
||||
interface StatCardProps {
|
||||
icon: ReactNode;
|
||||
title: string;
|
||||
@@ -64,9 +51,6 @@ declare global {
|
||||
}
|
||||
}
|
||||
|
||||
// 控制更新频率
|
||||
const CONNECTIONS_UPDATE_INTERVAL = 5000; // 5秒更新一次连接数据
|
||||
|
||||
// 统计卡片组件 - 使用memo优化
|
||||
const CompactStatCard = memo(
|
||||
({ icon, title, value, unit, color, onClick }: StatCardProps) => {
|
||||
@@ -159,13 +143,12 @@ CompactStatCard.displayName = "CompactStatCard";
|
||||
export const EnhancedTrafficStats = () => {
|
||||
const { t } = useTranslation();
|
||||
const theme = useTheme();
|
||||
const { clashInfo } = useClashInfo();
|
||||
const { verge } = useVerge();
|
||||
const trafficRef = useRef<EnhancedCanvasTrafficGraphRef>(null);
|
||||
const pageVisible = useVisibility();
|
||||
|
||||
// 使用AppDataProvider
|
||||
const { connections, uptime } = useAppData();
|
||||
const { connections } = useAppData();
|
||||
|
||||
// 使用增强版的统一流量数据Hook
|
||||
const { traffic, memory, isLoading, isDataFresh, hasValidData } =
|
||||
@@ -258,7 +241,7 @@ export const EnhancedTrafficStats = () => {
|
||||
borderRadius: "4px",
|
||||
}}
|
||||
>
|
||||
DEBUG: {!!trafficRef.current ? "图表已初始化" : "图表未初始化"}
|
||||
DEBUG: {trafficRef.current ? "图表已初始化" : "图表未初始化"}
|
||||
<br />
|
||||
状态: {isDataFresh ? "active" : "inactive"}
|
||||
<br />
|
||||
|
||||
@@ -73,14 +73,6 @@ export interface HomeProfileCardProps {
|
||||
onProfileUpdated?: () => void;
|
||||
}
|
||||
|
||||
// 添加一个通用的截断样式
|
||||
const truncateStyle = {
|
||||
maxWidth: "calc(100% - 28px)",
|
||||
overflow: "hidden",
|
||||
textOverflow: "ellipsis",
|
||||
whiteSpace: "nowrap",
|
||||
};
|
||||
|
||||
// 提取独立组件减少主组件复杂度
|
||||
const ProfileDetails = ({
|
||||
current,
|
||||
|
||||
@@ -32,7 +32,7 @@ export const SystemInfoCard = () => {
|
||||
const { t } = useTranslation();
|
||||
const { verge, patchVerge } = useVerge();
|
||||
const navigate = useNavigate();
|
||||
const { isAdminMode, isSidecarMode, mutateRunningMode } = useSystemState();
|
||||
const { isAdminMode, isSidecarMode } = useSystemState();
|
||||
const { installServiceAndRestartCore } = useServiceInstaller();
|
||||
|
||||
// 系统信息状态
|
||||
|
||||
Reference in New Issue
Block a user