Skip to content

A modern and elegant dashboard for network traffic visualization and analysis.

feat: Implement skeleton loading, add domain preview with copy functionality, and refine WebSocket data handling for tables.

luoleifc18e468d38d
diff --git a/README.en.md b/README.en.md
index c068fc2..f190aa0 100644
--- a/README.en.md
+++ b/README.en.md
@@ -5,8 +5,8 @@
</p>
<p align="center">
- <b>A more beautiful and modern web application that lets you visualize and manage your Clash network traffic</b><br>
- <span>Real-time Monitoring · Multi-dimensional Analysis · Multi-Backend Management</span>
+ <b>Modern network visualization dashboard</b><br>
+ <span>Real-time Monitoring · Traffic Audit · Multi-Gateway Management</span>
</p>
<p align="center">
@@ -22,6 +22,15 @@
<b>English</b>
</p>
+> [!IMPORTANT]
+> **Disclaimer**
+>
+> This project is a **Network Traffic Visualization & Analysis Tool** designed to visualize connection states and traffic flows of local network devices.
+>
+> This project **does NOT provide** any internet access services, proxy subscriptions, or cross-network connectivity features. All data is derived from the user's own network gateway; this project solely performs data collection and visualization.
+>
+> This project is open-source under the MIT License. The developers assume no responsibility for any consequences resulting from the use of this software.
+
![Clash Master Overview](./assets/clash-master-overview.png)
![Clash Master Rules](./assets/clash-master-rules.png)
![Clash Master Regions](./assets/clash-master-regions.png)
@@ -172,16 +181,16 @@ Open <http://localhost:3000> to configure.
![First Use](./assets/clash-master-setup.png)
1. Open <http://localhost:3000>
-2. The **Backend Configuration** dialog will appear on first visit
-3. Fill in your OpenClash connection info:
- - **Name**: Custom name (e.g., "Home")
- - **Host**: OpenClash backend address (e.g., `192.168.101.1`)
- - **Port**: OpenClash backend port (e.g., `9090`)
+2. The **Gateway Configuration** dialog will appear on first visit
+3. Fill in your network gateway (e.g., OpenClash) connection info:
+ - **Name**: Custom name (e.g., "Home Gateway")
+ - **Host**: Gateway backend address (e.g., `192.168.101.1`)
+ - **Port**: Gateway backend port (e.g., `9090`)
- **Token**: Fill if Secret is configured, otherwise leave empty
4. Click "Add Backend" to save
-5. The system will automatically start collecting data
+5. The system will automatically start collecting and analyzing traffic data
-> 💡 **Get OpenClash Address**: OpenClash Plugin → Enable "External Control" → Copy address
+> 💡 **Get Gateway Address**: Go to your gateway control panel (e.g., OpenClash) → Enable "External Control" → Copy API address
## 🔧 Port Conflict Resolution
diff --git a/README.md b/README.md
index 6f2e830..0632c66 100644
--- a/README.md
+++ b/README.md
@@ -5,8 +5,8 @@
</p>
<p align="center">
- <b>优雅且现代化的 OpenClash 流量可视化分析工具</b><br>
- <span>实时监控 · 多维度分析 · 多后端管理</span>
+ <b>优雅且现代化的网络可视化分析面板</b><br>
+ <span>实时监控 · 流量审计 · 多网关管理</span>
</p>
<p align="center">
@@ -22,6 +22,15 @@
<a href="./README.en.md">English</a>
</p>
+> [!IMPORTANT]
+> **免责声明 / Disclaimer**
+>
+> 本项目仅为 **网络流量可视化与分析工具**,旨在帮助用户通过可视化仪表盘 (Dashboard) 审计本地网络流量、发现异常连接请求、优化网络配置。
+>
+> 本项目 **不提供** 任何网络接入服务、代理节点订阅或跨网络连接功能。所有数据均来源于用户自有的网络网关,数据采集仅在用户本地网络内进行。
+>
+> 本项目遵循 MIT 协议开源,不对因使用本软件产生的任何后果承担责任。请在合规范围内使用。
+
![Clash Master Overview](./assets/clash-master-overview.png)
![Clash Master Rules](./assets/clash-master-rules.png)
![Clash Master Regions](./assets/clash-master-regions.png)
@@ -71,8 +80,8 @@ services:
container_name: clash-master
restart: unless-stopped
ports:
- - "3000:3000" # Web UI
- - "3002:3002" # WebSocket(供 Nginx / Tunnel 转发)
+ - "3000:3000" # Web UI
+ - "3002:3002" # WebSocket(供 Nginx / Tunnel 转发)
volumes:
- ./data:/app/data
environment:
@@ -157,16 +166,16 @@ pnpm dev
![首次使用](./assets/clash-master-setup.png)
1. 打开 <http://localhost:3000>
-2. 首次访问会弹出**后端配置**对话框
-3. 填写 OpenClash 连接信息:
- - **名称**: 自定义名称(如 "Home")
- - **地址**: OpenClash 后端地址(如 `192.168.101.1`)
- - **端口**: OpenClash 后端端口(如 `9090`)
+2. 首次访问会弹出**网关配置**对话框
+3. 填写网络网关(如 OpenClash)连接信息:
+ - **名称**: 自定义名称(如 "Home Gateway")
+ - **地址**: 网关后端地址(如 `192.168.101.1`)
+ - **端口**: 网关后端端口(如 `9090`)
- **Token**: 如果配置了 Secret 则填写,否则留空
4. 点击「添加后端」保存配置
-5. 系统将自动开始采集数据
+5. 系统将自动开始采集并分析流量数据
-> 💡 **获取 OpenClash 地址**: 进入 OpenClash 插件 → 打开「外部控制」→ 复制地址
+> 💡 **获取网关地址**: 进入网关控制面板(如 OpenClash) → 打开「外部控制」→ 复制 API 地址
## 🔧 端口冲突解决
@@ -213,25 +222,25 @@ curl -fsSL https://raw.githubusercontent.com/foru17/clash-master/main/setup.sh |
### 端口说明
-| 端口 | 用途 | 外部必需 | 说明 |
-| :--: | :-------: | :------: | :--- |
-| 3000 | Web 界面 | ✅ | 前端访问入口 |
-| 3001 | API 接口 | 可选 | 前端默认同域 `/api`,一般无需暴露 |
+| 端口 | 用途 | 外部必需 | 说明 |
+| :--: | :-------: | :------: | :----------------------------------------------- |
+| 3000 | Web 界面 | ✅ | 前端访问入口 |
+| 3001 | API 接口 | 可选 | 前端默认同域 `/api`,一般无需暴露 |
| 3002 | WebSocket | 可选 | 实时推送端口,建议仅给反代层转发,不直接公网暴露 |
### 环境变量说明(Docker)
-| 变量名 | 默认值 | 作用 | 何时设置 |
-| :-- | :-- | :-- | :-- |
-| `WEB_PORT` | `3000` | 前端服务监听端口(容器内) | 一般不用改 |
-| `API_PORT` | `3001` | API 服务监听端口(容器内) | 一般不用改 |
-| `COLLECTOR_WS_PORT` | `3002` | WS 服务监听端口(容器内) | 一般不用改 |
-| `DB_PATH` | `/app/data/stats.db` | SQLite 数据文件路径 | 自定义数据目录时 |
-| `WEB_EXTERNAL_PORT` | `3000` | 运行时注入给前端显示/拼接用的外部 Web 端口 | 外部映射端口变更时 |
-| `API_EXTERNAL_PORT` | `3001` | 运行时注入给前端的 API 外部端口 | 仅直连 API 时 |
-| `WS_EXTERNAL_PORT` | `3002` | 运行时注入给前端的 WS 外部端口 | 仅直连 WS 时 |
-| `NEXT_PUBLIC_API_URL` | 空 | 强制前端 API 基地址(覆盖默认 `/api`) | API 不走同域时 |
-| `NEXT_PUBLIC_WS_URL` | 自动 `/_cm_ws` | 自定义前端 WS 地址(覆盖默认) | 仅在你想改默认路径/域名时 |
+| 变量名 | 默认值 | 作用 | 何时设置 |
+| :-------------------- | :------------------- | :----------------------------------------- | :------------------------ |
+| `WEB_PORT` | `3000` | 前端服务监听端口(容器内) | 一般不用改 |
+| `API_PORT` | `3001` | API 服务监听端口(容器内) | 一般不用改 |
+| `COLLECTOR_WS_PORT` | `3002` | WS 服务监听端口(容器内) | 一般不用改 |
+| `DB_PATH` | `/app/data/stats.db` | SQLite 数据文件路径 | 自定义数据目录时 |
+| `WEB_EXTERNAL_PORT` | `3000` | 运行时注入给前端显示/拼接用的外部 Web 端口 | 外部映射端口变更时 |
+| `API_EXTERNAL_PORT` | `3001` | 运行时注入给前端的 API 外部端口 | 仅直连 API 时 |
+| `WS_EXTERNAL_PORT` | `3002` | 运行时注入给前端的 WS 外部端口 | 仅直连 WS 时 |
+| `NEXT_PUBLIC_API_URL` | 空 | 强制前端 API 基地址(覆盖默认 `/api`) | API 不走同域时 |
+| `NEXT_PUBLIC_WS_URL` | 自动 `/_cm_ws` | 自定义前端 WS 地址(覆盖默认) | 仅在你想改默认路径/域名时 |
### API / WS 地址解析优先级
diff --git a/apps/web/app/[locale]/layout.tsx b/apps/web/app/[locale]/layout.tsx
index 136787d..ef78ef5 100644
--- a/apps/web/app/[locale]/layout.tsx
+++ b/apps/web/app/[locale]/layout.tsx
@@ -22,7 +22,7 @@ const geistMono = Geist_Mono({
export const metadata: Metadata = {
title: "Clash Master",
- description: "Modern and beautiful traffic analysis dashboard for Clash",
+ description: "Modern and beautiful network traffic analysis dashboard",
icons: {
icon: "/clash-master.png",
shortcut: "/clash-master.png",
diff --git a/apps/web/app/[locale]/page.tsx b/apps/web/app/[locale]/page.tsx
index 9ce5c67..ee337ed 100644
--- a/apps/web/app/[locale]/page.tsx
+++ b/apps/web/app/[locale]/page.tsx
@@ -3,7 +3,11 @@
import { useEffect, useState, useCallback, memo, useMemo } from "react";
import { useTranslations, useLocale } from "next-intl";
import { useTheme } from "next-themes";
-import { keepPreviousData, useQuery, useQueryClient } from "@tanstack/react-query";
+import {
+ keepPreviousData,
+ useQuery,
+ useQueryClient,
+} from "@tanstack/react-query";
import {
Globe,
MapPin,
@@ -47,6 +51,7 @@ import { Button } from "@/components/ui/button";
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs";
import { Badge } from "@/components/ui/badge";
+import { InsightThreePanelSkeleton } from "@/components/ui/insight-skeleton";
import {
DropdownMenu,
DropdownMenuContent,
@@ -67,11 +72,7 @@ import {
PopoverContent,
PopoverTrigger,
} from "@/components/ui/popover";
-import {
- api,
- getPresetTimeRange,
- type TimeRange,
-} from "@/lib/api";
+import { api, getPresetTimeRange, type TimeRange } from "@/lib/api";
import {
getCountriesQueryKey,
getDevicesQueryKey,
@@ -109,7 +110,16 @@ const NAV_ITEMS = [
{ id: "rules", label: "rules" },
];
-type TimePreset = "1m" | "5m" | "15m" | "30m" | "24h" | "7d" | "30d" | "today" | "custom";
+type TimePreset =
+ | "1m"
+ | "5m"
+ | "15m"
+ | "30m"
+ | "24h"
+ | "7d"
+ | "30d"
+ | "today"
+ | "custom";
type RollingTimePreset = Exclude<TimePreset, "custom">;
type BackendStatus = "healthy" | "unhealthy" | "unknown";
const SUMMARY_WS_MIN_PUSH_MS = 3000;
@@ -168,6 +178,7 @@ const DomainsContent = memo(function DomainsContent({
autoRefresh: boolean;
}) {
const t = useTranslations("domains");
+ const [sharedPageSize, setSharedPageSize] = useState<10 | 20 | 50 | 100>(10);
return (
<div className="space-y-6">
<TopDomainsChart
@@ -184,6 +195,8 @@ const DomainsContent = memo(function DomainsContent({
activeBackendId={activeBackendId}
timeRange={timeRange}
autoRefresh={autoRefresh}
+ pageSize={sharedPageSize}
+ onPageSizeChange={setSharedPageSize}
/>
</TabsContent>
<TabsContent value="ips" className="overflow-hidden">
@@ -191,6 +204,8 @@ const DomainsContent = memo(function DomainsContent({
activeBackendId={activeBackendId}
timeRange={timeRange}
autoRefresh={autoRefresh}
+ pageSize={sharedPageSize}
+ onPageSizeChange={setSharedPageSize}
/>
</TabsContent>
</Tabs>
@@ -226,8 +241,7 @@ const CountriesContent = memo(function CountriesContent({
)}
onClick={() => setSortBy("traffic")}
title={t("sortByTraffic")}
- aria-label={t("sortByTraffic")}
- >
+ aria-label={t("sortByTraffic")}>
<BarChart3 className="w-4 h-4" />
</Button>
<Button
@@ -241,8 +255,7 @@ const CountriesContent = memo(function CountriesContent({
)}
onClick={() => setSortBy("connections")}
title={t("sortByConnections")}
- aria-label={t("sortByConnections")}
- >
+ aria-label={t("sortByConnections")}>
<Link2 className="w-4 h-4" />
</Button>
</div>
@@ -332,9 +345,11 @@ const DevicesContent = memo(function DevicesContent({
if (loading) {
return (
- <div className="flex items-center justify-center p-12">
- <RefreshCw className="w-6 h-6 animate-spin text-muted-foreground" />
- </div>
+ <Card>
+ <CardContent className="p-5 sm:p-6">
+ <InsightThreePanelSkeleton />
+ </CardContent>
+ </Card>
);
}
@@ -373,7 +388,9 @@ export default function DashboardPage() {
const { theme, setTheme } = useTheme();
const queryClient = useQueryClient();
const [activeTab, setActiveTab] = useState("overview");
- const [timeRange, setTimeRange] = useState<TimeRange>(getPresetTimeRange("24h"));
+ const [timeRange, setTimeRange] = useState<TimeRange>(
+ getPresetTimeRange("24h"),
+ );
const [timePreset, setTimePreset] = useState<TimePreset>("24h");
const [isManualRefreshing, setIsManualRefreshing] = useState(false);
const [autoRefresh, setAutoRefresh] = useState(true);
@@ -383,9 +400,7 @@ export default function DashboardPage() {
const [showAboutDialog, setShowAboutDialog] = useState(false);
const stableTimeRange = useStableTimeRange(timeRange);
- const isWsSummaryTab =
- activeTab === "overview" ||
- activeTab === "countries";
+ const isWsSummaryTab = activeTab === "overview" || activeTab === "countries";
const backendsQuery = useQuery({
queryKey: ["backends"],
@@ -412,29 +427,32 @@ export default function DashboardPage() {
range: stableTimeRange,
minPushIntervalMs: SUMMARY_WS_MIN_PUSH_MS,
enabled: wsEnabled,
- onMessage: useCallback((stats: StatsSummary) => {
- if (!activeBackendId) return;
- setAutoRefreshTick((tick) => tick + 1);
- queryClient.setQueryData(
- getSummaryQueryKey(activeBackendId, stableTimeRange),
- (previous) => ({
- ...(typeof previous === "object" && previous ? previous : {}),
- ...stats,
- }),
- );
- if (stats.countryStats) {
+ onMessage: useCallback(
+ (stats: StatsSummary) => {
+ if (!activeBackendId) return;
+ setAutoRefreshTick((tick) => tick + 1);
queryClient.setQueryData(
- getCountriesQueryKey(activeBackendId, 50, stableTimeRange),
- stats.countryStats,
+ getSummaryQueryKey(activeBackendId, stableTimeRange),
+ (previous) => ({
+ ...(typeof previous === "object" && previous ? previous : {}),
+ ...stats,
+ }),
);
- }
- if (stats.deviceStats) {
- queryClient.setQueryData(
- getDevicesQueryKey(activeBackendId, 50, stableTimeRange),
- stats.deviceStats,
- );
- }
- }, [activeBackendId, queryClient, stableTimeRange]),
+ if (stats.countryStats) {
+ queryClient.setQueryData(
+ getCountriesQueryKey(activeBackendId, 50, stableTimeRange),
+ stats.countryStats,
+ );
+ }
+ if (stats.deviceStats) {
+ queryClient.setQueryData(
+ getDevicesQueryKey(activeBackendId, 50, stableTimeRange),
+ stats.deviceStats,
+ );
+ }
+ },
+ [activeBackendId, queryClient, stableTimeRange],
+ ),
});
const wsConnected = wsStatus === "connected";
const wsRealtimeActive = wsEnabled && wsConnected;
@@ -493,7 +511,8 @@ export default function DashboardPage() {
const backendStatusHint = useMemo(() => {
if (effectiveSummaryError) return effectiveSummaryError;
- if (activeBackend && !activeBackend.listening) return dashboardT("backendUnavailableHint");
+ if (activeBackend && !activeBackend.listening)
+ return dashboardT("backendUnavailableHint");
return null;
}, [effectiveSummaryError, activeBackend, dashboardT]);
@@ -556,7 +575,13 @@ export default function DashboardPage() {
if (isFirstTime) {
setIsFirstTime(false);
}
- }, [backends.length, backendsQuery.isError, backendsQuery.isFetching, backendsQuery.isLoading, isFirstTime]);
+ }, [
+ backends.length,
+ backendsQuery.isError,
+ backendsQuery.isFetching,
+ backendsQuery.isLoading,
+ isFirstTime,
+ ]);
// Rolling presets: keep the time window moving.
// Only reduce to 30s on lightweight WS tabs (overview/countries).
@@ -573,7 +598,8 @@ export default function DashboardPage() {
// Fixed presets: keep HTTP polling only when WS realtime is not active.
useEffect(() => {
- if (!autoRefresh || isRollingTimePreset(timePreset) || wsRealtimeActive) return;
+ if (!autoRefresh || isRollingTimePreset(timePreset) || wsRealtimeActive)
+ return;
const intervalMs = 5000;
const interval = setInterval(() => {
setAutoRefreshTick((tick) => tick + 1);
@@ -774,7 +800,11 @@ export default function DashboardPage() {
variant="ghost"
size="icon"
onClick={() => setAutoRefresh((prev) => !prev)}
- aria-label={autoRefresh ? dashboardT("autoRefresh") : dashboardT("paused")}
+ aria-label={
+ autoRefresh
+ ? dashboardT("autoRefresh")
+ : dashboardT("paused")
+ }
className={cn(
"h-9 w-9 rounded-full transition-colors",
autoRefresh
@@ -799,10 +829,14 @@ export default function DashboardPage() {
</TooltipTrigger>
<TooltipContent side="bottom">
<p className="font-medium">
- {autoRefresh ? dashboardT("autoRefresh") : dashboardT("paused")}
+ {autoRefresh
+ ? dashboardT("autoRefresh")
+ : dashboardT("paused")}
</p>
<p className="opacity-80">
- {autoRefresh ? dashboardT("clickToPause") : dashboardT("clickToResume")}
+ {autoRefresh
+ ? dashboardT("clickToPause")
+ : dashboardT("clickToResume")}
</p>
</TooltipContent>
</Tooltip>
@@ -837,8 +871,7 @@ export default function DashboardPage() {
size="icon"
variant="ghost"
aria-label={dashboardT("backendUnavailable")}
- className="relative h-9 w-9 text-rose-500 hover:bg-rose-500/10 hover:text-rose-500"
- >
+ className="relative h-9 w-9 text-rose-500 hover:bg-rose-500/10 hover:text-rose-500">
<span className="absolute top-1.5 right-1.5 h-1.5 w-1.5 rounded-full bg-rose-500 animate-ping [animation-duration:900ms]" />
<AlertTriangle className="h-4 w-4" />
</Button>
@@ -846,8 +879,7 @@ export default function DashboardPage() {
<PopoverContent
align="end"
side="bottom"
- className="w-[240px] p-3"
- >
+ className="w-[240px] p-3">
<div className="flex items-start gap-2">
<AlertTriangle className="mt-0.5 h-4 w-4 shrink-0 text-rose-500" />
<div className="min-w-0">
@@ -855,7 +887,8 @@ export default function DashboardPage() {
{dashboardT("backendUnavailable")}
</p>
<p className="text-xs text-muted-foreground">
- {backendStatusHint || dashboardT("backendUnavailableHint")}
+ {backendStatusHint ||
+ dashboardT("backendUnavailableHint")}
</p>
</div>
</div>
diff --git a/apps/web/app/manifest.ts b/apps/web/app/manifest.ts
index f4de692..29b1ad0 100644
--- a/apps/web/app/manifest.ts
+++ b/apps/web/app/manifest.ts
@@ -4,7 +4,7 @@ export default function manifest(): MetadataRoute.Manifest {
return {
name: "Clash Master",
short_name: "Clash Master",
- description: "Modern traffic analysis dashboard for Clash",
+ description: "Modern network traffic analysis dashboard",
start_url: "/",
scope: "/",
display: "standalone",
diff --git a/apps/web/components/domain-preview.tsx b/apps/web/components/domain-preview.tsx
new file mode 100644
index 0000000..1851dba
--- /dev/null
+++ b/apps/web/components/domain-preview.tsx
@@ -0,0 +1,105 @@
+"use client";
+
+import { useState, useEffect, useRef, useCallback, type MouseEvent } from "react";
+import { Check, Copy } from "lucide-react";
+import { CopyToClipboard } from "react-copy-to-clipboard";
+import { Button } from "@/components/ui/button";
+import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover";
+import { cn } from "@/lib/utils";
+
+interface DomainPreviewProps {
+ domain?: string | null;
+ unknownLabel: string;
+ copyLabel: string;
+ copiedLabel: string;
+ className?: string;
+ triggerClassName?: string;
+}
+
+export function DomainPreview({
+ domain,
+ unknownLabel,
+ copyLabel,
+ copiedLabel,
+ className,
+ triggerClassName,
+}: DomainPreviewProps) {
+ const [copied, setCopied] = useState(false);
+ const copiedTimerRef = useRef<ReturnType<typeof setTimeout> | null>(null);
+ const domainText = domain || unknownLabel;
+
+ useEffect(() => {
+ return () => {
+ if (copiedTimerRef.current) clearTimeout(copiedTimerRef.current);
+ };
+ }, []);
+
+ const handleTriggerClick = useCallback((event: MouseEvent<HTMLButtonElement>) => {
+ event.stopPropagation();
+ }, []);
+
+ const handleCopyResult = useCallback((_: string, result: boolean) => {
+ if (result) {
+ setCopied(true);
+ if (copiedTimerRef.current) clearTimeout(copiedTimerRef.current);
+ copiedTimerRef.current = setTimeout(() => setCopied(false), 1200);
+ } else {
+ setCopied(false);
+ }
+ }, []);
+
+ return (
+ <div className={cn("min-w-0", className)} onClick={(event) => event.stopPropagation()}>
+ <Popover>
+ <PopoverTrigger asChild>
+ <button
+ type="button"
+ className={cn(
+ "w-full min-w-0 text-left font-medium truncate text-sm rounded-sm outline-none cursor-pointer underline-offset-4 decoration-dotted decoration-transparent hover:underline hover:decoration-muted-foreground/60 hover:text-foreground/95 focus-visible:ring-2 focus-visible:ring-ring/60",
+ triggerClassName,
+ )}
+ onClick={handleTriggerClick}
+ >
+ {domainText}
+ </button>
+ </PopoverTrigger>
+ <PopoverContent
+ align="start"
+ side="bottom"
+ sideOffset={8}
+ className="w-[min(92vw,30rem)] rounded-lg border-border/50 bg-popover p-2.5 shadow-lg"
+ onClick={(event) => event.stopPropagation()}
+ >
+ <div className="flex items-start gap-2">
+ <code className="min-w-0 flex-1 max-h-28 overflow-auto rounded-md border border-border/50 bg-muted/25 px-2.5 py-2 text-[13px] leading-5 break-all">
+ {domainText}
+ </code>
+ {domain ? (
+ <CopyToClipboard text={domain} onCopy={handleCopyResult}>
+ <Button
+ type="button"
+ size="icon"
+ variant="ghost"
+ title={copied ? copiedLabel : copyLabel}
+ aria-label={copied ? copiedLabel : copyLabel}
+ className={cn(
+ "h-8 w-8 shrink-0 rounded-md border border-border/40",
+ copied
+ ? "text-emerald-600 bg-emerald-500/15 hover:bg-emerald-500/20 dark:text-emerald-400"
+ : "text-muted-foreground hover:text-foreground hover:bg-muted/50",
+ )}
+ onClick={(event) => {
+ event.preventDefault();
+ event.stopPropagation();
+ }}
+ >
+ {copied ? <Check className="h-3.5 w-3.5" /> : <Copy className="h-3.5 w-3.5" />}
+ </Button>
+ </CopyToClipboard>
+ ) : null}
+ </div>
+ </PopoverContent>
+ </Popover>
+ </div>
+ );
+}
diff --git a/apps/web/components/domains-table.tsx b/apps/web/components/domains-table.tsx
index 135c878..5ba9536 100644
--- a/apps/web/components/domains-table.tsx
+++ b/apps/web/components/domains-table.tsx
@@ -1,12 +1,14 @@
"use client";
-import { useState, useEffect, useMemo, useRef, useCallback } from "react";
-import { Search, ArrowUpDown, ArrowDown, ArrowUp, ChevronLeft, ChevronRight, Rows3, ChevronDown, ChevronUp, Server, Loader2 } from "lucide-react";
+import { useState, useEffect, useRef, useCallback } from "react";
+import { Search, ArrowUpDown, ArrowDown, ArrowUp, ChevronLeft, ChevronRight, Rows3, ChevronDown, ChevronUp, Server } from "lucide-react";
import { useTranslations } from "next-intl";
import { keepPreviousData, useQuery } from "@tanstack/react-query";
import { Input } from "@/components/ui/input";
import { Button } from "@/components/ui/button";
+import { InsightTableSkeleton } from "@/components/ui/insight-skeleton";
import { Favicon } from "@/components/favicon";
+import { DomainPreview } from "@/components/domain-preview";
import { DomainExpandedDetails } from "@/components/stats-tables/expanded-details";
import { ProxyChainBadge } from "@/components/proxy-chain-badge";
import { ExpandReveal } from "@/components/ui/expand-reveal";
@@ -32,6 +34,8 @@ interface DomainsTableProps {
activeBackendId?: number;
timeRange?: TimeRange;
autoRefresh?: boolean;
+ pageSize?: PageSize;
+ onPageSizeChange?: (size: PageSize) => void;
}
type SortKey = "domain" | "totalDownload" | "totalUpload" | "totalConnections" | "lastSeen";
@@ -41,8 +45,27 @@ const PAGE_SIZE_OPTIONS = [10, 20, 50, 100] as const;
type PageSize = typeof PAGE_SIZE_OPTIONS[number];
const DETAIL_QUERY_STALE_MS = 30_000;
const DOMAINS_WS_MIN_PUSH_MS = 3_000;
-
-export function DomainsTable({ activeBackendId, timeRange, autoRefresh = true }: DomainsTableProps) {
+type DomainsPageQueryState = {
+ offset: number;
+ limit: number;
+ sortBy?: string;
+ sortOrder?: "asc" | "desc";
+ search?: string;
+};
+type DomainsPageState = {
+ data: DomainStats[];
+ total: number;
+ query: DomainsPageQueryState;
+ backendId?: number;
+};
+
+export function DomainsTable({
+ activeBackendId,
+ timeRange,
+ autoRefresh = true,
+ pageSize: controlledPageSize,
+ onPageSizeChange,
+}: DomainsTableProps) {
const t = useTranslations("domains");
const stableTimeRange = useStableTimeRange(timeRange);
const detailTimeRange = stableTimeRange;
@@ -51,9 +74,17 @@ export function DomainsTable({ activeBackendId, timeRange, autoRefresh = true }:
const [sortKey, setSortKey] = useState<SortKey>("totalDownload");
const [sortOrder, setSortOrder] = useState<SortOrder>("desc");
const [currentPage, setCurrentPage] = useState(1);
- const [pageSize, setPageSize] = useState<PageSize>(10);
+ const [internalPageSize, setInternalPageSize] = useState<PageSize>(10);
+ const pageSize = controlledPageSize ?? internalPageSize;
+ const setEffectivePageSize = useCallback((size: PageSize) => {
+ if (onPageSizeChange) {
+ onPageSizeChange(size);
+ return;
+ }
+ setInternalPageSize(size);
+ }, [onPageSizeChange]);
const [expandedDomain, setExpandedDomain] = useState<string | null>(null);
- const [wsDomainsPage, setWsDomainsPage] = useState<{ data: DomainStats[]; total: number } | null>(null);
+ const [wsDomainsPage, setWsDomainsPage] = useState<DomainsPageState | null>(null);
const debounceRef = useRef<ReturnType<typeof setTimeout> | null>(null);
const pageOffset = (currentPage - 1) * pageSize;
const wsPageSearch = debouncedSearch || undefined;
@@ -75,26 +106,29 @@ export function DomainsTable({ activeBackendId, timeRange, autoRefresh = true }:
const query = stats.domainsPageQuery;
const page = stats.domainsPage;
if (!page || !query) return;
- if (query.offset !== pageOffset || query.limit !== pageSize) return;
- if ((query.sortBy || "totalDownload") !== sortKey) return;
- if ((query.sortOrder || "desc") !== sortOrder) return;
- if ((query.search || undefined) !== wsPageSearch) return;
- setWsDomainsPage(page);
- }, [pageOffset, pageSize, sortKey, sortOrder, wsPageSearch]),
+ setWsDomainsPage({
+ data: page.data,
+ total: page.total,
+ query: {
+ offset: query.offset,
+ limit: query.limit,
+ sortBy: query.sortBy || "totalDownload",
+ sortOrder: query.sortOrder === "asc" ? "asc" : "desc",
+ search: query.search || undefined,
+ },
+ backendId: activeBackendId,
+ });
+ }, [activeBackendId]),
});
- useEffect(() => {
- setWsDomainsPage(null);
- }, [
- activeBackendId,
- stableTimeRange?.start,
- stableTimeRange?.end,
- pageOffset,
- pageSize,
- sortKey,
- sortOrder,
- wsPageSearch,
- ]);
+ const wsDomainsPageMatchesCurrent =
+ wsDomainsPage !== null &&
+ wsDomainsPage.backendId === activeBackendId &&
+ wsDomainsPage.query.offset === pageOffset &&
+ wsDomainsPage.query.limit === pageSize &&
+ (wsDomainsPage.query.sortBy || "totalDownload") === sortKey &&
+ (wsDomainsPage.query.sortOrder || "desc") === sortOrder &&
+ (wsDomainsPage.query.search || undefined) === wsPageSearch;
// Debounce search input
useEffect(() => {
@@ -127,16 +161,17 @@ export function DomainsTable({ activeBackendId, timeRange, autoRefresh = true }:
start: stableTimeRange?.start,
end: stableTimeRange?.end,
}),
- enabled: !!activeBackendId && wsPageStatus !== "connected",
+ enabled:
+ !!activeBackendId &&
+ (!wsPageEnabled || wsPageStatus !== "connected" || !wsDomainsPageMatchesCurrent),
placeholderData: keepPreviousData,
});
- const hasWsDomainsPage = wsPageEnabled && wsPageStatus === "connected" && wsDomainsPage !== null;
- const data = hasWsDomainsPage ? wsDomainsPage.data : domainsQuery.data?.data ?? [];
- const total = hasWsDomainsPage ? wsDomainsPage.total : domainsQuery.data?.total ?? 0;
- const loading =
- (wsPageStatus === "connected" && wsDomainsPage === null) ||
- (!hasWsDomainsPage && domainsQuery.isLoading && !domainsQuery.data);
+ const hasWsDomainsPage =
+ wsPageEnabled && wsPageStatus === "connected" && wsDomainsPageMatchesCurrent;
+ const data = hasWsDomainsPage ? wsDomainsPage!.data : domainsQuery.data?.data ?? [];
+ const total = hasWsDomainsPage ? wsDomainsPage!.total : domainsQuery.data?.total ?? 0;
+ const loading = !hasWsDomainsPage && domainsQuery.isLoading && !domainsQuery.data;
useEffect(() => {
// Backend switch means a different data universe, collapse safely.
@@ -192,7 +227,7 @@ export function DomainsTable({ activeBackendId, timeRange, autoRefresh = true }:
};
const handlePageSizeChange = (size: PageSize) => {
- setPageSize(size);
+ setEffectivePageSize(size);
setCurrentPage(1);
};
@@ -330,9 +365,7 @@ export function DomainsTable({ activeBackendId, timeRange, autoRefresh = true }:
{/* Table Body */}
<div className="divide-y divide-border/30 min-h-[300px]">
{loading && data.length === 0 ? (
- <div className="px-5 py-12 text-center text-muted-foreground">
- <Loader2 className="h-6 w-6 animate-spin mx-auto mb-2" />
- </div>
+ <InsightTableSkeleton />
) : data.length === 0 ? (
<div className="px-5 py-12 text-center text-muted-foreground">
{t("noResults")}
@@ -356,9 +389,12 @@ export function DomainsTable({ activeBackendId, timeRange, autoRefresh = true }:
<div className="col-span-3 flex items-center gap-3 min-w-0">
<Favicon domain={domain.domain} size="sm" className="shrink-0" />
<div className="min-w-0">
- <p className="font-medium truncate text-sm">
- {domain.domain || t("unknown")}
- </p>
+ <DomainPreview
+ domain={domain.domain}
+ unknownLabel={t("unknown")}
+ copyLabel={t("copyDomain")}
+ copiedLabel={t("copied")}
+ />
</div>
</div>
@@ -368,12 +404,12 @@ export function DomainsTable({ activeBackendId, timeRange, autoRefresh = true }:
</div>
{/* Download */}
- <div className="col-span-2 text-right tabular-nums text-sm">
+ <div className="col-span-2 text-right tabular-nums text-sm whitespace-nowrap">
<span className="text-blue-500">{formatBytes(domain.totalDownload)}</span>
</div>
{/* Upload */}
- <div className="col-span-1 text-right tabular-nums text-sm">
+ <div className="col-span-1 text-right tabular-nums text-sm whitespace-nowrap">
<span className="text-purple-500">{formatBytes(domain.totalUpload)}</span>
</div>
@@ -430,9 +466,12 @@ export function DomainsTable({ activeBackendId, timeRange, autoRefresh = true }:
<div className="flex items-center gap-2.5 mb-2">
<Favicon domain={domain.domain} size="sm" className="shrink-0" />
<div className="flex-1 min-w-0">
- <p className="font-medium text-sm truncate">
- {domain.domain || t("unknown")}
- </p>
+ <DomainPreview
+ domain={domain.domain}
+ unknownLabel={t("unknown")}
+ copyLabel={t("copyDomain")}
+ copiedLabel={t("copied")}
+ />
</div>
<Button
variant="ghost"
@@ -463,8 +502,8 @@ export function DomainsTable({ activeBackendId, timeRange, autoRefresh = true }:
{/* Row 3: Traffic stats - compact layout */}
<div className="flex items-center gap-3 text-[11px] pl-[30px]">
- <span className="text-blue-500 tabular-nums">↓ {formatBytes(domain.totalDownload)}</span>
- <span className="text-purple-500 tabular-nums">↑ {formatBytes(domain.totalUpload)}</span>
+ <span className="text-blue-500 tabular-nums whitespace-nowrap">↓ {formatBytes(domain.totalDownload)}</span>
+ <span className="text-purple-500 tabular-nums whitespace-nowrap">↑ {formatBytes(domain.totalUpload)}</span>
<span className="text-muted-foreground tabular-nums ml-auto">
{formatNumber(domain.totalConnections)} {t("conn")}
</span>
@@ -525,17 +564,14 @@ export function DomainsTable({ activeBackendId, timeRange, autoRefresh = true }:
))}
</DropdownMenuContent>
</DropdownMenu>
- <span className="text-sm text-muted-foreground">
- {t("total")} {total}
- </span>
</div>
{/* Pagination info and controls */}
- <div className="flex items-center gap-2 sm:gap-3">
- <p className="text-xs sm:text-sm text-muted-foreground hidden sm:block">
+ <div className="flex flex-col sm:flex-row items-center gap-1 sm:gap-3">
+ <p className="text-xs sm:text-sm text-muted-foreground hidden sm:block whitespace-nowrap shrink-0">
{t("showing")} {Math.min((currentPage - 1) * pageSize + 1, total)} - {Math.min(currentPage * pageSize, total)} {t("of")} {total}
</p>
- <p className="text-xs text-muted-foreground sm:hidden">
+ <p className="text-xs text-muted-foreground sm:hidden whitespace-nowrap shrink-0">
{Math.min((currentPage - 1) * pageSize + 1, total)}-{Math.min(currentPage * pageSize, total)} / {total}
</p>
diff --git a/apps/web/components/interactive-device-stats.tsx b/apps/web/components/interactive-device-stats.tsx
index 44acaec..45bbc04 100644
--- a/apps/web/components/interactive-device-stats.tsx
+++ b/apps/web/components/interactive-device-stats.tsx
@@ -1,7 +1,7 @@
"use client";
import { useState, useCallback, useMemo, useEffect } from "react";
-import { Loader2, BarChart3, Link2, Smartphone } from "lucide-react";
+import { BarChart3, Link2, Smartphone } from "lucide-react";
import { useTranslations } from "next-intl";
import { useQuery } from "@tanstack/react-query";
import { PieChart, Pie, Cell, ResponsiveContainer, Tooltip as RechartsTooltip, BarChart, Bar, XAxis, YAxis, Cell as BarCell, LabelList } from "recharts";
@@ -20,7 +20,8 @@ import { keepPreviousByIdentity } from "@/lib/query-placeholder";
import { useStatsWebSocket } from "@/lib/websocket";
import { Favicon } from "@/components/favicon";
import { DomainStatsTable, IPStatsTable } from "@/components/stats-tables";
-import { COLORS } from "@/lib/stats-utils";
+import { InsightChartSkeleton } from "@/components/ui/insight-skeleton";
+import { COLORS, type PageSize } from "@/lib/stats-utils";
import type { DeviceStats, DomainStats, IPStats, StatsSummary } from "@clashmaster/shared";
interface InteractiveDeviceStatsProps {
@@ -57,6 +58,7 @@ export function InteractiveDeviceStats({
const [selectedDevice, setSelectedDevice] = useState<string | null>(null);
const [activeTab, setActiveTab] = useState("domains");
+ const [detailPageSize, setDetailPageSize] = useState<PageSize>(10);
const [showDomainBarLabels, setShowDomainBarLabels] = useState(true);
const [wsDeviceDomains, setWsDeviceDomains] = useState<DomainStats[] | null>(null);
const [wsDeviceIPs, setWsDeviceIPs] = useState<IPStats[] | null>(null);
@@ -163,9 +165,19 @@ export function InteractiveDeviceStats({
}),
});
- const deviceDomains = hasWsDeviceDetails ? wsDeviceDomains ?? [] : deviceDomainsQuery.data ?? [];
- const deviceIPs = hasWsDeviceDetails ? wsDeviceIPs ?? [] : deviceIPsQuery.data ?? [];
- const loading = !!selectedDevice && !hasWsDeviceDetails && !deviceDomainsQuery.data && !deviceIPsQuery.data;
+ const deviceDomains = hasWsDeviceDetails
+ ? wsDeviceDomains ?? []
+ : deviceDomainsQuery.data ?? wsDeviceDomains ?? [];
+ const deviceIPs = hasWsDeviceDetails
+ ? wsDeviceIPs ?? []
+ : deviceIPsQuery.data ?? wsDeviceIPs ?? [];
+ const hasDetailSnapshot =
+ hasWsDeviceDetails ||
+ wsDeviceDomains !== null ||
+ wsDeviceIPs !== null ||
+ deviceDomainsQuery.data !== undefined ||
+ deviceIPsQuery.data !== undefined;
+ const loading = !!selectedDevice && !hasDetailSnapshot;
const handleDeviceClick = useCallback((rawName: string) => {
if (selectedDevice !== rawName) {
@@ -211,9 +223,9 @@ export function InteractiveDeviceStats({
return (
<div className="space-y-6">
- <div className="grid grid-cols-1 lg:grid-cols-12 gap-6">
+ <div className="grid grid-cols-1 md:grid-cols-2 xl:grid-cols-12 gap-6">
{/* Pie Chart */}
- <Card className="lg:col-span-3">
+ <Card className="min-w-0 md:col-span-1 xl:col-span-3">
<CardHeader className="pb-2">
<CardTitle className="text-sm font-semibold text-muted-foreground uppercase tracking-wider">{t("title")}</CardTitle>
</CardHeader>
@@ -258,7 +270,7 @@ export function InteractiveDeviceStats({
</Card>
{/* Device List */}
- <Card className="lg:col-span-4">
+ <Card className="min-w-0 md:col-span-1 xl:col-span-4">
<CardHeader className="pb-2"><CardTitle className="text-sm font-semibold text-muted-foreground uppercase tracking-wider">{t("title")}</CardTitle></CardHeader>
<CardContent className="p-3">
<ScrollArea className="h-[280px] pr-3">
@@ -273,7 +285,7 @@ export function InteractiveDeviceStats({
<div className="flex items-center gap-2 mb-1.5">
<span className={cn("w-5 h-5 rounded-md text-[10px] font-bold flex items-center justify-center shrink-0", badgeColor)}>{item.rank + 1}</span>
<span className="flex-1 text-sm font-medium truncate" title={item.name}>{item.name}</span>
- <span className="text-sm font-bold tabular-nums shrink-0">{formatBytes(item.value)}</span>
+ <span className="text-sm font-bold tabular-nums shrink-0 whitespace-nowrap">{formatBytes(item.value)}</span>
</div>
<div className="pl-7 space-y-1">
<div className="h-1.5 rounded-full bg-muted overflow-hidden flex">
@@ -282,8 +294,8 @@ export function InteractiveDeviceStats({
</div>
<div className="flex flex-wrap items-center justify-between gap-1 text-xs text-muted-foreground">
<div className="flex flex-wrap items-center gap-1.5 sm:gap-2">
- <span className="text-blue-500 dark:text-blue-400">↓ {formatBytes(item.download)}</span>
- <span className="text-purple-500 dark:text-purple-400">↑ {formatBytes(item.upload)}</span>
+ <span className="text-blue-500 dark:text-blue-400 whitespace-nowrap">↓ {formatBytes(item.download)}</span>
+ <span className="text-purple-500 dark:text-purple-400 whitespace-nowrap">↑ {formatBytes(item.upload)}</span>
<span className="flex items-center gap-1 tabular-nums"><Link2 className="w-3 h-3" />{formatNumber(item.connections)}</span>
</div>
<span className="tabular-nums">{percentage.toFixed(1)}%</span>
@@ -298,7 +310,7 @@ export function InteractiveDeviceStats({
</Card>
{/* Top Domains Chart */}
- <Card className="lg:col-span-5">
+ <Card className="min-w-0 md:col-span-2 xl:col-span-5">
<CardHeader className="pb-2">
<div className="flex items-center justify-between">
<CardTitle className="text-sm font-semibold text-muted-foreground uppercase tracking-wider flex items-center gap-2"><BarChart3 className="h-4 w-4" />{domainsT("title")}</CardTitle>
@@ -306,7 +318,7 @@ export function InteractiveDeviceStats({
</div>
</CardHeader>
<CardContent className="pt-0">
- {loading ? (<div className="h-[280px] flex items-center justify-center"><Loader2 className="h-5 w-5 animate-spin text-muted-foreground" /></div>
+ {loading ? (<InsightChartSkeleton />
) : domainChartData.length === 0 ? (
<div className="h-[280px] rounded-xl border border-dashed border-border/60 bg-card/30 px-4 py-5 flex flex-col items-center justify-center text-center">
<BarChart3 className="h-5 w-5 text-muted-foreground/70 mb-2" />
@@ -349,6 +361,8 @@ export function InteractiveDeviceStats({
<DomainStatsTable
domains={deviceDomains}
loading={loading}
+ pageSize={detailPageSize}
+ onPageSizeChange={setDetailPageSize}
activeBackendId={activeBackendId}
timeRange={timeRange}
sourceIP={selectedDevice ?? undefined}
@@ -359,6 +373,8 @@ export function InteractiveDeviceStats({
<IPStatsTable
ips={deviceIPs}
loading={loading}
+ pageSize={detailPageSize}
+ onPageSizeChange={setDetailPageSize}
activeBackendId={activeBackendId}
timeRange={timeRange}
sourceIP={selectedDevice ?? undefined}
diff --git a/apps/web/components/interactive-proxy-stats.tsx b/apps/web/components/interactive-proxy-stats.tsx
index d947e0c..e619b26 100644
--- a/apps/web/components/interactive-proxy-stats.tsx
+++ b/apps/web/components/interactive-proxy-stats.tsx
@@ -1,7 +1,7 @@
"use client";
import { useState, useCallback, useMemo, useEffect } from "react";
-import { Loader2, BarChart3, Link2, Waypoints } from "lucide-react";
+import { BarChart3, Link2, Waypoints } from "lucide-react";
import { useTranslations } from "next-intl";
import { keepPreviousData, useQuery } from "@tanstack/react-query";
import { PieChart, Pie, Cell, ResponsiveContainer, Tooltip as RechartsTooltip, BarChart, Bar, XAxis, YAxis, Cell as BarCell, LabelList } from "recharts";
@@ -22,7 +22,8 @@ import {
} from "@/lib/stats-query-keys";
import { Favicon } from "@/components/favicon";
import { DomainStatsTable, IPStatsTable } from "@/components/stats-tables";
-import { COLORS } from "@/lib/stats-utils";
+import { InsightChartSkeleton, InsightThreePanelSkeleton } from "@/components/ui/insight-skeleton";
+import { COLORS, type PageSize } from "@/lib/stats-utils";
import type { DomainStats, IPStats, ProxyStats, StatsSummary } from "@clashmaster/shared";
interface InteractiveProxyStatsProps {
@@ -92,6 +93,7 @@ export function InteractiveProxyStats({
const [selectedProxy, setSelectedProxy] = useState<string | null>(null);
const [activeTab, setActiveTab] = useState("domains");
+ const [detailPageSize, setDetailPageSize] = useState<PageSize>(10);
const [showDomainBarLabels, setShowDomainBarLabels] = useState(true);
const [wsProxyDomains, setWsProxyDomains] = useState<DomainStats[] | null>(null);
const [wsProxyIPs, setWsProxyIPs] = useState<IPStats[] | null>(null);
@@ -199,9 +201,19 @@ export function InteractiveProxyStats({
}),
});
- const proxyDomains = hasWsProxyDetails ? wsProxyDomains ?? [] : proxyDomainsQuery.data ?? [];
- const proxyIPs = hasWsProxyDetails ? wsProxyIPs ?? [] : proxyIPsQuery.data ?? [];
- const loading = !!selectedProxy && !hasWsProxyDetails && !proxyDomainsQuery.data && !proxyIPsQuery.data;
+ const proxyDomains = hasWsProxyDetails
+ ? wsProxyDomains ?? []
+ : proxyDomainsQuery.data ?? wsProxyDomains ?? [];
+ const proxyIPs = hasWsProxyDetails
+ ? wsProxyIPs ?? []
+ : proxyIPsQuery.data ?? wsProxyIPs ?? [];
+ const hasDetailSnapshot =
+ hasWsProxyDetails ||
+ wsProxyDomains !== null ||
+ wsProxyIPs !== null ||
+ proxyDomainsQuery.data !== undefined ||
+ proxyIPsQuery.data !== undefined;
+ const loading = !!selectedProxy && !hasDetailSnapshot;
const handleProxyClick = useCallback((rawName: string) => {
if (selectedProxy !== rawName) {
@@ -235,9 +247,7 @@ export function InteractiveProxyStats({
return (
<Card>
<CardContent className="p-5 sm:p-6">
- <div className="flex items-center justify-center py-12">
- <Loader2 className="h-5 w-5 animate-spin text-muted-foreground" />
- </div>
+ <InsightThreePanelSkeleton />
</CardContent>
</Card>
);
@@ -259,9 +269,9 @@ export function InteractiveProxyStats({
return (
<div className="space-y-6">
- <div className="grid grid-cols-1 lg:grid-cols-12 gap-6">
+ <div className="grid grid-cols-1 md:grid-cols-2 xl:grid-cols-12 gap-6">
{/* Pie Chart */}
- <Card className="lg:col-span-3">
+ <Card className="min-w-0 md:col-span-1 xl:col-span-3">
<CardHeader className="pb-2">
<CardTitle className="text-sm font-semibold text-muted-foreground uppercase tracking-wider">{t("title")}</CardTitle>
</CardHeader>
@@ -313,7 +323,7 @@ export function InteractiveProxyStats({
</Card>
{/* Proxy List */}
- <Card className="lg:col-span-4">
+ <Card className="min-w-0 md:col-span-1 xl:col-span-4">
<CardHeader className="pb-2"><CardTitle className="text-sm font-semibold text-muted-foreground uppercase tracking-wider">{t("title")}</CardTitle></CardHeader>
<CardContent className="p-3">
<ScrollArea className="h-[280px] pr-3">
@@ -329,7 +339,7 @@ export function InteractiveProxyStats({
<div className="flex items-center gap-2 mb-1.5">
<span className={cn("w-5 h-5 rounded-md text-[10px] font-bold flex items-center justify-center shrink-0", badgeColor)}>{item.rank + 1}</span>
<span className="emoji-flag-font flex-1 text-sm font-medium truncate" title={rawDisplayName}>{rawDisplayName}</span>
- <span className="text-sm font-bold tabular-nums shrink-0">{formatBytes(item.value)}</span>
+ <span className="text-sm font-bold tabular-nums shrink-0 whitespace-nowrap">{formatBytes(item.value)}</span>
</div>
<div className="pl-7 space-y-1">
<div className="h-1.5 rounded-full bg-muted overflow-hidden flex">
@@ -338,8 +348,8 @@ export function InteractiveProxyStats({
</div>
<div className="flex flex-wrap items-center justify-between gap-1 text-xs text-muted-foreground">
<div className="flex flex-wrap items-center gap-1.5 sm:gap-2">
- <span className="text-blue-500 dark:text-blue-400">↓ {formatBytes(item.download)}</span>
- <span className="text-purple-500 dark:text-purple-400">↑ {formatBytes(item.upload)}</span>
+ <span className="text-blue-500 dark:text-blue-400 whitespace-nowrap">↓ {formatBytes(item.download)}</span>
+ <span className="text-purple-500 dark:text-purple-400 whitespace-nowrap">↑ {formatBytes(item.upload)}</span>
<span className="flex items-center gap-1 tabular-nums"><Link2 className="w-3 h-3" />{formatNumber(item.connections)}</span>
</div>
<span className="tabular-nums">{percentage.toFixed(1)}%</span>
@@ -354,7 +364,7 @@ export function InteractiveProxyStats({
</Card>
{/* Top Domains Chart */}
- <Card className="lg:col-span-5">
+ <Card className="min-w-0 md:col-span-2 xl:col-span-5">
<CardHeader className="pb-2">
<div className="flex items-center justify-between">
<CardTitle className="text-sm font-semibold text-muted-foreground uppercase tracking-wider flex items-center gap-2"><BarChart3 className="h-4 w-4" />{domainsT("title")}</CardTitle>
@@ -367,7 +377,7 @@ export function InteractiveProxyStats({
</div>
</CardHeader>
<CardContent className="pt-0">
- {loading ? (<div className="h-[280px] flex items-center justify-center"><Loader2 className="h-5 w-5 animate-spin text-muted-foreground" /></div>
+ {loading ? (<InsightChartSkeleton />
) : domainChartData.length === 0 ? (
<div className="h-[280px] rounded-xl border border-dashed border-border/60 bg-card/30 px-4 py-5 flex flex-col items-center justify-center text-center">
<BarChart3 className="h-5 w-5 text-muted-foreground/70 mb-2" />
@@ -410,6 +420,8 @@ export function InteractiveProxyStats({
<DomainStatsTable
domains={proxyDomains}
loading={loading}
+ pageSize={detailPageSize}
+ onPageSizeChange={setDetailPageSize}
activeBackendId={activeBackendId}
timeRange={timeRange}
sourceChain={selectedProxy}
@@ -422,6 +434,8 @@ export function InteractiveProxyStats({
<IPStatsTable
ips={proxyIPs}
loading={loading}
+ pageSize={detailPageSize}
+ onPageSizeChange={setDetailPageSize}
activeBackendId={activeBackendId}
timeRange={timeRange}
sourceChain={selectedProxy}
diff --git a/apps/web/components/interactive-rule-stats.tsx b/apps/web/components/interactive-rule-stats.tsx
index ac91e4b..49a7856 100644
--- a/apps/web/components/interactive-rule-stats.tsx
+++ b/apps/web/components/interactive-rule-stats.tsx
@@ -1,7 +1,7 @@
"use client";
import { useState, useCallback, useMemo, useEffect, useRef, startTransition } from "react";
-import { Server, ChevronLeft, ChevronRight, Loader2, BarChart3, Link2, Rows3, ArrowUpDown, ArrowDown, ArrowUp, Globe, Waypoints, ChevronDown, ChevronUp } from "lucide-react";
+import { Server, ChevronLeft, ChevronRight, BarChart3, Link2, Rows3, ArrowUpDown, ArrowDown, ArrowUp, Globe, Waypoints, ChevronDown, ChevronUp } from "lucide-react";
import { useTranslations } from "next-intl";
import { keepPreviousData, useQuery } from "@tanstack/react-query";
import { PieChart, Pie, Cell, ResponsiveContainer, Tooltip as RechartsTooltip } from "recharts";
@@ -34,10 +34,12 @@ import {
} from "@/lib/stats-query-keys";
import { CountryFlag } from "@/components/country-flag";
import { Favicon } from "@/components/favicon";
+import { DomainPreview } from "@/components/domain-preview";
import { ProxyChainBadge } from "@/components/proxy-chain-badge";
import { DomainExpandedDetails, IPExpandedDetails } from "@/components/stats-tables/expanded-details";
import { ExpandReveal } from "@/components/ui/expand-reveal";
import { UnifiedRuleChainFlow } from "@/components/rule-chain-flow";
+import { InsightChartSkeleton, InsightDetailSectionSkeleton, InsightTableSkeleton, InsightThreePanelSkeleton } from "@/components/ui/insight-skeleton";
import type { RuleStats, DomainStats, IPStats, StatsSummary } from "@clashmaster/shared";
interface InteractiveRuleStatsProps {
@@ -162,10 +164,9 @@ export function InteractiveRuleStats({
// Pagination states
const [domainPage, setDomainPage] = useState(1);
- const [domainPageSize, setDomainPageSize] = useState<PageSize>(10);
+ const [detailPageSize, setDetailPageSize] = useState<PageSize>(10);
const [domainSearch, setDomainSearch] = useState("");
const [ipPage, setIpPage] = useState(1);
- const [ipPageSize, setIpPageSize] = useState<PageSize>(10);
const [ipSearch, setIpSearch] = useState("");
const [showDomainBarLabels, setShowDomainBarLabels] = useState(true);
const [clashRules, setClashRules] = useState<ClashRulesResponse | null>(null);
@@ -518,9 +519,19 @@ export function InteractiveRuleStats({
}),
});
- const ruleDomains: DomainStats[] = hasWsRuleDetails ? wsRuleDomains ?? [] : ruleDomainsQuery.data ?? [];
- const ruleIPs: IPStats[] = hasWsRuleDetails ? wsRuleIPs ?? [] : ruleIPsQuery.data ?? [];
- const loading = !!selectedRule && !hasWsRuleDetails && !ruleDomainsQuery.data && !ruleIPsQuery.data;
+ const ruleDomains: DomainStats[] = hasWsRuleDetails
+ ? wsRuleDomains ?? []
+ : ruleDomainsQuery.data ?? wsRuleDomains ?? [];
+ const ruleIPs: IPStats[] = hasWsRuleDetails
+ ? wsRuleIPs ?? []
+ : ruleIPsQuery.data ?? wsRuleIPs ?? [];
+ const hasDetailSnapshot =
+ hasWsRuleDetails ||
+ wsRuleDomains !== null ||
+ wsRuleIPs !== null ||
+ ruleDomainsQuery.data !== undefined ||
+ ruleIPsQuery.data !== undefined;
+ const loading = !!selectedRule && !hasDetailSnapshot;
// Sort icon component
const DomainSortIcon = ({ column }: { column: DomainSortKey }) => {
@@ -604,12 +615,12 @@ export function InteractiveRuleStats({
const paginatedDomains = useMemo(() => {
if (!isDomainsTab) return EMPTY_DOMAINS;
- const start = (domainPage - 1) * domainPageSize;
- return filteredDomains.slice(start, start + domainPageSize);
- }, [isDomainsTab, filteredDomains, domainPage, domainPageSize]);
+ const start = (domainPage - 1) * detailPageSize;
+ return filteredDomains.slice(start, start + detailPageSize);
+ }, [isDomainsTab, filteredDomains, domainPage, detailPageSize]);
const domainTotalPages = isDomainsTab
- ? Math.max(1, Math.ceil(filteredDomains.length / domainPageSize))
+ ? Math.max(1, Math.ceil(filteredDomains.length / detailPageSize))
: 1;
const totalFilteredDomainTraffic = useMemo(
() => (isDomainsTab
@@ -642,12 +653,12 @@ export function InteractiveRuleStats({
const paginatedIPs = useMemo(() => {
if (!isIPsTab) return EMPTY_IPS;
- const start = (ipPage - 1) * ipPageSize;
- return filteredIPs.slice(start, start + ipPageSize);
- }, [isIPsTab, filteredIPs, ipPage, ipPageSize]);
+ const start = (ipPage - 1) * detailPageSize;
+ return filteredIPs.slice(start, start + detailPageSize);
+ }, [isIPsTab, filteredIPs, ipPage, detailPageSize]);
const ipTotalPages = isIPsTab
- ? Math.max(1, Math.ceil(filteredIPs.length / ipPageSize))
+ ? Math.max(1, Math.ceil(filteredIPs.length / detailPageSize))
: 1;
const totalFilteredIPTraffic = useMemo(
() => (isIPsTab
@@ -705,13 +716,14 @@ export function InteractiveRuleStats({
if (listLoading) {
return (
- <Card>
- <CardContent className="p-5 sm:p-6">
- <div className="flex items-center justify-center py-12">
- <Loader2 className="h-5 w-5 animate-spin text-muted-foreground" />
- </div>
- </CardContent>
- </Card>
+ <div className="space-y-6">
+ <Card>
+ <CardContent className="p-5 sm:p-6">
+ <InsightThreePanelSkeleton />
+ </CardContent>
+ </Card>
+ <InsightDetailSectionSkeleton />
+ </div>
);
}
@@ -732,9 +744,9 @@ export function InteractiveRuleStats({
return (
<div className="space-y-6">
{/* Top Section: Three Column Layout */}
- <div className="grid grid-cols-1 lg:grid-cols-12 gap-6">
+ <div className="grid grid-cols-1 md:grid-cols-2 xl:grid-cols-12 gap-6">
{/* Left: Pie Chart (3 columns) */}
- <Card className="lg:col-span-3">
+ <Card className="min-w-0 md:col-span-1 xl:col-span-3">
<CardHeader className="pb-2">
<CardTitle className="text-sm font-semibold text-muted-foreground uppercase tracking-wider">
{t("distribution")}
@@ -819,7 +831,7 @@ export function InteractiveRuleStats({
</Card>
{/* Middle: Rule List (4 columns) */}
- <Card className="lg:col-span-4">
+ <Card className="min-w-0 md:col-span-1 xl:col-span-4">
<CardHeader className="pb-2">
<CardTitle className="text-sm font-semibold text-muted-foreground uppercase tracking-wider">
{t("ruleList")}
@@ -870,7 +882,7 @@ export function InteractiveRuleStats({
{item.name}
</span>
- <span className="text-sm font-bold tabular-nums shrink-0">
+ <span className="text-sm font-bold tabular-nums shrink-0 whitespace-nowrap">
{noTraffic ? (
<span className="text-xs font-normal text-muted-foreground">{t("noTrafficRecord")}</span>
) : formatBytes(item.value)}
@@ -894,8 +906,8 @@ export function InteractiveRuleStats({
{/* Stats */}
<div className="flex flex-wrap items-center justify-between gap-1 text-xs text-muted-foreground">
<div className="flex flex-wrap items-center gap-1.5 sm:gap-2">
- <span className="text-blue-500 dark:text-blue-400">↓ {formatBytes(item.download)}</span>
- <span className="text-purple-500 dark:text-purple-400">↑ {formatBytes(item.upload)}</span>
+ <span className="text-blue-500 dark:text-blue-400 whitespace-nowrap">↓ {formatBytes(item.download)}</span>
+ <span className="text-purple-500 dark:text-purple-400 whitespace-nowrap">↑ {formatBytes(item.upload)}</span>
<span className="flex items-center gap-1 tabular-nums">
<Link2 className="w-3 h-3" />
{formatNumber(item.connections)}
@@ -914,7 +926,7 @@ export function InteractiveRuleStats({
</Card>
{/* Right: Top Domains Chart (5 columns) */}
- <Card className="lg:col-span-5">
+ <Card className="min-w-0 md:col-span-2 xl:col-span-5">
<CardHeader className="pb-2">
<div className="flex items-center justify-between">
<CardTitle className="text-sm font-semibold text-muted-foreground uppercase tracking-wider flex items-center gap-2">
@@ -930,9 +942,7 @@ export function InteractiveRuleStats({
</CardHeader>
<CardContent>
{loading ? (
- <div className="flex items-center justify-center py-8 h-[280px]">
- <div className="h-5 w-5 border-2 border-primary/30 border-t-primary rounded-full animate-spin" />
- </div>
+ <InsightChartSkeleton />
) : domainChartData.length === 0 ? (
<div className="h-[280px] rounded-xl border border-dashed border-border/60 bg-card/30 px-4 py-5 flex flex-col items-center justify-center text-center">
<BarChart3 className="h-5 w-5 text-muted-foreground/70 mb-2" />
@@ -1039,7 +1049,7 @@ export function InteractiveRuleStats({
/>
{/* Bottom Section: Domain List & IP Addresses with pagination */}
- {selectedRule && (
+ {selectedRule ? (
<Tabs value={activeTab} onValueChange={setActiveTab} className="w-full">
{/* Simplified Tabs - no icons, no counts, like Domains page */}
<TabsList className="glass">
@@ -1078,9 +1088,7 @@ export function InteractiveRuleStats({
<CardContent className="p-0">
{loading ? (
- <div className="flex items-center justify-center py-12">
- <Loader2 className="h-5 w-5 animate-spin text-muted-foreground" />
- </div>
+ <InsightTableSkeleton />
) : filteredDomains.length === 0 ? (
<div className="px-4 py-6">
<div className="min-h-[180px] rounded-xl border border-dashed border-border/60 bg-card/30 px-4 py-5 flex flex-col items-center justify-center text-center">
@@ -1186,9 +1194,13 @@ export function InteractiveRuleStats({
{/* Domain with Favicon */}
<div className="col-span-3 flex items-center gap-3 min-w-0">
<Favicon domain={domain.domain} size="sm" className="shrink-0" />
- <span className="font-medium text-sm truncate" title={domain.domain}>
- {domain.domain}
- </span>
+ <DomainPreview
+ className="flex-1"
+ domain={domain.domain}
+ unknownLabel={domainsT("unknown")}
+ copyLabel={domainsT("copyDomain")}
+ copiedLabel={domainsT("copied")}
+ />
</div>
{/* Proxy */}
@@ -1197,12 +1209,12 @@ export function InteractiveRuleStats({
</div>
{/* Download */}
- <div className="col-span-2 text-right tabular-nums text-sm">
+ <div className="col-span-2 text-right tabular-nums text-sm whitespace-nowrap">
<span className="text-blue-500">{formatBytes(domain.totalDownload)}</span>
</div>
{/* Upload */}
- <div className="col-span-2 text-right tabular-nums text-sm">
+ <div className="col-span-2 text-right tabular-nums text-sm whitespace-nowrap">
<span className="text-purple-500">{formatBytes(domain.totalUpload)}</span>
</div>
@@ -1251,9 +1263,13 @@ export function InteractiveRuleStats({
{/* Top: Favicon + Domain + Expand */}
<div className="flex items-center gap-2.5 mb-2">
<Favicon domain={domain.domain} size="sm" className="shrink-0" />
- <span className="font-medium text-sm truncate flex-1" title={domain.domain}>
- {domain.domain}
- </span>
+ <DomainPreview
+ className="flex-1"
+ domain={domain.domain}
+ unknownLabel={domainsT("unknown")}
+ copyLabel={domainsT("copyDomain")}
+ copiedLabel={domainsT("copied")}
+ />
<Button
variant="ghost"
size="sm"
@@ -1283,8 +1299,8 @@ export function InteractiveRuleStats({
{/* Bottom: Stats row */}
<div className="flex items-center justify-between text-xs pl-[30px]">
- <span className="text-blue-500 tabular-nums">↓ {formatBytes(domain.totalDownload)}</span>
- <span className="text-purple-500 tabular-nums">↑ {formatBytes(domain.totalUpload)}</span>
+ <span className="text-blue-500 tabular-nums whitespace-nowrap">↓ {formatBytes(domain.totalDownload)}</span>
+ <span className="text-purple-500 tabular-nums whitespace-nowrap">↑ {formatBytes(domain.totalUpload)}</span>
<span className="px-2 py-0.5 rounded-full bg-secondary text-muted-foreground font-medium">
{formatNumber(domain.totalConnections)} {domainsT("conn")}
</span>
@@ -1329,7 +1345,7 @@ export function InteractiveRuleStats({
<DropdownMenuTrigger asChild>
<Button variant="ghost" size="sm" className="h-8 gap-1.5 text-muted-foreground hover:text-foreground">
<Rows3 className="h-4 w-4" />
- <span>{domainPageSize} / {domainsT("page")}</span>
+ <span>{detailPageSize} / {domainsT("page")}</span>
</Button>
</DropdownMenuTrigger>
<DropdownMenuContent align="start">
@@ -1337,23 +1353,21 @@ export function InteractiveRuleStats({
<DropdownMenuItem
key={size}
onClick={() => {
- setDomainPageSize(size);
+ setDetailPageSize(size);
setDomainPage(1);
+ setIpPage(1);
}}
- className={domainPageSize === size ? "bg-primary/10" : ""}
+ className={detailPageSize === size ? "bg-primary/10" : ""}
>
{size} / {domainsT("page")}
</DropdownMenuItem>
))}
</DropdownMenuContent>
</DropdownMenu>
- <span className="text-sm text-muted-foreground">
- {domainsT("total")} {filteredDomains.length}
- </span>
</div>
- <div className="flex items-center gap-2">
- <p className="text-xs text-muted-foreground">
- {(domainPage - 1) * domainPageSize + 1}-{Math.min(domainPage * domainPageSize, filteredDomains.length)} / {filteredDomains.length}
+ <div className="flex flex-col sm:flex-row items-center gap-1 sm:gap-2">
+ <p className="text-xs text-muted-foreground whitespace-nowrap shrink-0">
+ {(domainPage - 1) * detailPageSize + 1}-{Math.min(domainPage * detailPageSize, filteredDomains.length)} / {filteredDomains.length}
</p>
<div className="flex items-center gap-1">
<Button
@@ -1427,9 +1441,7 @@ export function InteractiveRuleStats({
<CardContent className="p-0">
{loading ? (
- <div className="flex items-center justify-center py-12">
- <Loader2 className="h-5 w-5 animate-spin text-muted-foreground" />
- </div>
+ <InsightTableSkeleton />
) : filteredIPs.length === 0 ? (
<div className="px-4 py-6">
<div className="min-h-[180px] rounded-xl border border-dashed border-border/60 bg-card/30 px-4 py-5 flex flex-col items-center justify-center text-center">
@@ -1562,12 +1574,12 @@ export function InteractiveRuleStats({
</div>
{/* Download */}
- <div className="col-span-2 text-right tabular-nums text-sm">
+ <div className="col-span-2 text-right tabular-nums text-sm whitespace-nowrap">
<span className="text-blue-500">{formatBytes(ip.totalDownload)}</span>
</div>
{/* Upload */}
- <div className="col-span-1 text-right tabular-nums text-sm">
+ <div className="col-span-1 text-right tabular-nums text-sm whitespace-nowrap">
<span className="text-purple-500">{formatBytes(ip.totalUpload)}</span>
</div>
@@ -1656,8 +1668,8 @@ export function InteractiveRuleStats({
{/* Bottom: Stats row */}
<div className="flex items-center justify-between text-xs pl-[30px]">
- <span className="text-blue-500 tabular-nums">↓ {formatBytes(ip.totalDownload)}</span>
- <span className="text-purple-500 tabular-nums">↑ {formatBytes(ip.totalUpload)}</span>
+ <span className="text-blue-500 tabular-nums whitespace-nowrap">↓ {formatBytes(ip.totalDownload)}</span>
+ <span className="text-purple-500 tabular-nums whitespace-nowrap">↑ {formatBytes(ip.totalUpload)}</span>
<span className="px-2 py-0.5 rounded-full bg-secondary text-muted-foreground font-medium">
{formatNumber(ip.totalConnections)} {ipsT("conn")}
</span>
@@ -1703,7 +1715,7 @@ export function InteractiveRuleStats({
<DropdownMenuTrigger asChild>
<Button variant="ghost" size="sm" className="h-8 gap-1.5 text-muted-foreground hover:text-foreground">
<Rows3 className="h-4 w-4" />
- <span>{ipPageSize} / {ipsT("page")}</span>
+ <span>{detailPageSize} / {ipsT("page")}</span>
</Button>
</DropdownMenuTrigger>
<DropdownMenuContent align="start">
@@ -1711,23 +1723,21 @@ export function InteractiveRuleStats({
<DropdownMenuItem
key={size}
onClick={() => {
- setIpPageSize(size);
+ setDetailPageSize(size);
+ setDomainPage(1);
setIpPage(1);
}}
- className={ipPageSize === size ? "bg-primary/10" : ""}
+ className={detailPageSize === size ? "bg-primary/10" : ""}
>
{size} / {ipsT("page")}
</DropdownMenuItem>
))}
</DropdownMenuContent>
</DropdownMenu>
- <span className="text-sm text-muted-foreground">
- {ipsT("total")} {filteredIPs.length}
- </span>
</div>
- <div className="flex items-center gap-2">
- <p className="text-xs text-muted-foreground">
- {(ipPage - 1) * ipPageSize + 1}-{Math.min(ipPage * ipPageSize, filteredIPs.length)} / {filteredIPs.length}
+ <div className="flex flex-col sm:flex-row items-center gap-1 sm:gap-2">
+ <p className="text-xs text-muted-foreground whitespace-nowrap shrink-0">
+ {(ipPage - 1) * detailPageSize + 1}-{Math.min(ipPage * detailPageSize, filteredIPs.length)} / {filteredIPs.length}
</p>
<div className="flex items-center gap-1">
<Button
@@ -1774,6 +1784,8 @@ export function InteractiveRuleStats({
</Card>
</TabsContent>
</Tabs>
+ ) : (
+ <InsightDetailSectionSkeleton />
)}
</div>
);
diff --git a/apps/web/components/ips-table.tsx b/apps/web/components/ips-table.tsx
index 6d6bcc1..3017bec 100644
--- a/apps/web/components/ips-table.tsx
+++ b/apps/web/components/ips-table.tsx
@@ -1,6 +1,6 @@
"use client";
-import { useState, useEffect, useMemo, useRef, useCallback } from "react";
+import { useState, useEffect, useRef, useCallback } from "react";
import {
Search,
ArrowUpDown,
@@ -14,12 +14,12 @@ import {
ChevronDown,
ChevronUp,
Link2,
- Loader2,
} from "lucide-react";
import { useTranslations } from "next-intl";
import { keepPreviousData, useQuery } from "@tanstack/react-query";
import { Input } from "@/components/ui/input";
import { Button } from "@/components/ui/button";
+import { InsightTableSkeleton } from "@/components/ui/insight-skeleton";
import { CountryFlag } from "@/components/country-flag";
import { formatBytes, formatNumber } from "@/lib/utils";
import { cn } from "@/lib/utils";
@@ -46,6 +46,8 @@ interface IPsTableProps {
activeBackendId?: number;
timeRange?: TimeRange;
autoRefresh?: boolean;
+ pageSize?: PageSize;
+ onPageSizeChange?: (size: PageSize) => void;
}
type SortKey =
@@ -60,6 +62,19 @@ const PAGE_SIZE_OPTIONS = [10, 20, 50, 100] as const;
type PageSize = (typeof PAGE_SIZE_OPTIONS)[number];
const DETAIL_QUERY_STALE_MS = 30_000;
const IPS_WS_MIN_PUSH_MS = 3_000;
+type IPsPageQueryState = {
+ offset: number;
+ limit: number;
+ sortBy?: string;
+ sortOrder?: "asc" | "desc";
+ search?: string;
+};
+type IPsPageState = {
+ data: IPStats[];
+ total: number;
+ query: IPsPageQueryState;
+ backendId?: number;
+};
// Color palette for IP icons - solid colors that work in both light/dark modes
const IP_COLORS = [
@@ -82,7 +97,13 @@ const getIPColor = (ip: string) => {
return IP_COLORS[Math.abs(hash) % IP_COLORS.length];
};
-export function IPsTable({ activeBackendId, timeRange, autoRefresh = true }: IPsTableProps) {
+export function IPsTable({
+ activeBackendId,
+ timeRange,
+ autoRefresh = true,
+ pageSize: controlledPageSize,
+ onPageSizeChange,
+}: IPsTableProps) {
const t = useTranslations("ips");
const stableTimeRange = useStableTimeRange(timeRange);
const detailTimeRange = stableTimeRange;
@@ -91,9 +112,17 @@ export function IPsTable({ activeBackendId, timeRange, autoRefresh = true }: IPs
const [sortKey, setSortKey] = useState<SortKey>("totalDownload");
const [sortOrder, setSortOrder] = useState<SortOrder>("desc");
const [currentPage, setCurrentPage] = useState(1);
- const [pageSize, setPageSize] = useState<PageSize>(10);
+ const [internalPageSize, setInternalPageSize] = useState<PageSize>(10);
+ const pageSize = controlledPageSize ?? internalPageSize;
+ const setEffectivePageSize = useCallback((size: PageSize) => {
+ if (onPageSizeChange) {
+ onPageSizeChange(size);
+ return;
+ }
+ setInternalPageSize(size);
+ }, [onPageSizeChange]);
const [expandedIP, setExpandedIP] = useState<string | null>(null);
- const [wsIPsPage, setWsIPsPage] = useState<{ data: IPStats[]; total: number } | null>(null);
+ const [wsIPsPage, setWsIPsPage] = useState<IPsPageState | null>(null);
const debounceRef = useRef<ReturnType<typeof setTimeout> | null>(null);
const pageOffset = (currentPage - 1) * pageSize;
const wsPageSearch = debouncedSearch || undefined;
@@ -115,26 +144,29 @@ export function IPsTable({ activeBackendId, timeRange, autoRefresh = true }: IPs
const query = stats.ipsPageQuery;
const page = stats.ipsPage;
if (!page || !query) return;
- if (query.offset !== pageOffset || query.limit !== pageSize) return;
- if ((query.sortBy || "totalDownload") !== sortKey) return;
- if ((query.sortOrder || "desc") !== sortOrder) return;
- if ((query.search || undefined) !== wsPageSearch) return;
- setWsIPsPage(page);
- }, [pageOffset, pageSize, sortKey, sortOrder, wsPageSearch]),
+ setWsIPsPage({
+ data: page.data,
+ total: page.total,
+ query: {
+ offset: query.offset,
+ limit: query.limit,
+ sortBy: query.sortBy || "totalDownload",
+ sortOrder: query.sortOrder === "asc" ? "asc" : "desc",
+ search: query.search || undefined,
+ },
+ backendId: activeBackendId,
+ });
+ }, [activeBackendId]),
});
- useEffect(() => {
- setWsIPsPage(null);
- }, [
- activeBackendId,
- stableTimeRange?.start,
- stableTimeRange?.end,
- pageOffset,
- pageSize,
- sortKey,
- sortOrder,
- wsPageSearch,
- ]);
+ const wsIPsPageMatchesCurrent =
+ wsIPsPage !== null &&
+ wsIPsPage.backendId === activeBackendId &&
+ wsIPsPage.query.offset === pageOffset &&
+ wsIPsPage.query.limit === pageSize &&
+ (wsIPsPage.query.sortBy || "totalDownload") === sortKey &&
+ (wsIPsPage.query.sortOrder || "desc") === sortOrder &&
+ (wsIPsPage.query.search || undefined) === wsPageSearch;
// Debounce search input
useEffect(() => {
@@ -169,16 +201,17 @@ export function IPsTable({ activeBackendId, timeRange, autoRefresh = true }: IPs
start: stableTimeRange?.start,
end: stableTimeRange?.end,
}),
- enabled: !!activeBackendId && wsPageStatus !== "connected",
+ enabled:
+ !!activeBackendId &&
+ (!wsPageEnabled || wsPageStatus !== "connected" || !wsIPsPageMatchesCurrent),
placeholderData: keepPreviousData,
});
- const hasWsIPsPage = wsPageEnabled && wsPageStatus === "connected" && wsIPsPage !== null;
- const data = hasWsIPsPage ? wsIPsPage.data : ipsQuery.data?.data ?? [];
- const total = hasWsIPsPage ? wsIPsPage.total : ipsQuery.data?.total ?? 0;
- const loading =
- (wsPageStatus === "connected" && wsIPsPage === null) ||
- (!hasWsIPsPage && ipsQuery.isLoading && !ipsQuery.data);
+ const hasWsIPsPage =
+ wsPageEnabled && wsPageStatus === "connected" && wsIPsPageMatchesCurrent;
+ const data = hasWsIPsPage ? wsIPsPage!.data : ipsQuery.data?.data ?? [];
+ const total = hasWsIPsPage ? wsIPsPage!.total : ipsQuery.data?.total ?? 0;
+ const loading = !hasWsIPsPage && ipsQuery.isLoading && !ipsQuery.data;
useEffect(() => {
// Backend switch means a different data universe, collapse safely.
@@ -234,7 +267,7 @@ export function IPsTable({ activeBackendId, timeRange, autoRefresh = true }: IPs
};
const handlePageSizeChange = (size: PageSize) => {
- setPageSize(size);
+ setEffectivePageSize(size);
setCurrentPage(1);
};
@@ -367,9 +400,7 @@ export function IPsTable({ activeBackendId, timeRange, autoRefresh = true }: IPs
{/* Table Body */}
<div className="divide-y divide-border/30 min-h-[300px]">
{loading && data.length === 0 ? (
- <div className="px-5 py-12 text-center text-muted-foreground">
- <Loader2 className="h-6 w-6 animate-spin mx-auto mb-2" />
- </div>
+ <InsightTableSkeleton />
) : data.length === 0 ? (
<div className="px-5 py-12 text-center text-muted-foreground">
{t("noResults")}
@@ -422,14 +453,14 @@ export function IPsTable({ activeBackendId, timeRange, autoRefresh = true }: IPs
</div>
{/* Download */}
- <div className="col-span-2 text-right tabular-nums text-sm">
+ <div className="col-span-2 text-right tabular-nums text-sm whitespace-nowrap">
<span className="text-blue-500">
{formatBytes(ip.totalDownload)}
</span>
</div>
{/* Upload */}
- <div className="col-span-1 text-right tabular-nums text-sm">
+ <div className="col-span-1 text-right tabular-nums text-sm whitespace-nowrap">
<span className="text-purple-500">
{formatBytes(ip.totalUpload)}
</span>
@@ -526,10 +557,10 @@ export function IPsTable({ activeBackendId, timeRange, autoRefresh = true }: IPs
{/* Row 3: Traffic stats - compact layout */}
<div className="flex items-center gap-3 text-[11px] pl-[30px]">
- <span className="text-blue-500 tabular-nums">
+ <span className="text-blue-500 tabular-nums whitespace-nowrap">
↓ {formatBytes(ip.totalDownload)}
</span>
- <span className="text-purple-500 tabular-nums">
+ <span className="text-purple-500 tabular-nums whitespace-nowrap">
↑ {formatBytes(ip.totalUpload)}
</span>
<span className="text-muted-foreground tabular-nums ml-auto">
@@ -573,11 +604,11 @@ export function IPsTable({ activeBackendId, timeRange, autoRefresh = true }: IPs
<div className="p-3 sm:p-4 border-t border-border/50 bg-secondary/20">
<div className="flex flex-col sm:flex-row items-center justify-between gap-3">
{/* Page size selector */}
- <div className="flex items-center gap-2">
- <DropdownMenu>
- <DropdownMenuTrigger asChild>
- <Button
- variant="ghost"
+ <div className="flex items-center gap-2">
+ <DropdownMenu>
+ <DropdownMenuTrigger asChild>
+ <Button
+ variant="ghost"
size="sm"
className="h-8 gap-1.5 text-muted-foreground hover:text-foreground">
<Rows3 className="h-4 w-4" />
@@ -595,21 +626,18 @@ export function IPsTable({ activeBackendId, timeRange, autoRefresh = true }: IPs
{size} / {t("page")}
</DropdownMenuItem>
))}
- </DropdownMenuContent>
- </DropdownMenu>
- <span className="text-sm text-muted-foreground">
- {t("total")} {total}
- </span>
- </div>
+ </DropdownMenuContent>
+ </DropdownMenu>
+ </div>
{/* Pagination info and controls */}
- <div className="flex items-center gap-2 sm:gap-3">
- <p className="text-xs sm:text-sm text-muted-foreground hidden sm:block">
+ <div className="flex flex-col sm:flex-row items-center gap-1 sm:gap-3">
+ <p className="text-xs sm:text-sm text-muted-foreground hidden sm:block whitespace-nowrap shrink-0">
{t("showing")}{" "}
{Math.min((currentPage - 1) * pageSize + 1, total)} -{" "}
{Math.min(currentPage * pageSize, total)} {t("of")} {total}
</p>
- <p className="text-xs text-muted-foreground sm:hidden">
+ <p className="text-xs text-muted-foreground sm:hidden whitespace-nowrap shrink-0">
{Math.min((currentPage - 1) * pageSize + 1, total)}-
{Math.min(currentPage * pageSize, total)} / {total}
</p>
diff --git a/apps/web/components/overview/index.tsx b/apps/web/components/overview/index.tsx
index 098aca8..99a9ebd 100644
--- a/apps/web/components/overview/index.tsx
+++ b/apps/web/components/overview/index.tsx
@@ -127,7 +127,7 @@ export function OverviewTab({
const [trendGranularity, setTrendGranularity] = useState<TrendGranularity>("minute");
const [trendTimeRange, setTrendTimeRange] = useState<TrendTimeRange>("24h");
const [trendLoading, setTrendLoading] = useState(false);
- const [isPending, startTransition] = useTransition();
+ const [, startTransition] = useTransition();
const initialLoadedRef = useRef(false);
const requestIdRef = useRef(0);
@@ -336,6 +336,8 @@ export function OverviewTab({
// Handle time range change with transition
const handleTimeRangeChange = (range: TrendTimeRange) => {
+ if (range === trendTimeRange) return;
+ setTrendLoading(true);
startTransition(() => {
setTrendTimeRange(range);
});
@@ -350,7 +352,7 @@ export function OverviewTab({
timeRange={canUseTrendSelector ? trendTimeRange : undefined}
timeRangeOptions={trendTimeOptions}
onTimeRangeChange={canUseTrendSelector ? handleTimeRangeChange : undefined}
- isLoading={trendLoading || isPending}
+ isLoading={trendLoading}
emptyHint={backendStatus === "unhealthy" ? dashboardT("backendUnavailableHint") : undefined}
/>
diff --git a/apps/web/components/stats-tables/domain-stats-table.tsx b/apps/web/components/stats-tables/domain-stats-table.tsx
index 1eefcfd..acb6a66 100644
--- a/apps/web/components/stats-tables/domain-stats-table.tsx
+++ b/apps/web/components/stats-tables/domain-stats-table.tsx
@@ -5,7 +5,6 @@ import { useQuery } from "@tanstack/react-query";
import {
ChevronLeft,
ChevronRight,
- Loader2,
Rows3,
ArrowUpDown,
ArrowDown,
@@ -34,9 +33,11 @@ import {
getDomainProxyStatsQueryKey,
} from "@/lib/stats-query-keys";
import { Favicon } from "@/components/favicon";
+import { DomainPreview } from "@/components/domain-preview";
import { DomainExpandedDetails } from "@/components/stats-tables/expanded-details";
import { ProxyChainBadge } from "@/components/proxy-chain-badge";
import { ExpandReveal } from "@/components/ui/expand-reveal";
+import { InsightTableSkeleton } from "@/components/ui/insight-skeleton";
import {
PAGE_SIZE_OPTIONS,
getPageNumbers,
@@ -52,6 +53,8 @@ interface DomainStatsTableProps {
loading?: boolean;
title?: string;
showHeader?: boolean;
+ pageSize?: PageSize;
+ onPageSizeChange?: (size: PageSize) => void;
activeBackendId?: number;
timeRange?: TimeRange;
sourceIP?: string;
@@ -66,6 +69,8 @@ export function DomainStatsTable({
loading = false,
title,
showHeader = true,
+ pageSize: controlledPageSize,
+ onPageSizeChange,
activeBackendId,
timeRange,
sourceIP,
@@ -78,7 +83,8 @@ export function DomainStatsTable({
const detailTimeRange = useStableTimeRange(timeRange);
const [page, setPage] = useState(1);
- const [pageSize, setPageSize] = useState<PageSize>(10);
+ const [internalPageSize, setInternalPageSize] = useState<PageSize>(10);
+ const pageSize = controlledPageSize ?? internalPageSize;
const [search, setSearch] = useState("");
const [sortKey, setSortKey] = useState<DomainSortKey>("totalDownload");
const [sortOrder, setSortOrder] = useState<SortOrder>("desc");
@@ -89,6 +95,18 @@ export function DomainStatsTable({
setExpandedDomain(null);
}, [activeBackendId, sourceIP, sourceChain, richExpand]);
+ useEffect(() => {
+ setPage(1);
+ }, [pageSize]);
+
+ const setEffectivePageSize = (size: PageSize) => {
+ if (onPageSizeChange) {
+ onPageSizeChange(size);
+ return;
+ }
+ setInternalPageSize(size);
+ };
+
const expandedDomainProxyQuery = useQuery({
queryKey: getDomainProxyStatsQueryKey(expandedDomain, activeBackendId, detailTimeRange, {
sourceIP,
@@ -214,9 +232,7 @@ export function DomainStatsTable({
<CardContent className="p-0">
{loading ? (
- <div className="flex items-center justify-center py-12">
- <Loader2 className="h-5 w-5 animate-spin text-muted-foreground" />
- </div>
+ <InsightTableSkeleton />
) : filteredDomains.length === 0 ? (
<div className="text-center py-12 text-muted-foreground">
{search ? t("noResults") : t("noData")}
@@ -301,9 +317,13 @@ export function DomainStatsTable({
>
<div className={cn(domainColumnClass, "flex items-center gap-3 min-w-0")}>
<Favicon domain={domain.domain} size="sm" className="shrink-0" />
- <span className="font-medium text-sm truncate" title={domain.domain}>
- {domain.domain || t("unknown")}
- </span>
+ <DomainPreview
+ className="flex-1"
+ domain={domain.domain}
+ unknownLabel={t("unknown")}
+ copyLabel={t("copyDomain")}
+ copiedLabel={t("copied")}
+ />
</div>
{showProxyColumn && (
@@ -312,11 +332,11 @@ export function DomainStatsTable({
</div>
)}
- <div className="col-span-2 text-right tabular-nums text-sm">
+ <div className="col-span-2 text-right tabular-nums text-sm whitespace-nowrap">
<span className="text-blue-500">{formatBytes(domain.totalDownload)}</span>
</div>
- <div className="col-span-2 text-right tabular-nums text-sm">
+ <div className="col-span-2 text-right tabular-nums text-sm whitespace-nowrap">
<span className="text-purple-500">{formatBytes(domain.totalUpload)}</span>
</div>
@@ -361,9 +381,13 @@ export function DomainStatsTable({
>
<div className="flex items-center gap-2.5 mb-2">
<Favicon domain={domain.domain} size="sm" className="shrink-0" />
- <span className="font-medium text-sm truncate flex-1" title={domain.domain}>
- {domain.domain || t("unknown")}
- </span>
+ <DomainPreview
+ className="flex-1"
+ domain={domain.domain}
+ unknownLabel={t("unknown")}
+ copyLabel={t("copyDomain")}
+ copiedLabel={t("copied")}
+ />
<Button
variant="ghost"
size="sm"
@@ -389,8 +413,8 @@ export function DomainStatsTable({
)}
<div className="flex items-center justify-between text-xs pl-[30px]">
- <span className="text-blue-500 tabular-nums">↓ {formatBytes(domain.totalDownload)}</span>
- <span className="text-purple-500 tabular-nums">↑ {formatBytes(domain.totalUpload)}</span>
+ <span className="text-blue-500 tabular-nums whitespace-nowrap">↓ {formatBytes(domain.totalDownload)}</span>
+ <span className="text-purple-500 tabular-nums whitespace-nowrap">↑ {formatBytes(domain.totalUpload)}</span>
<span className="px-2 py-0.5 rounded-full bg-secondary text-muted-foreground font-medium">
{formatNumber(domain.totalConnections)} {t("conn")}
</span>
@@ -442,7 +466,7 @@ export function DomainStatsTable({
<DropdownMenuItem
key={size}
onClick={() => {
- setPageSize(size);
+ setEffectivePageSize(size);
setPage(1);
}}
className={pageSize === size ? "bg-primary/10" : ""}
@@ -452,12 +476,9 @@ export function DomainStatsTable({
))}
</DropdownMenuContent>
</DropdownMenu>
- <span className="text-sm text-muted-foreground">
- {t("total")} {filteredDomains.length}
- </span>
</div>
- <div className="flex items-center gap-2">
- <p className="text-xs text-muted-foreground">
+ <div className="flex flex-col sm:flex-row items-center gap-1 sm:gap-2">
+ <p className="text-xs text-muted-foreground whitespace-nowrap shrink-0">
{(page - 1) * pageSize + 1}-{Math.min(page * pageSize, filteredDomains.length)} / {filteredDomains.length}
</p>
<div className="flex items-center gap-1">
diff --git a/apps/web/components/stats-tables/expanded-details.tsx b/apps/web/components/stats-tables/expanded-details.tsx
index 5a0f4eb..c6646aa 100644
--- a/apps/web/components/stats-tables/expanded-details.tsx
+++ b/apps/web/components/stats-tables/expanded-details.tsx
@@ -1,8 +1,10 @@
"use client";
import { Globe, Link2, Loader2, Server, Waypoints } from "lucide-react";
+import { useTranslations } from "next-intl";
import { CountryFlag } from "@/components/country-flag";
import { Favicon } from "@/components/favicon";
+import { DomainPreview } from "@/components/domain-preview";
import { getDomainColor, getIPGradient } from "@/lib/stats-utils";
import { formatBytes, formatNumber } from "@/lib/utils";
import type { DomainStats, IPStats, ProxyTrafficStats } from "@clashmaster/shared";
@@ -398,6 +400,7 @@ export function IPExpandedDetails({
showProxyTraffic = true,
}: IPExpandedDetailsProps) {
const AssociatedDomainsTitleIcon = associatedDomainsIcon === "globe" ? Globe : Link2;
+ const domainsT = useTranslations("domains");
if (!richExpand) {
return (
@@ -470,7 +473,14 @@ export function IPExpandedDetails({
<div className="flex items-center justify-between mb-1.5">
<div className="flex items-center gap-1.5 min-w-0">
<Favicon domain={domain.domain} size="sm" className="shrink-0" />
- <span className="text-xs font-medium truncate">{domain.domain}</span>
+ <DomainPreview
+ className="flex-1"
+ triggerClassName="text-xs"
+ domain={domain.domain}
+ unknownLabel={domainsT("unknown")}
+ copyLabel={domainsT("copyDomain")}
+ copiedLabel={domainsT("copied")}
+ />
</div>
<span className="text-[11px] text-muted-foreground tabular-nums shrink-0">
{percent.toFixed(1)}%
diff --git a/apps/web/components/stats-tables/ip-stats-table.tsx b/apps/web/components/stats-tables/ip-stats-table.tsx
index de954e0..ef2d1dd 100644
--- a/apps/web/components/stats-tables/ip-stats-table.tsx
+++ b/apps/web/components/stats-tables/ip-stats-table.tsx
@@ -5,7 +5,6 @@ import { useQuery } from "@tanstack/react-query";
import {
ChevronLeft,
ChevronRight,
- Loader2,
Rows3,
ArrowUpDown,
ArrowDown,
@@ -38,6 +37,7 @@ import {
import { IPExpandedDetails } from "@/components/stats-tables/expanded-details";
import { ProxyChainBadge } from "@/components/proxy-chain-badge";
import { ExpandReveal } from "@/components/ui/expand-reveal";
+import { InsightTableSkeleton } from "@/components/ui/insight-skeleton";
import {
PAGE_SIZE_OPTIONS,
getIPGradient,
@@ -54,6 +54,8 @@ interface IPStatsTableProps {
loading?: boolean;
title?: string;
showHeader?: boolean;
+ pageSize?: PageSize;
+ onPageSizeChange?: (size: PageSize) => void;
activeBackendId?: number;
timeRange?: TimeRange;
sourceIP?: string;
@@ -68,6 +70,8 @@ export function IPStatsTable({
loading = false,
title,
showHeader = true,
+ pageSize: controlledPageSize,
+ onPageSizeChange,
activeBackendId,
timeRange,
sourceIP,
@@ -80,7 +84,8 @@ export function IPStatsTable({
const detailTimeRange = useStableTimeRange(timeRange);
const [page, setPage] = useState(1);
- const [pageSize, setPageSize] = useState<PageSize>(10);
+ const [internalPageSize, setInternalPageSize] = useState<PageSize>(10);
+ const pageSize = controlledPageSize ?? internalPageSize;
const [search, setSearch] = useState("");
const [sortKey, setSortKey] = useState<IPSortKey>("totalDownload");
const [sortOrder, setSortOrder] = useState<SortOrder>("desc");
@@ -91,6 +96,18 @@ export function IPStatsTable({
setExpandedIP(null);
}, [activeBackendId, sourceIP, sourceChain, richExpand]);
+ useEffect(() => {
+ setPage(1);
+ }, [pageSize]);
+
+ const setEffectivePageSize = (size: PageSize) => {
+ if (onPageSizeChange) {
+ onPageSizeChange(size);
+ return;
+ }
+ setInternalPageSize(size);
+ };
+
const expandedIPProxyQuery = useQuery({
queryKey: getIPProxyStatsQueryKey(expandedIP, activeBackendId, detailTimeRange, {
sourceIP,
@@ -219,9 +236,7 @@ export function IPStatsTable({
<CardContent className="p-0">
{loading ? (
- <div className="flex items-center justify-center py-12">
- <Loader2 className="h-5 w-5 animate-spin text-muted-foreground" />
- </div>
+ <InsightTableSkeleton />
) : filteredIPs.length === 0 ? (
<div className="text-center py-12 text-muted-foreground">
{search ? t("noResults") : t("noData")}
@@ -330,11 +345,11 @@ export function IPStatsTable({
)}
</div>
- <div className="col-span-2 text-right tabular-nums text-sm">
+ <div className="col-span-2 text-right tabular-nums text-sm whitespace-nowrap">
<span className="text-blue-500">{formatBytes(ip.totalDownload)}</span>
</div>
- <div className="col-span-1 text-right tabular-nums text-sm">
+ <div className="col-span-1 text-right tabular-nums text-sm whitespace-nowrap">
<span className="text-purple-500">{formatBytes(ip.totalUpload)}</span>
</div>
@@ -413,8 +428,8 @@ export function IPStatsTable({
</div>
<div className="flex items-center justify-between text-xs pl-[30px]">
- <span className="text-blue-500 tabular-nums">↓ {formatBytes(ip.totalDownload)}</span>
- <span className="text-purple-500 tabular-nums">↑ {formatBytes(ip.totalUpload)}</span>
+ <span className="text-blue-500 tabular-nums whitespace-nowrap">↓ {formatBytes(ip.totalDownload)}</span>
+ <span className="text-purple-500 tabular-nums whitespace-nowrap">↑ {formatBytes(ip.totalUpload)}</span>
<span className="px-2 py-0.5 rounded-full bg-secondary text-muted-foreground font-medium">
{formatNumber(ip.totalConnections)} {t("conn")}
</span>
@@ -467,7 +482,7 @@ export function IPStatsTable({
<DropdownMenuItem
key={size}
onClick={() => {
- setPageSize(size);
+ setEffectivePageSize(size);
setPage(1);
}}
className={pageSize === size ? "bg-primary/10" : ""}
@@ -477,12 +492,9 @@ export function IPStatsTable({
))}
</DropdownMenuContent>
</DropdownMenu>
- <span className="text-sm text-muted-foreground">
- {t("total")} {filteredIPs.length}
- </span>
</div>
- <div className="flex items-center gap-2">
- <p className="text-xs text-muted-foreground">
+ <div className="flex flex-col sm:flex-row items-center gap-1 sm:gap-2">
+ <p className="text-xs text-muted-foreground whitespace-nowrap shrink-0">
{(page - 1) * pageSize + 1}-{Math.min(page * pageSize, filteredIPs.length)} / {filteredIPs.length}
</p>
<div className="flex items-center gap-1">
diff --git a/apps/web/components/traffic-trend-chart.tsx b/apps/web/components/traffic-trend-chart.tsx
index bc186d3..026e7a5 100644
--- a/apps/web/components/traffic-trend-chart.tsx
+++ b/apps/web/components/traffic-trend-chart.tsx
@@ -10,7 +10,7 @@ import {
ResponsiveContainer,
CartesianGrid,
} from "recharts";
-import { Activity, Clock, BarChart3 } from "lucide-react";
+import { Activity, Clock, BarChart3, Loader2 } from "lucide-react";
import { useTranslations } from "next-intl";
import { Button } from "@/components/ui/button";
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
@@ -285,12 +285,12 @@ export const TrafficTrendChart = React.memo(
</CardHeader>
<CardContent className="pt-0">
- <div className="h-[200px] w-full">
- {isLoading && chartData.length === 0 ? (
- <div className="h-full flex items-center justify-center text-muted-foreground">
- <div className="flex items-center gap-2">
- <Activity className="w-4 h-4 animate-pulse" />
- {t("loading")}
+ <div className="relative h-[200px] w-full">
+ {chartData.length === 0 ? (
+ <div className="absolute inset-x-0 top-0 bottom-6 flex items-center justify-center text-muted-foreground">
+ <div className="inline-flex items-center gap-2 rounded-full border border-border/60 bg-background/90 px-3 py-1.5 shadow-sm">
+ <Loader2 className="w-4 h-4 animate-spin text-primary" />
+ <span className="text-xs font-medium">{t("loading")}</span>
</div>
</div>
) : (
@@ -365,6 +365,15 @@ export const TrafficTrendChart = React.memo(
</AreaChart>
</ResponsiveContainer>
)}
+
+ {isLoading && chartData.length > 0 && (
+ <div className="absolute inset-x-0 top-0 bottom-6 flex items-center justify-center bg-background/35 backdrop-blur-[1px] pointer-events-none">
+ <div className="inline-flex items-center gap-2 rounded-full border border-border/60 bg-background/90 px-3 py-1.5 shadow-sm">
+ <Loader2 className="w-4 h-4 animate-spin text-primary" />
+ <span className="text-xs font-medium">{t("loading")}</span>
+ </div>
+ </div>
+ )}
</div>
</CardContent>
</Card>
diff --git a/apps/web/components/ui/insight-skeleton.tsx b/apps/web/components/ui/insight-skeleton.tsx
new file mode 100644
index 0000000..6a58aaf
--- /dev/null
+++ b/apps/web/components/ui/insight-skeleton.tsx
@@ -0,0 +1,97 @@
+"use client";
+
+import { cn } from "@/lib/utils";
+
+export function InsightThreePanelSkeleton({ className }: { className?: string }) {
+ return (
+ <div className={cn("grid grid-cols-1 md:grid-cols-2 xl:grid-cols-12 gap-6", className)}>
+ <div className="min-w-0 md:col-span-1 xl:col-span-3 rounded-xl border border-dashed border-border/60 bg-card/30 p-4">
+ <div className="h-4 w-24 rounded bg-muted/60 animate-pulse" />
+ <div className="mt-4 flex justify-center">
+ <div className="h-28 w-28 rounded-full border-8 border-muted/60 animate-pulse" />
+ </div>
+ <div className="mt-4 space-y-2">
+ {[0, 1, 2].map((item) => (
+ <div key={item} className="h-7 rounded-lg bg-muted/60 animate-pulse" />
+ ))}
+ </div>
+ </div>
+
+ <div className="min-w-0 md:col-span-1 xl:col-span-4 rounded-xl border border-dashed border-border/60 bg-card/30 p-4">
+ <div className="h-4 w-28 rounded bg-muted/60 animate-pulse" />
+ <div className="mt-4 space-y-2.5">
+ {[0, 1, 2, 3].map((item) => (
+ <div key={item} className="h-12 rounded-xl bg-muted/60 animate-pulse" />
+ ))}
+ </div>
+ </div>
+
+ <div className="min-w-0 md:col-span-2 xl:col-span-5 rounded-xl border border-dashed border-border/60 bg-card/30 p-4">
+ <div className="h-4 w-32 rounded bg-muted/60 animate-pulse" />
+ <div className="mt-4 space-y-3">
+ {[70, 85, 55, 90, 65].map((width, idx) => (
+ <div key={idx} className="flex items-center gap-3">
+ <div className="h-3 w-20 rounded bg-muted/50 animate-pulse" />
+ <div
+ className="h-6 rounded bg-muted/60 animate-pulse"
+ style={{ width: `${width}%` }}
+ />
+ </div>
+ ))}
+ </div>
+ </div>
+ </div>
+ );
+}
+
+export function InsightChartSkeleton({ className }: { className?: string }) {
+ return (
+ <div
+ className={cn(
+ "h-[280px] rounded-xl border border-dashed border-border/60 bg-card/30 px-4 py-5",
+ className,
+ )}
+ >
+ <div className="space-y-3">
+ {[72, 88, 56, 92, 64].map((width, idx) => (
+ <div key={idx} className="flex items-center gap-3">
+ <div className="h-3 w-20 rounded bg-muted/50 animate-pulse" />
+ <div
+ className="h-6 rounded bg-muted/60 animate-pulse"
+ style={{ width: `${width}%` }}
+ />
+ </div>
+ ))}
+ </div>
+ </div>
+ );
+}
+
+export function InsightTableSkeleton({ className }: { className?: string }) {
+ return (
+ <div className={cn("px-4 py-6", className)}>
+ <div className="min-h-[180px] rounded-xl border border-dashed border-border/60 bg-card/30 px-4 py-5">
+ <div className="h-8 rounded-lg bg-muted/60 animate-pulse" />
+ <div className="mt-2 space-y-2">
+ {[0, 1, 2, 3, 4].map((item) => (
+ <div key={item} className="h-10 rounded-lg bg-muted/60 animate-pulse" />
+ ))}
+ </div>
+ </div>
+ </div>
+ );
+}
+
+export function InsightDetailSectionSkeleton({ className }: { className?: string }) {
+ return (
+ <div className={cn("rounded-xl border border-border/50 bg-card", className)}>
+ <div className="px-4 py-3 border-b border-border/50">
+ <div className="flex items-center gap-2">
+ <div className="h-8 w-28 rounded-lg bg-muted/60 animate-pulse" />
+ <div className="h-8 w-24 rounded-lg bg-muted/60 animate-pulse" />
+ </div>
+ </div>
+ <InsightTableSkeleton className="py-4" />
+ </div>
+ );
+}
diff --git a/apps/web/messages/en.json b/apps/web/messages/en.json
index 5757efd..1283c6c 100644
--- a/apps/web/messages/en.json
+++ b/apps/web/messages/en.json
@@ -1,7 +1,7 @@
{
"metadata": {
"title": "Clash Master - Traffic Analytics",
- "description": "Real-time traffic statistics and analytics for Clash"
+ "description": "Real-time network traffic statistics and analytics"
},
"nav": {
"overview": "Overview",
@@ -15,7 +15,7 @@
},
"header": {
"title": "Clash Master",
- "subtitle": "Clash traffic analytics dashboard"
+ "subtitle": "Modern network visualization dashboard"
},
"dashboard": {
"title": "Dashboard",
@@ -162,12 +162,15 @@
"ipCount": "IPs",
"proxy": "Proxy",
"proxyTraffic": "Proxy Traffic Breakdown",
- "associatedIPs": "Associated IP Addresses",
+
"domainsCount": "domains",
"showing": "Showing",
"of": "of",
"page": "page",
- "total": "Total"
+ "total": "Total",
+ "fullDomain": "Full domain",
+ "copyDomain": "Copy",
+ "copied": "Copied"
},
"ips": {
"title": "Top IP Addresses",
@@ -274,7 +277,7 @@
"title": "About",
"version": "Version",
"projectName": "Clash Master",
- "description": "Clash traffic analytics dashboard",
+ "description": "Modern network visualization dashboard",
"github": "GitHub",
"openSource": "Clash Master",
"license": "MIT License",
diff --git a/apps/web/messages/zh.json b/apps/web/messages/zh.json
index 922a51b..0030316 100644
--- a/apps/web/messages/zh.json
+++ b/apps/web/messages/zh.json
@@ -1,7 +1,7 @@
{
"metadata": {
"title": "Clash Master - 流量分析",
- "description": "Clash 实时流量统计与分析"
+ "description": "实时网络流量统计与分析"
},
"nav": {
"overview": "概览",
@@ -15,7 +15,7 @@
},
"header": {
"title": "Clash Master",
- "subtitle": "现代 Clash 可视化看板"
+ "subtitle": "现代网络可视化分析面板"
},
"dashboard": {
"title": "仪表盘",
@@ -161,12 +161,15 @@
"ipCount": "IP数",
"proxy": "代理节点",
"proxyTraffic": "代理节点流量明细",
- "associatedIPs": "关联 IP 地址",
+
"domainsCount": "个域名",
"showing": "显示",
"of": "共",
"page": "页",
- "total": "总计"
+ "total": "总计",
+ "fullDomain": "完整域名",
+ "copyDomain": "复制",
+ "copied": "已复制"
},
"ips": {
"title": "热门 IP 地址",
@@ -273,7 +276,7 @@
"title": "关于",
"version": "版本",
"projectName": "Clash Master",
- "description": "现代 Clash 可视化看板",
+ "description": "现代的网络可视化分析面板",
"github": "GitHub",
"openSource": "开源项目",
"license": "MIT 许可证",
@@ -326,8 +329,8 @@
},
"backend": {
"title": "设置",
- "firstTimeTitle": "配置 Clash 后端",
- "firstTimeDescription": "请输入您的 Clash 连接信息以开始监控流量",
+ "firstTimeTitle": "配置网关后端",
+ "firstTimeDescription": "请输入您的网络网关连接信息以开始监控流量",
"description": "管理后端连接和数据库",
"backendsTab": "后端管理",
"databaseTab": "数据库",
diff --git a/apps/web/package.json b/apps/web/package.json
index fc94a88..8a19c15 100644
--- a/apps/web/package.json
+++ b/apps/web/package.json
@@ -1,6 +1,7 @@
{
"name": "@clashmaster/web",
"version": "1.0.1",
+ "description": "A modern and elegant dashboard for network traffic visualization and analysis.",
"private": true,
"scripts": {
"dev": "next dev -p 3000",
@@ -16,6 +17,7 @@
"@radix-ui/react-radio-group": "^1.3.8",
"@radix-ui/react-scroll-area": "^1.2.10",
"@tanstack/react-query": "^5.90.20",
+ "@types/react-copy-to-clipboard": "^5.0.7",
"@xyflow/react": "^12.10.0",
"class-variance-authority": "^0.7.1",
"clsx": "^2.1.1",
@@ -29,6 +31,7 @@
"next-themes": "^0.4.6",
"radix-ui": "^1.4.3",
"react": "^19.2.0",
+ "react-copy-to-clipboard": "^5.1.0",
"react-day-picker": "^9.13.1",
"react-dom": "^19.2.0",
"react-simple-maps": "^3.0.0",
diff --git a/package.json b/package.json
index 1f0dba4..d7716d4 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,7 @@
{
"name": "clash-master",
- "version": "1.1.4",
+ "version": "1.1.5",
+ "description": "A modern and elegant dashboard for network traffic visualization and analysis.",
"private": true,
"workspaces": [
"apps/*",
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 39efa04..c41b678 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -72,6 +72,9 @@ importers:
'@tanstack/react-query':
specifier: ^5.90.20
version: 5.90.20([email protected])
+ '@types/react-copy-to-clipboard':
+ specifier: ^5.0.7
+ version: 5.0.7
'@xyflow/react':
specifier: ^12.10.0
@@ -111,6 +114,9 @@ importers:
react:
specifier: ^19.2.0
version: 19.2.4
+ react-copy-to-clipboard:
+ specifier: ^5.1.0
+ version: 5.1.0([email protected])
react-day-picker:
specifier: ^9.13.1
version: 9.13.1([email protected])
@@ -2299,6 +2305,9 @@ packages:
resolution: {integrity: sha512-PD03/U8g1F9T9MI+1OBisaIARhSzeidsUjQaf51fOxrfjeiKN9bLVO06lHuHYjxdnqLWJijJHfqXPSJri2EM2A==}
+ '@types/[email protected]':
+ resolution: {integrity: sha512-Gft19D+as4M+9Whq1oglhmK49vqPhcLzk8WfvfLvaYMIPYanyfLy0+CwFucMJfdKoSFyySPmkkWn8/E6voQXjQ==}
+
resolution: {integrity: sha512-jp2L/eY6fn+KgVVQAOqYItbF0VY/YApe5Mz2F0aykSO8gx31bYCZyvSeYxCHKvzHG5eZjc+zyaS5BrBWya2+kQ==}
peerDependencies:
@@ -2778,6 +2787,9 @@ packages:
resolution: {integrity: sha512-yki5XnKuf750l50uGTllt6kKILY4nQ1eNIQatoXEByZ5dWgnKqbnqmTrBE5B4N7lrMJKQ2ytWMiTO2o0v6Ew/w==}
engines: {node: '>= 0.6'}
+ resolution: {integrity: sha512-2KV8NhB5JqC3ky0r9PMCAZKbUHSwtEo4CwCs0KXgruG43gX5PMqDEBbVU4OUzw2MuAWUfsuFmWvEKG5QRfSnJA==}
+
resolution: {integrity: sha512-OM4cAF3D6VtH/WkLtWvyNC56EZVXsZdU3iqaMG2B4WvYrlqU831pc4UtG5yp0sE9z8Y02wVN7PjW5Zf9Gt0f1Q==}
@@ -4092,6 +4104,11 @@ packages:
resolution: {integrity: sha512-y3bGgqKj3QBdxLbLkomlohkvsA8gdAiUQlSBJnBhfn+BPxg4bc62d8TcBW15wavDfgexCgccckhcZvywyQYPOw==}
hasBin: true
+ resolution: {integrity: sha512-k61RsNgAayIJNoy9yDsYzDe/yAZAzEbEgcz3DZMhF686LEyukcE1hzurxe85JandPUG+yTfGVFzuEw3xt8WP/A==}
+ peerDependencies:
+ react: ^15.3.0 || 16 || 17 || 18
+
resolution: {integrity: sha512-9nx2lBBJ0VZw5jJekId3DishwnJLiqY1Me1JvCrIyqbWwcflBTVaEkiK+w1bre5oMNWYo722eu+8UAMXWMqktw==}
engines: {node: '>=18'}
@@ -4524,6 +4541,9 @@ packages:
resolution: {integrity: sha512-/m8M+2BJUpoJdgAHoG+baCwBT+tf2VraSfkBgl0Y00qIWt41DJ8R5B8nsEw0I58YwF5IZH6z24/2TobDKnqSWw==}
engines: {node: '>=12'}
+ resolution: {integrity: sha512-BiZS+C1OS8g/q2RRbJmy59xpyghNBqrr6k5L/uKBGRsTfxmu3ffiRnd8mlGPUVayg8pvfi5urfnu8TU7DVOkLQ==}
+
resolution: {integrity: sha512-605uxS6bcYxGXw9qi62XyrV6Q3xwbndjachmNxu8HWTtVPxZfEJN9fd/SZS1Q54Sn2y0TMyMxFj/cJINqGHrKw==}
hasBin: true
@@ -7029,6 +7049,10 @@ snapshots:
dependencies:
undici-types: 6.21.0
+ '@types/[email protected]':
+ dependencies:
+ '@types/react': 19.2.11
+
dependencies:
'@types/react': 19.2.11
@@ -7568,6 +7592,10 @@ snapshots:
+ dependencies:
+ toggle-selection: 1.0.6
+
dependencies:
browserslist: 4.28.1
@@ -9095,6 +9123,12 @@ snapshots:
minimist: 1.2.8
strip-json-comments: 2.0.1
+ dependencies:
+ copy-to-clipboard: 3.3.3
+ prop-types: 15.8.1
+ react: 19.2.4
+
dependencies:
'@date-fns/tz': 1.4.1
@@ -9596,6 +9630,8 @@ snapshots:
+
dependencies:
commander: 2.20.3