Skip to content

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

feat: Implement `useResponsiveItemCount` for dynamic overview list display and add traffic progress bars to top domains.

luoleid6a60f1313c4
diff --git a/apps/web/app/[locale]/dashboard/components/header/index.tsx b/apps/web/app/[locale]/dashboard/components/header/index.tsx
index f19b08c..6d080c9 100644
--- a/apps/web/app/[locale]/dashboard/components/header/index.tsx
+++ b/apps/web/app/[locale]/dashboard/components/header/index.tsx
@@ -34,11 +34,6 @@ import {
TooltipProvider,
TooltipTrigger,
} from "@/components/ui/tooltip";
-import {
- Popover,
- PopoverContent,
- PopoverTrigger,
-} from "@/components/ui/popover";
import { Switch } from "@/components/ui/switch";
import { TimeRangePicker, LanguageSwitcher, ThemeToggle, ClientOnly } from "@/components/common";
import { cn } from "@/lib/utils";
@@ -414,52 +409,36 @@ export function Header({
</div>
)}
- {/* Mobile: Backend warning in top actions */}
- {backendStatus === "unhealthy" && (
- <div className="sm:hidden">
- <Popover>
- <PopoverTrigger asChild>
- <Button
- 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"
- >
- <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>
- </PopoverTrigger>
- <PopoverContent
- align="end"
- side="bottom"
- 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">
- <p className="text-sm font-medium text-rose-600 dark:text-rose-400">
- {dashboardT("backendUnavailable")}
- </p>
- <p className="text-xs text-muted-foreground">
- {backendStatusHint ||
- dashboardT("backendUnavailableHint")}
- </p>
- </div>
- </div>
- </PopoverContent>
- </Popover>
- </div>
- )}
+
{/* Mobile: More Options Dropdown */}
<div className="sm:hidden">
<DropdownMenu>
<DropdownMenuTrigger asChild>
- <Button variant="ghost" size="icon" className="h-9 w-9">
+ <Button variant="ghost" size="icon" className="h-9 w-9 relative">
+ {backendStatus === "unhealthy" && (
+ <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]" />
+ )}
<MoreVertical className="w-5 h-5" />
</Button>
</DropdownMenuTrigger>
<DropdownMenuContent align="end" className="w-56">
+ {/* Backend Warning - show when unhealthy */}
+ {backendStatus === "unhealthy" && (
+ <>
+ <DropdownMenuLabel className="flex items-center gap-2 text-rose-600 dark:text-rose-400">
+ <AlertTriangle className="w-4 h-4" />
+ {dashboardT("backendUnavailable")}
+ </DropdownMenuLabel>
+ <div className="px-2 py-1.5">
+ <p className="text-xs text-muted-foreground">
+ {backendStatusHint || dashboardT("backendUnavailableHint")}
+ </p>
+ </div>
+ <DropdownMenuSeparator />
+ </>
+ )}
+
{/* Showcase Mode Indicator */}
{isShowcase && (
<>
@@ -470,7 +449,6 @@ export function Header({
<DropdownMenuSeparator />
</>
)}
-
{/* Auto Refresh Toggle */}
<DropdownMenuLabel className="flex items-center gap-2">
<RefreshCw className="w-4 h-4" />
@@ -498,6 +476,12 @@ export function Header({
</DropdownMenuItem>
<DropdownMenuSeparator />
+ {/* Manual Refresh */}
+ <DropdownMenuItem onClick={onRefresh} disabled={isLoading}>
+ <RefreshCw className={cn("w-4 h-4 mr-2", isLoading && "animate-spin")} />
+ {dashboardT("refresh")}
+ </DropdownMenuItem>
+ <DropdownMenuSeparator />
{/* Theme Selection */}
<DropdownMenuLabel className="flex items-center gap-2">
{theme === "dark" ? (
@@ -585,20 +569,21 @@ export function Header({
</DropdownMenu>
</div>
- {/* Refresh Button - show when auto refresh is off or backend is unhealthy */}
+ {/* Refresh Button - show when auto refresh is off or backend is unhealthy (desktop only) */}
{(!autoRefresh || backendStatus === "unhealthy") && (
<Button
variant="outline"
size="icon"
onClick={onRefresh}
disabled={isLoading}
- className="h-9 w-9"
+ className="h-9 w-9 hidden sm:flex"
>
<RefreshCw
className={cn("w-4 h-4", isLoading && "animate-spin")}
/>
</Button>
)}
+
</div>
</div>
{/* Transition progress bar - sits at the bottom edge of the header */}
diff --git a/apps/web/components/features/rules/rule-chain-flow.tsx b/apps/web/components/features/rules/rule-chain-flow.tsx
index 25f5add..81c0799 100644
--- a/apps/web/components/features/rules/rule-chain-flow.tsx
+++ b/apps/web/components/features/rules/rule-chain-flow.tsx
@@ -1017,6 +1017,7 @@ function UnifiedRuleChainFlowInner({
const element = target as HTMLElement & {
webkitRequestFullscreen?: () => Promise<void> | void;
};
+
const fullscreenElement =
doc.fullscreenElement ?? doc.webkitFullscreenElement ?? null;
diff --git a/apps/web/components/overview/top-countries-simple.tsx b/apps/web/components/overview/top-countries-simple.tsx
index 1e179d6..190fcc1 100644
--- a/apps/web/components/overview/top-countries-simple.tsx
+++ b/apps/web/components/overview/top-countries-simple.tsx
@@ -6,6 +6,7 @@ import { useTranslations, useLocale } from "next-intl";
import { Button } from "@/components/ui/button";
import { CountryFlag } from "@/components/features/countries";
import { formatBytes, formatNumber, cn } from "@/lib/utils";
+import { useResponsiveItemCount } from "@/lib/hooks/use-responsive-item-count";
import type { CountryStats } from "@neko-master/shared";
interface TopCountriesSimpleProps {
@@ -52,6 +53,7 @@ export const TopCountriesSimple = React.memo(function TopCountriesSimple({
}: TopCountriesSimpleProps) {
const t = useTranslations("topCountries");
const locale = useLocale();
+ const itemCount = useResponsiveItemCount();
const sortedCountries = useMemo(() => {
if (!countries?.length) return [];
@@ -62,8 +64,8 @@ export const TopCountriesSimple = React.memo(function TopCountriesSimple({
}
return b.totalConnections - a.totalConnections;
})
- .slice(0, 6);
- }, [countries, sortBy]);
+ .slice(0, itemCount);
+ }, [countries, sortBy, itemCount]);
const hasData = sortedCountries.length > 0;
@@ -184,8 +186,8 @@ export const TopCountriesSimple = React.memo(function TopCountriesSimple({
</div>
);
}) : isLoading ? (
- // Skeleton loading state - 6 items with 2 rows each to match actual content height
- Array.from({ length: 6 }).map((_, i) => (
+ // Skeleton loading state - dynamic items with 2 rows each to match actual content height
+ Array.from({ length: itemCount }).map((_, i) => (
<div
key={i}
className="p-2.5 rounded-xl border border-border/50 bg-card/50"
diff --git a/apps/web/components/overview/top-domains-simple.tsx b/apps/web/components/overview/top-domains-simple.tsx
index 5323ffb..1ba7e09 100644
--- a/apps/web/components/overview/top-domains-simple.tsx
+++ b/apps/web/components/overview/top-domains-simple.tsx
@@ -6,6 +6,7 @@ import { useTranslations } from "next-intl";
import { Button } from "@/components/ui/button";
import { cn, formatBytes, formatNumber } from "@/lib/utils";
import { useSettings, getFaviconUrl } from "@/lib/settings";
+import { useResponsiveItemCount } from "@/lib/hooks/use-responsive-item-count";
import type { DomainStats } from "@neko-master/shared";
interface TopDomainsSimpleProps {
@@ -30,7 +31,7 @@ export const TopDomainsSimple = React.memo(function TopDomainsSimple({
const t = useTranslations("topDomains");
const { settings } = useSettings();
const faviconDisabled = settings.faviconProvider === "off";
-
+ const itemCount = useResponsiveItemCount();
const sortedDomains = useMemo(() => {
if (!domains?.length) return [];
@@ -45,11 +46,19 @@ export const TopDomainsSimple = React.memo(function TopDomainsSimple({
}
});
- return sorted.slice(0, 6);
- }, [domains, sortBy]);
-
+ return sorted.slice(0, itemCount);
+ }, [domains, sortBy, itemCount]);
const hasData = sortedDomains.length > 0;
+ const maxTotal = useMemo(() => {
+ if (!sortedDomains.length) return 1;
+ return Math.max(...sortedDomains.map(d => d.totalDownload + d.totalUpload));
+ }, [sortedDomains]);
+
+ const totalTraffic = useMemo(() => {
+ if (!domains?.length) return 1;
+ return domains.reduce((sum, d) => sum + d.totalDownload + d.totalUpload, 0);
+ }, [domains]);
// Get favicon URL using current provider
const getFaviconForDomain = (domain: string) => {
return getFaviconUrl(domain, settings.faviconProvider);
@@ -101,6 +110,8 @@ export const TopDomainsSimple = React.memo(function TopDomainsSimple({
<div className="space-y-2 flex-1">
{hasData ? sortedDomains.map((domain, index) => {
const total = domain.totalDownload + domain.totalUpload;
+ const barPercent = (total / maxTotal) * 100;
+ const sharePercent = (total / totalTraffic) * 100;
const badgeColor = index === 0
? "bg-amber-100 text-amber-700 dark:bg-amber-900/30 dark:text-amber-400"
: index === 1
@@ -108,13 +119,12 @@ export const TopDomainsSimple = React.memo(function TopDomainsSimple({
: index === 2
? "bg-orange-100 text-orange-700 dark:bg-orange-900/30 dark:text-orange-400"
: "bg-muted text-muted-foreground";
-
return (
<div
key={domain.domain}
className="p-2.5 rounded-xl border border-border/50 bg-card/50 hover:bg-card transition-colors"
>
- <div className="flex items-center gap-2">
+ <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
@@ -153,38 +163,61 @@ export const TopDomainsSimple = React.memo(function TopDomainsSimple({
</span>
</div>
- {/* Stats */}
- <div className="pl-7 mt-1">
- <div className="flex items-center gap-2 text-xs text-muted-foreground">
+ {/* Row 2: Progress bar + Stats */}
+ <div className="pl-7 space-y-1.5">
+ {/* Progress bar */}
+ <div className="h-1.5 rounded-full bg-muted overflow-hidden flex">
+ <div
+ className="h-full bg-blue-500 dark:bg-blue-400"
+ style={{ width: `${(domain.totalDownload / total) * barPercent}%` }}
+ />
+ <div
+ className="h-full bg-purple-500 dark:bg-purple-400"
+ style={{ width: `${(domain.totalUpload / total) * barPercent}%` }}
+ />
+ </div>
+ {/* Stats */}
+ <div className="flex items-center justify-between text-xs text-muted-foreground">
+ <div className="flex items-center gap-2">
<span className="text-blue-500 dark:text-blue-400">↓ {formatBytes(domain.totalDownload)}</span>
<span className="text-purple-500 dark:text-purple-400">↑ {formatBytes(domain.totalUpload)}</span>
- <span className="flex items-center gap-1 tabular-nums">
- <Link2 className="w-3 h-3" />
- {formatNumber(domain.totalConnections)}
+ <span className="flex items-center gap-1 tabular-nums">
+ <Link2 className="w-3 h-3" />
+ {formatNumber(domain.totalConnections)}
+ </span>
+ </div>
+ <span className="tabular-nums">
+ {sharePercent.toFixed(1)}%
</span>
</div>
</div>
</div>
);
}) : isLoading ? (
- // Skeleton loading state - 6 items with 2 rows each to match actual content height
- Array.from({ length: 6 }).map((_, i) => (
+ // Skeleton loading state - dynamic items with 2 rows each to match actual content height
+ Array.from({ length: itemCount }).map((_, i) => (
<div
key={i}
className="p-2.5 rounded-xl border border-border/50 bg-card/50"
>
{/* Row 1: Rank + Icon + Name + Total */}
- <div className="flex items-center gap-2">
+ <div className="flex items-center gap-2 mb-1.5">
<div className="w-5 h-5 rounded-md bg-muted/60 animate-pulse shrink-0" />
<div className="w-5 h-5 rounded bg-muted/60 animate-pulse shrink-0" />
<div className="flex-1 h-4 bg-muted/60 rounded animate-pulse" />
<div className="w-12 h-4 bg-muted/60 rounded animate-pulse shrink-0" />
</div>
- {/* Row 2: Stats placeholder to match actual height - use mt-1 like real data */}
- <div className="pl-7 mt-1 flex items-center gap-2">
- <div className="w-16 h-3 bg-muted/60 rounded animate-pulse" />
- <div className="w-16 h-3 bg-muted/60 rounded animate-pulse" />
- <div className="w-12 h-3 bg-muted/60 rounded animate-pulse" />
+ {/* Row 2: Progress bar + Stats placeholder */}
+ <div className="pl-7 space-y-1.5">
+ <div className="h-1.5 rounded-full bg-muted/60 animate-pulse" />
+ <div className="flex items-center justify-between">
+ <div className="flex items-center gap-2">
+ <div className="w-14 h-3 bg-muted/60 rounded animate-pulse" />
+ <div className="w-14 h-3 bg-muted/60 rounded animate-pulse" />
+ <div className="w-10 h-3 bg-muted/60 rounded animate-pulse" />
+ </div>
+ <div className="w-8 h-3 bg-muted/60 rounded animate-pulse" />
+ </div>
</div>
</div>
))
diff --git a/apps/web/components/overview/top-proxies-simple.tsx b/apps/web/components/overview/top-proxies-simple.tsx
index 33d5c9d..85e3272 100644
--- a/apps/web/components/overview/top-proxies-simple.tsx
+++ b/apps/web/components/overview/top-proxies-simple.tsx
@@ -6,6 +6,7 @@ import { useTranslations } from "next-intl";
import { Button } from "@/components/ui/button";
import { cn, formatBytes, formatNumber } from "@/lib/utils";
import { useIsWindows } from "@/lib/hooks/use-is-windows";
+import { useResponsiveItemCount } from "@/lib/hooks/use-responsive-item-count";
import type { ProxyStats } from "@neko-master/shared";
interface TopProxiesSimpleProps {
@@ -35,6 +36,7 @@ export const TopProxiesSimple = React.memo(
}: TopProxiesSimpleProps) {
const t = useTranslations("topProxies");
const isWindows = useIsWindows();
+ const itemCount = useResponsiveItemCount();
const sortedProxies = useMemo(() => {
if (!proxies?.length) return [];
@@ -49,8 +51,8 @@ export const TopProxiesSimple = React.memo(
}
});
- return sorted.slice(0, 6);
- }, [proxies, sortBy]);
+ return sorted.slice(0, itemCount);
+ }, [proxies, sortBy, itemCount]);
const hasData = sortedProxies.length > 0;
@@ -189,8 +191,8 @@ export const TopProxiesSimple = React.memo(
</div>
);
}) : isLoading ? (
- // Skeleton loading state - 6 items with 2 rows each to match actual content height
- Array.from({ length: 6 }).map((_, i) => (
+ // Skeleton loading state - dynamic items with 2 rows each to match actual content height
+ Array.from({ length: itemCount }).map((_, i) => (
<div
key={i}
className="p-2.5 rounded-xl border border-border/50 bg-card/50"
diff --git a/apps/web/lib/hooks/use-responsive-item-count.ts b/apps/web/lib/hooks/use-responsive-item-count.ts
new file mode 100644
index 0000000..3b32b61
--- /dev/null
+++ b/apps/web/lib/hooks/use-responsive-item-count.ts
@@ -0,0 +1,46 @@
+"use client";
+
+import { useState, useEffect } from "react";
+
+interface UseResponsiveItemCountOptions {
+ /** Default/base number of items to show (mobile/small screens) */
+ defaultCount?: number;
+ /** Number of items to show on large screens */
+ largeScreenCount?: number;
+ /** Minimum viewport height to be considered "large screen" (in pixels) */
+ minHeightThreshold?: number;
+}
+
+/**
+ * Hook to determine how many items to display based on viewport height.
+ * Useful for responsive list/grid components that should show more content
+ * on larger screens while keeping a compact view on smaller screens.
+ */
+export function useResponsiveItemCount({
+ defaultCount = 5,
+ largeScreenCount = 10,
+ minHeightThreshold = 1100,
+}: UseResponsiveItemCountOptions = {}) {
+ const [itemCount, setItemCount] = useState(defaultCount);
+
+ useEffect(() => {
+ const updateCount = () => {
+ const viewportHeight = window.innerHeight;
+ setItemCount(
+ viewportHeight >= minHeightThreshold ? largeScreenCount : defaultCount
+ );
+ };
+
+ // Initial check
+ updateCount();
+
+ // Listen for resize events
+ window.addEventListener("resize", updateCount);
+
+ return () => {
+ window.removeEventListener("resize", updateCount);
+ };
+ }, [defaultCount, largeScreenCount, minHeightThreshold]);
+
+ return itemCount;
+}