From e9076c02131c272216fec0cb62c55ba44b7e78d6 Mon Sep 17 00:00:00 2001 From: Nicolas Mowen Date: Mon, 26 Feb 2024 13:47:44 -0700 Subject: [PATCH] Show correct time range when time filter is active (#10066) * Show correct time range when time filter is active * remove console --- web/src/pages/Events.tsx | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/web/src/pages/Events.tsx b/web/src/pages/Events.tsx index f8a87aecb..4778cbeb1 100644 --- a/web/src/pages/Events.tsx +++ b/web/src/pages/Events.tsx @@ -28,9 +28,19 @@ export default function Events() { // review paging - const timeRange = useMemo(() => { + const last24Hours = useMemo(() => { return { before: Date.now() / 1000, after: getHoursAgo(24) }; }, []); + const selectedTimeRange = useMemo(() => { + if (reviewSearchParams["after"] == undefined) { + return last24Hours; + } + + return { + before: Math.floor(reviewSearchParams["before"]), + after: Math.floor(reviewSearchParams["after"]), + }; + }, [reviewSearchParams]); const reviewSegmentFetcher = useCallback((key: any) => { const [path, params] = Array.isArray(key) ? key : [key, undefined]; @@ -47,7 +57,7 @@ export default function Events() { labels: reviewSearchParams["labels"], reviewed: reviewSearchParams["showReviewed"], before: lastDate, - after: reviewSearchParams["after"] || timeRange.after, + after: reviewSearchParams["after"] || last24Hours.after, limit: API_LIMIT, }; return ["review", pagedParams]; @@ -58,8 +68,8 @@ export default function Events() { labels: reviewSearchParams["labels"], reviewed: reviewSearchParams["showReviewed"], limit: API_LIMIT, - before: reviewSearchParams["before"] || timeRange.before, - after: reviewSearchParams["after"] || timeRange.after, + before: reviewSearchParams["before"] || last24Hours.before, + after: reviewSearchParams["after"] || last24Hours.after, }; return ["review", params]; }, @@ -205,7 +215,7 @@ export default function Events() {