Compare commits
4
Commits
v0.8.1
..
803c346854
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
803c346854 | ||
|
|
f9f9af0fc9 | ||
|
|
9f51ea5e84 | ||
|
|
d190a55bf2 |
No files matched your search
+974
-91
File diff suppressed because it is too large.
Load diff
@@ -179,7 +179,7 @@ export function DashboardPage() {
|
||||
</div>
|
||||
{loadStats && !loading && (
|
||||
<span className="hidden text-[10px] text-content-muted sm:inline">
|
||||
{t("loadStats", { ms: loadStats.ms, kb: loadStats.kb })}
|
||||
{t("loadStats", { ms: loadStats.ms })}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { useCallback, useEffect, useState } from "react";
|
||||
import { useCallback, useEffect, useRef, useState } from "react";
|
||||
import { invoke } from "@tauri-apps/api/core";
|
||||
import type { SummaryResult } from "../types/dashboard";
|
||||
|
||||
@@ -23,9 +23,12 @@ export function useDashboard() {
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
/** Round-trip timing for the last get_summary call (user-perceived lag). */
|
||||
const [loadStats, setLoadStats] = useState<{ ms: number; kb: number } | null>(null);
|
||||
const [loadStats, setLoadStats] = useState<{ ms: number } | null>(null);
|
||||
// Generation counter: stale responses (superseded range / unmounted) are dropped.
|
||||
const genRef = useRef(0);
|
||||
|
||||
const refresh = useCallback(async (force = false) => {
|
||||
const gen = ++genRef.current;
|
||||
setLoading(true);
|
||||
setError(null);
|
||||
const start = performance.now();
|
||||
@@ -34,16 +37,15 @@ export function useDashboard() {
|
||||
range,
|
||||
refresh: force,
|
||||
});
|
||||
if (genRef.current !== gen) return;
|
||||
setData(result);
|
||||
setLoadStats({
|
||||
ms: Math.round(performance.now() - start),
|
||||
kb: Math.round(JSON.stringify(result).length / 1024),
|
||||
});
|
||||
setLoadStats({ ms: Math.round(performance.now() - start) });
|
||||
} catch (err) {
|
||||
if (genRef.current !== gen) return;
|
||||
const msg = err instanceof Error ? err.message : String(err);
|
||||
setError(msg);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
if (genRef.current === gen) setLoading(false);
|
||||
}
|
||||
}, [range]);
|
||||
|
||||
@@ -51,6 +53,13 @@ export function useDashboard() {
|
||||
refresh();
|
||||
}, [refresh]);
|
||||
|
||||
// Ignore late responses after unmount.
|
||||
useEffect(() => {
|
||||
return () => {
|
||||
genRef.current += 1;
|
||||
};
|
||||
}, []);
|
||||
|
||||
const changeRange = useCallback((next: DashboardRange) => {
|
||||
setRange(next);
|
||||
try {
|
||||
|
||||
+1
-1
@@ -257,7 +257,7 @@ export const enTranslations: Record<TranslationKey, string> = {
|
||||
scanning: "Scanning…",
|
||||
refresh: "Refresh",
|
||||
refreshing: "Refreshing…",
|
||||
loadStats: "Loaded in {ms} ms · {kb} KB payload",
|
||||
loadStats: "Loaded in {ms} ms",
|
||||
refreshed: "Refreshed",
|
||||
cancel: "Cancel",
|
||||
confirmDeleteTitle: "Delete session forever?",
|
||||
|
||||
+1
-1
@@ -249,7 +249,7 @@ export const zhTranslations = {
|
||||
scanning: "扫描中…",
|
||||
refresh: "刷新",
|
||||
refreshing: "刷新中…",
|
||||
loadStats: "加载 {ms} ms · 数据 {kb} KB",
|
||||
loadStats: "加载 {ms} ms",
|
||||
refreshed: "已刷新",
|
||||
cancel: "取消",
|
||||
confirmDeleteTitle: "永久删除会话?",
|
||||
|
||||
Reference in new issue
Block a user