Skip to content

Commit

Permalink
chore: use hardcoded deadline for sports
Browse files Browse the repository at this point in the history
  • Loading branch information
ArtemSBulgakov committed Nov 19, 2024
1 parent e622ee3 commit 0ec9c3b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/components/dashboard/SportsWidget.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { $sports } from "@/api/sports";
import { useNowMS } from "@/lib/utils/use-now.ts";

export function SportsWidget() {
const { data: sportInfo } = $sports.useQuery("get", "/users/sport_info");
const nowMs = useNowMS(!!sportInfo);

if (!sportInfo) return null;

Expand All @@ -12,12 +14,12 @@ export function SportsWidget() {
const semesterHours = sportInfo.ongoing_semester.hours_sem_max;
const debtHours = sportInfo.ongoing_semester.debt;

/* TODO: Fetch the end date of current semester from sports
const deadline = new Date(sportInfo.ongoing_semester.deadline);
// TODO: Fetch the end date of current semester from sports
const deadline = new Date("2024-12-08");
const daysLeft = Math.max(
0,
Math.floor((deadline.getTime() - nowMs) / (1000 * 60 * 60 * 24)),
);*/
Math.ceil((deadline.getTime() - nowMs) / (1000 * 60 * 60 * 24)),
);

return (
<div className="group flex flex-row gap-4 rounded-2xl bg-primary-main px-4 py-6">
Expand All @@ -29,15 +31,15 @@ export function SportsWidget() {
Sports: {earnedHours} / {semesterHours}
{debtHours ? ` (+${debtHours} debt)` : null} hours
</p>
{/*<p className="text-lg text-text-secondary/75">
<p className="text-lg text-text-secondary/75">
Deadline:{" "}
{deadline.toLocaleDateString("en-US", {
month: "long",
day: "numeric",
year: "numeric",
})}{" "}
({daysLeft} days left)
</p>*/}
</p>
<a
href="https://t.me/IUSportBot"
className="text-lg text-text-secondary/75 hover:underline"
Expand Down
9 changes: 9 additions & 0 deletions src/lib/utils/use-now.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { useState } from "react";
import { useInterval } from "usehooks-ts";

export function useNowMS(enabled: boolean) {
const [now, setNow] = useState<number>(Date.now());
// Update every 5 seconds
useInterval(() => setNow(Date.now()), enabled ? 5000 : null);
return now;
}

0 comments on commit 0ec9c3b

Please sign in to comment.