From 41e16cc039e09e56742039a77f4172ac1a5a47e2 Mon Sep 17 00:00:00 2001 From: Topvennie Date: Sat, 6 Jul 2024 22:42:18 +0200 Subject: [PATCH] vinvoor: show the user's most common days --- vinvoor/package.json | 1 + vinvoor/src/overview/Overview.tsx | 6 +++ vinvoor/src/overview/days/Days.tsx | 58 ++++++++++++++++++++++++++ vinvoor/src/overview/streak/Streak.tsx | 10 +---- vinvoor/yarn.lock | 7 ++++ 5 files changed, 74 insertions(+), 8 deletions(-) create mode 100644 vinvoor/src/overview/days/Days.tsx diff --git a/vinvoor/package.json b/vinvoor/package.json index b035fc8..4e2c34b 100644 --- a/vinvoor/package.json +++ b/vinvoor/package.json @@ -25,6 +25,7 @@ "mdi-material-ui": "^7.9.1", "notistack": "^3.0.1", "react": "^18.2.0", + "react-apexcharts": "^1.4.1", "react-device-detect": "^2.2.3", "react-dom": "^18.2.0", "react-router-dom": "^6.23.1", diff --git a/vinvoor/src/overview/Overview.tsx b/vinvoor/src/overview/Overview.tsx index e0c9bd2..779df9f 100644 --- a/vinvoor/src/overview/Overview.tsx +++ b/vinvoor/src/overview/Overview.tsx @@ -7,6 +7,7 @@ import { LoadingSkeleton } from "../components/LoadingSkeleton"; import { useFetch } from "../hooks/useFetch"; import { convertScanJSON, Scan } from "../types/scans"; import { CheckIn } from "./checkin/CheckIn"; +import { Days } from "./days/Days"; import { Heatmap, HeatmapVariant } from "./heatmap/Heatmap"; import { Streak } from "./streak/Streak"; @@ -75,6 +76,11 @@ export const Overview = () => { + + + + + diff --git a/vinvoor/src/overview/days/Days.tsx b/vinvoor/src/overview/days/Days.tsx new file mode 100644 index 0000000..d0f1dab --- /dev/null +++ b/vinvoor/src/overview/days/Days.tsx @@ -0,0 +1,58 @@ +import { ApexOptions } from "apexcharts"; +import { useContext } from "react"; +import Chart from "react-apexcharts"; +import { Scan } from "../../types/scans"; +import { ScanContext } from "../Overview"; + +const getDayCount = (scans: readonly Scan[]) => { + const days = [0, 0, 0, 0, 0, 0, 0]; + scans.forEach((scan) => { + days[scan.scanTime.getDay() - 1]++; + }); + return days.slice(0, -2); +}; + +export const Days = () => { + const { scans } = useContext(ScanContext); + + const state = { + options: { + labels: ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday"], + fill: { + opacity: 1, + }, + yaxis: { + show: false, + }, + legend: { + position: "bottom", + labels: { + useSeriesColors: true, + }, + }, + plotOptions: { + polarArea: { + rings: { + strokeWidth: 0, + }, + spokes: { + strokeWidth: 0, + }, + }, + }, + theme: { + monochrome: { + enabled: true, + color: "#ff7f00", + shadeTo: "light", + shadeIntensity: 1, + }, + }, + } as ApexOptions, + series: getDayCount(scans), + }; + + return ( + + ); +}; diff --git a/vinvoor/src/overview/streak/Streak.tsx b/vinvoor/src/overview/streak/Streak.tsx index e34258e..071d1f7 100644 --- a/vinvoor/src/overview/streak/Streak.tsx +++ b/vinvoor/src/overview/streak/Streak.tsx @@ -60,7 +60,7 @@ export const Streak = () => { const [isOnStreak, streak] = getStreak(scans); return isOnStreak ? ( - + { ) : ( - +