21 lines
643 B
TypeScript
21 lines
643 B
TypeScript
import { useMemo } from "react";
|
|
|
|
/**
|
|
* Returns true when a stream is within the last 10% of its retention window.
|
|
* For example, with 24h retention, this fires when < 2.4h remain.
|
|
*/
|
|
export function useExpiringSoon(
|
|
lastChildCreatedAt: Date | undefined,
|
|
retentionHours: number,
|
|
): boolean {
|
|
return useMemo(() => {
|
|
if (!lastChildCreatedAt) return false;
|
|
|
|
const retentionMs = retentionHours * 60 * 60 * 1000;
|
|
const expiresAt = lastChildCreatedAt.getTime() + retentionMs;
|
|
const remaining = expiresAt - Date.now();
|
|
|
|
return remaining > 0 && remaining < retentionMs * 0.1;
|
|
}, [lastChildCreatedAt, retentionHours]);
|
|
}
|