feat: label stale evidence data
This commit is contained in:
@@ -34,7 +34,7 @@ export type MediaAsset = { id: string; entity_type: "fish" | "waterbody" | "tack
|
||||
|
||||
export const spotPath = (item: Pick<Activity, "waterbody_slug" | "x" | "y">) => `/spots/${item.waterbody_slug}-${item.x}x${item.y}`;
|
||||
|
||||
export { activityLevel, ago, kg, plural } from "./presentation";
|
||||
export { activityLevel, ago, freshnessStatus, kg, plural } from "./presentation";
|
||||
|
||||
const base = process.env.API_INTERNAL_URL || import.meta.env.API_INTERNAL_URL || "http://localhost:8000";
|
||||
|
||||
|
||||
@@ -20,3 +20,10 @@ export function ago(value: string) {
|
||||
const minutes = Math.max(0, Math.round((Date.now() - new Date(value).getTime()) / 60000));
|
||||
return minutes < 60 ? `${minutes} мин назад` : `${Math.floor(minutes / 60)} ч назад`;
|
||||
}
|
||||
|
||||
export function freshnessStatus(value: string | null | undefined, now = Date.now()): "fresh" | "stale" | "unknown" {
|
||||
if (!value) return "unknown";
|
||||
const timestamp = new Date(value).getTime();
|
||||
if (!Number.isFinite(timestamp)) return "unknown";
|
||||
return now - timestamp > 48 * 60 * 60 * 1000 ? "stale" : "fresh";
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user