-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
vinvoor: show current checkin status
- Loading branch information
Showing
11 changed files
with
606 additions
and
479 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,74 @@ | ||
import { Box, Paper, Switch, Typography } from "@mui/material"; | ||
import { useState } from "react"; | ||
import Grid from "@mui/material/Grid"; | ||
import { createContext, useState } from "react"; | ||
import { Tooltip } from "react-tooltip"; | ||
import { LoadingSkeleton } from "../components/LoadingSkeleton"; | ||
import { useFetch } from "../hooks/useFetch"; | ||
import { Scan } from "../types/scans"; | ||
import { convertScanJSON, Scan } from "../types/scans"; | ||
import { CheckIn } from "./checkin/CheckIn"; | ||
import { Heatmap, HeatmapVariant } from "./heatmap/Heatmap"; | ||
|
||
interface ScanContextProps { | ||
scans: readonly Scan[]; | ||
} | ||
|
||
export const ScanContext = createContext<ScanContextProps>({ | ||
scans: [], | ||
}); | ||
|
||
export const Overview = () => { | ||
const [scans, setScans] = useState<Scan[]>([]); | ||
const { loading } = useFetch<Scan[]>("scans", setScans); | ||
const [scans, setScans] = useState<readonly Scan[]>([]); | ||
const { loading } = useFetch<readonly Scan[]>( | ||
"scans", | ||
setScans, | ||
convertScanJSON | ||
); | ||
const [checked, setChecked] = useState<boolean>(true); | ||
|
||
const dates = scans.map((scan) => new Date(scan.scanTime)); | ||
|
||
const handleChange = (event: React.ChangeEvent<HTMLInputElement>) => { | ||
setChecked(event.target.checked); | ||
}; | ||
|
||
return ( | ||
<LoadingSkeleton loading={loading}> | ||
<Paper elevation={4} sx={{ padding: 2 }}> | ||
<Box | ||
sx={{ | ||
display: "flex", | ||
justifyContent: "right", | ||
}} | ||
> | ||
<Typography variant="h6">Months</Typography> | ||
<Switch checked={checked} onChange={handleChange} /> | ||
<Typography variant="h6">Days</Typography> | ||
</Box> | ||
<Heatmap | ||
startDate={new Date("2024-01-01")} | ||
endDate={new Date("2024-12-31")} | ||
days={dates} | ||
variant={ | ||
checked ? HeatmapVariant.DAYS : HeatmapVariant.MONTHS | ||
} | ||
/> | ||
<Tooltip id="heatmap" /> | ||
</Paper> | ||
<ScanContext.Provider value={{ scans }}> | ||
<Grid container spacing={2}> | ||
<Grid item xs={12} md={4}> | ||
<CheckIn /> | ||
</Grid> | ||
<Grid item xs={12} md={8}> | ||
<Paper elevation={4} sx={{ padding: 2 }}> | ||
<Box | ||
sx={{ | ||
display: "flex", | ||
justifyContent: "right", | ||
}} | ||
> | ||
<Typography variant="h6">Months</Typography> | ||
<Switch | ||
checked={checked} | ||
onChange={handleChange} | ||
/> | ||
<Typography variant="h6">Days</Typography> | ||
</Box> | ||
<Heatmap | ||
startDate={new Date("2024-01-01")} | ||
endDate={new Date("2024-12-31")} | ||
variant={ | ||
checked | ||
? HeatmapVariant.DAYS | ||
: HeatmapVariant.MONTHS | ||
} | ||
/> | ||
<Tooltip id="heatmap" /> | ||
</Paper> | ||
</Grid> | ||
</Grid> | ||
</ScanContext.Provider> | ||
</LoadingSkeleton> | ||
); | ||
}; | ||
|
||
// TODO: Checked in today | ||
// TODO: Current streak | ||
// TODO: Pie chart |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { Alert, AlertTitle } from "@mui/material"; | ||
import { EmoticonExcitedOutline, EmoticonFrownOutline } from "mdi-material-ui"; | ||
import { useContext } from "react"; | ||
import { ScanContext } from "../Overview"; | ||
|
||
const isTheSameDay = (date1: Date, date2: Date) => | ||
date1.getFullYear() === date2.getFullYear() && | ||
date1.getMonth() === date2.getMonth() && | ||
date1.getDate() === date2.getDate(); | ||
|
||
export const CheckIn = () => { | ||
const { scans } = useContext(ScanContext); | ||
|
||
const checkedIn = isTheSameDay( | ||
scans[scans.length - 1].scanTime, | ||
new Date() | ||
); | ||
|
||
return checkedIn ? ( | ||
<Alert | ||
variant="outlined" | ||
severity="success" | ||
iconMapping={{ | ||
success: <EmoticonExcitedOutline fontSize="large" />, | ||
}} | ||
> | ||
<AlertTitle>Checked in</AlertTitle> | ||
Thank you for stopping by the kelder! | ||
</Alert> | ||
) : ( | ||
<Alert | ||
variant="outlined" | ||
severity="error" | ||
iconMapping={{ | ||
error: <EmoticonFrownOutline fontSize="large" />, | ||
}} | ||
> | ||
<AlertTitle>Not checked in</AlertTitle> | ||
We miss you in the kelder! | ||
</Alert> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.