feat(ui): metrikleri odaklanma ve gezinme durumunda yenile
Metriklerin güncel kalması için pencere odaklanıldığında ve sayfa gezinildiğinde verilerin yeniden yüklenmesi eklendi. Backend deployment servisinde tip tanımları güncellendi.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { useEffect, useMemo, useState } from "react";
|
||||
import { useNavigate } from "react-router-dom";
|
||||
import { useCallback, useEffect, useMemo, useState } from "react";
|
||||
import { useLocation, useNavigate } from "react-router-dom";
|
||||
import {
|
||||
Line,
|
||||
LineChart,
|
||||
@@ -18,6 +18,7 @@ import { JobStatusBadge } from "../components/JobStatusBadge";
|
||||
import { RepoIcon } from "../components/RepoIcon";
|
||||
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
||||
import { faClockRotateLeft, faListCheck, faFlaskVial, faRocket } from "@fortawesome/free-solid-svg-icons";
|
||||
import { useAuth } from "../providers/auth-provider";
|
||||
|
||||
function formatDuration(ms?: number) {
|
||||
if (!ms || Number.isNaN(ms)) return "-";
|
||||
@@ -41,9 +42,14 @@ export function HomePage() {
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const { jobStreams } = useLiveData();
|
||||
const { token } = useAuth();
|
||||
const navigate = useNavigate();
|
||||
const location = useLocation();
|
||||
|
||||
useEffect(() => {
|
||||
const loadMetrics = useCallback(() => {
|
||||
if (!token) return;
|
||||
setLoading(true);
|
||||
setError(null);
|
||||
Promise.allSettled([fetchJobMetrics(), fetchDeploymentMetrics()])
|
||||
.then(([jobResult, deployResult]) => {
|
||||
if (jobResult.status === "fulfilled") {
|
||||
@@ -65,7 +71,25 @@ export function HomePage() {
|
||||
}
|
||||
})
|
||||
.finally(() => setLoading(false));
|
||||
}, []);
|
||||
}, [token]);
|
||||
|
||||
useEffect(() => {
|
||||
loadMetrics();
|
||||
}, [loadMetrics, location.key]);
|
||||
|
||||
useEffect(() => {
|
||||
const handleFocus = () => {
|
||||
if (document.visibilityState === "visible") {
|
||||
loadMetrics();
|
||||
}
|
||||
};
|
||||
window.addEventListener("focus", handleFocus);
|
||||
document.addEventListener("visibilitychange", handleFocus);
|
||||
return () => {
|
||||
window.removeEventListener("focus", handleFocus);
|
||||
document.removeEventListener("visibilitychange", handleFocus);
|
||||
};
|
||||
}, [loadMetrics]);
|
||||
|
||||
const chartData = useMemo(() => {
|
||||
if (!metrics) {
|
||||
|
||||
Reference in New Issue
Block a user