show indicator of stream expiring soon
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
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]);
|
||||
}
|
||||
Reference in New Issue
Block a user