Skip to content

Commit

Permalink
Merge pull request #86 from brown-ccv/chore-activity-changes
Browse files Browse the repository at this point in the history
chore: activity page changes
  • Loading branch information
hetd54 committed Sep 6, 2024
2 parents 73289e4 + b47fd77 commit fcef739
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 18 deletions.
1 change: 1 addition & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"@types/react": "^18.2.64",
"@types/react-dom": "^18.2.21",
"astro": "^4.3.6",
"date-fns": "^3.6.0",
"firebase": "^9.23.0",
"i": "^0.3.7",
"react": "^18.2.0",
Expand Down
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
5 changes: 1 addition & 4 deletions src/components/Login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@ const Login: React.FC<LoginProps> = ({ currentUser, setUserFunction }) => {

const login = async () => {
await handleLogin().then((loggedUser) => {
if (!loggedUser)
setMessage(
"You must be an admin on this project in order to see this data. If you believe this to be an error, please reach out to David Lindstrom ([email protected])."
)
if (!loggedUser) setMessage("You must be an admin on this project in order to see this data.")
setUserFunction(loggedUser)
})
}
Expand Down
10 changes: 1 addition & 9 deletions src/consts.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,4 @@
export const SITE_TITLE = "MMP"
export const SITE_DESCRIPTION = "Mesoamerican Migration Project"

export const LINKS = [
"people",
"news",
"publications",
"study-design",
"data",
"documentation",
"activity",
]
export const LINKS = ["people", "news", "publications", "study-design", "data", "documentation"]
2 changes: 1 addition & 1 deletion src/pages/activity.astro
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ import Layout from "../layouts/Layout.astro"
import ActivityPage from "../components/ActivityPage"
---

<Layout title="Admin" description="History Table of Downloads">
<Layout title="Activity" description="History Table of Downloads">
<ActivityPage client:only="react" />
</Layout>

0 comments on commit fcef739

Please sign in to comment.