diff --git a/.eslintrc.cjs b/.eslintrc.cjs index e219bfc..8dfe7ba 100644 --- a/.eslintrc.cjs +++ b/.eslintrc.cjs @@ -15,6 +15,7 @@ module.exports = { "warn", { allowConstantExport: true }, ], + "@typescript-eslint/no-explicit-any": "off", "prettier/prettier": "error", }, }; diff --git a/src/components/ClubStats.tsx b/src/components/ClubStats.tsx index 6965c37..5b5d75f 100644 --- a/src/components/ClubStats.tsx +++ b/src/components/ClubStats.tsx @@ -22,19 +22,14 @@ export const ClubStats = ({ average }: { average: AveragedSwing }) => { 0 ).toPrecision(3) + "m", }, - // { - // name: "Deviation Distance", - // stat: - // ( - // average?.["Total Deviation Distance"] || - // average?.["Gesamtabweichungsdistanz"] || - // 0 - // ).toPrecision(3) + "m", - // }, { - name: "Smash Factor", - stat: (average?.["Smash Factor"] || 0).toPrecision(2), + name: "Deviation Distance", + stat: getDeviationString(average), }, + // { + // name: "Smash Factor", + // stat: (average?.["Smash Factor"] || 0).toPrecision(2), + // }, ], [average], ); @@ -66,3 +61,12 @@ export const ClubStats = ({ average }: { average: AveragedSwing }) => { ); }; + +const getDeviationString = (average: AveragedSwing) => { + const deviation = + average?.["Total Deviation Distance"] || + average?.["Gesamtabweichungsdistanz"] || + 0; + + return deviation > 0 ? `${deviation}m left` : `${Math.abs(deviation)}m right`; +}; diff --git a/src/components/panels/Last30DaysAverages.tsx b/src/components/panels/Last30DaysAverages.tsx index 57daeb8..ac81d75 100644 --- a/src/components/panels/Last30DaysAverages.tsx +++ b/src/components/panels/Last30DaysAverages.tsx @@ -2,7 +2,7 @@ import { useAveragedSwings } from "../../utils/calculateAverages"; import { ClubStats } from "../ClubStats"; import { IQRNote } from "../IQRNote"; -export const Last30DaysAverages = () => { +export const AverageOverview = () => { const averages = useAveragedSwings(); return ( diff --git a/src/provider/SettingsContext.tsx b/src/provider/SettingsContext.tsx index 1719ca6..aa5b766 100644 --- a/src/provider/SettingsContext.tsx +++ b/src/provider/SettingsContext.tsx @@ -1,8 +1,11 @@ import { PropsWithChildren, createContext, useState } from "react"; +import { ClubAverageStat } from "./settings.utils"; + export type SettingsType = { useIQR: boolean; useAboveAverageShots: boolean; + clubAverageStats: ClubAverageStat[]; }; interface SettingsContextProps { @@ -11,14 +14,19 @@ interface SettingsContextProps { } export const SettingsContext = createContext({ - settings: { useIQR: false, useAboveAverageShots: false }, - setSettings: () => {}, + settings: { + useIQR: false, + useAboveAverageShots: false, + clubAverageStats: [] as any, + }, + setSettings: () => { }, }); export const SettingsProvider = ({ children }: PropsWithChildren) => { const [settings, setSettings] = useState({ useIQR: false, useAboveAverageShots: false, + clubAverageStats: ["CARRY_DISTANCE"], }); return ( diff --git a/src/provider/settings.utils.ts b/src/provider/settings.utils.ts new file mode 100644 index 0000000..a75fc0e --- /dev/null +++ b/src/provider/settings.utils.ts @@ -0,0 +1,8 @@ +export const CLUB_AVERAGE_STATS = [ + "CARRY_DISTANCE", + "TOTAL_DISTANCE", + "TOTAL_DEVIATION_DISTANCE", + "SMASH_FACTOR", +]; + +export type ClubAverageStat = (typeof CLUB_AVERAGE_STATS)[number]; diff --git a/src/views/Dashboard.tsx b/src/views/Dashboard.tsx index 980a357..a361513 100644 --- a/src/views/Dashboard.tsx +++ b/src/views/Dashboard.tsx @@ -1,6 +1,6 @@ import { Link } from "react-router-dom"; import { BasePageLayout } from "../components/base/BasePageLayout"; -import { Last30DaysAverages } from "../components/panels/Last30DaysAverages"; +import { AverageOverview } from "../components/panels/Last30DaysAverages"; import { SettingsForm } from "../components/panels/SettingsForm"; import { useSelectedSessions } from "../hooks/useSelectedSessions"; import { dashboardRoutes } from "../routes"; @@ -10,7 +10,7 @@ export const Dashboard = () => (
- +