Skip to content

Commit

Permalink
fix: cleanup blurb
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinWu098 committed Apr 24, 2024
1 parent e4a07b5 commit 6a05c98
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions components/search/Blurb.tsx
Original file line number Diff line number Diff line change
@@ -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: (
Expand All @@ -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 (
Expand All @@ -48,7 +50,8 @@ const Blurb = (props: BlurbProps) => {
</div>

<div className="flex text-sm font-light text-gray md:justify-end md:text-base">
{"GE-Z's"} data was updated {lastUpdated ? timeAgo : '[oopsie, time not available :(]'}
{"GE-Z's"} data was updated{" "}
{lastUpdated ? timeAgo : "x"}
</div>
</div>

Expand Down

0 comments on commit 6a05c98

Please sign in to comment.