improve home page

This commit is contained in:
csehviktor
2025-07-06 03:33:41 +02:00
parent 924187fea1
commit 6267733086
5 changed files with 150 additions and 4 deletions

28
ui/src/services/utils.ts Normal file
View File

@@ -0,0 +1,28 @@
import { UptimeMessage } from "@/services/types";
export function isAgentOnline(data: UptimeMessage): boolean {
const timeDiff = new Date().getTime() - new Date(data.last_seen).getTime();
return timeDiff < 10000;
}
export const formatRelativeTime = (timestamp: string): string => {
const now = new Date();
const past = new Date(timestamp);
const diffInSeconds = Math.floor((now.getTime() - past.getTime()) / 1000);
if (diffInSeconds < 5) {
return "now";
} else if (diffInSeconds < 60) {
return `${diffInSeconds}s ago`;
} else if (diffInSeconds < 3600) {
const minutes = Math.floor(diffInSeconds / 60);
return `${minutes}m ago`;
} else if (diffInSeconds < 86400) {
const hours = Math.floor(diffInSeconds / 3600);
return `${hours}h ago`;
} else {
const days = Math.floor(diffInSeconds / 86400);
return `${days}d ago`;
}
};