Skip to content
This repository has been archived by the owner on Dec 19, 2024. It is now read-only.

Commit

Permalink
feat: show number of downloads in the past year
Browse files Browse the repository at this point in the history
  • Loading branch information
hetd54 committed Aug 13, 2024
1 parent c130ce5 commit b47fd77
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions src/components/ActivityPage.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useState } from "react"
import type { UserInfo } from "firebase/auth"
import { isAfter, subYears, toDate } from "date-fns"
import Login from "../components/Login"
import { useActivityData } from "../hooks/activity.ts"
import ActivityTable from "./ActivityTable.tsx"
Expand All @@ -10,6 +11,9 @@ const ActivityPage = () => {
setUser(loggedUser)
}
const activityData = useActivityData(user)
const yearlyActivityData = activityData?.filter((data) =>
isAfter(toDate(data.date.toDate()), subYears(new Date(), 1))
)

return (
<div className="space-y-8">
Expand All @@ -22,10 +26,18 @@ const ActivityPage = () => {
)}
</section>
{user && activityData && (
<section className="space-y-2">
<h3>
<span className="px-2 font-bold">{activityData.length}</span> download(s)
</h3>
<section className="space-y-4">
<div className="flex justify-between">
<h3>
<span className="px-2 font-bold">{activityData.length}</span> total download(s)
</h3>
{yearlyActivityData && (
<h3>
<span className="px-2 font-bold">{yearlyActivityData.length}</span> download(s) in
the past year
</h3>
)}
</div>
<ActivityTable data={activityData} />
</section>
)}
Expand Down

0 comments on commit b47fd77

Please sign in to comment.