From 6a05c980f032f6e83165e967b66f70143670cdc6 Mon Sep 17 00:00:00 2001 From: Kevin Wu Date: Tue, 23 Apr 2024 23:03:32 -0700 Subject: [PATCH] fix: cleanup blurb --- components/search/Blurb.tsx | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/components/search/Blurb.tsx b/components/search/Blurb.tsx index 2d09cc8..12b8eef 100644 --- a/components/search/Blurb.tsx +++ b/components/search/Blurb.tsx @@ -1,6 +1,6 @@ -import React, { useEffect, useState } from 'react'; -import { CourseObject, FilterValues } from './Search'; -import { formatDistanceToNow } from 'date-fns'; +import React, { useEffect, useState } from "react"; +import { CourseObject, FilterValues } from "./Search"; +import { formatDistanceToNow } from "date-fns"; interface BlurbProps { filterData: ( @@ -15,20 +15,22 @@ interface BlurbProps { const Blurb = (props: BlurbProps) => { const { filterData, courses, lastUpdated, filterValues } = props; - const [timeAgo, setTimeAgo] = useState(''); + const [timeAgo, setTimeAgo] = useState(""); useEffect(() => { const updateRelativeTime = () => { if (lastUpdated) { - const formattedTimeAgo = formatDistanceToNow(new Date(lastUpdated)); + const formattedTimeAgo = formatDistanceToNow( + new Date(lastUpdated), + ); setTimeAgo(`${formattedTimeAgo} ago`); } }; - updateRelativeTime(); // Update initially - const intervalId = setInterval(updateRelativeTime, 1000); // Update every second + updateRelativeTime(); + const intervalId = setInterval(updateRelativeTime, 1000); - return () => clearInterval(intervalId); // Cleanup on unmount + return () => clearInterval(intervalId); }, [lastUpdated]); return ( @@ -48,7 +50,8 @@ const Blurb = (props: BlurbProps) => {
- {"GE-Z's"} data was updated {lastUpdated ? timeAgo : '[oopsie, time not available :(]'} + {"GE-Z's"} data was updated{" "} + {lastUpdated ? timeAgo : "x"}