Skip to content

Commit

Permalink
feat: add max hr to data context
Browse files Browse the repository at this point in the history
  • Loading branch information
morteako committed Jan 6, 2025
1 parent 925db10 commit 8f98c7c
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions apps/frontend/src/context/DataContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const DataContext = React.createContext<{
timeElapsed: number;
startingTime: Date | null;
distance: number;
maxHeartRate: number | null;
speed: number;
start: () => void;
stop: () => void;
Expand All @@ -36,6 +37,7 @@ interface Data {
untrackedData: DataPoint[];
timeElapsed: number;
distance: number;
maxHeartRate: number | null;
speed: number;
startingTime: Date | null;
state: 'not_started' | 'running' | 'paused';
Expand Down Expand Up @@ -93,6 +95,7 @@ export const DataContextProvider = ({ clockWorker, children }: Props) => {
speed: 0,
startingTime: new Date(),
state: 'running',
maxHeartRate: null,
};
}
return { ...currentData, state: 'running' };
Expand Down Expand Up @@ -170,6 +173,11 @@ export const DataContextProvider = ({ clockWorker, children }: Props) => {
}
: undefined),
};

const newMaxHeartRate = dataPoint.heartRate
? Math.max(dataPoint.heartRate, currentData.maxHeartRate || 0)
: currentData.maxHeartRate;

return {
...currentData,
untrackedData: [
Expand All @@ -178,6 +186,7 @@ export const DataContextProvider = ({ clockWorker, children }: Props) => {
],
speed: speed,
distance: currentData.distance + deltaDistance,
maxHeartRate: newMaxHeartRate,
laps: [
...laps.filter((_, i) => i !== laps.length - 1),
{
Expand All @@ -201,6 +210,7 @@ export const DataContextProvider = ({ clockWorker, children }: Props) => {
distance: 0,
speed: 0,
startingTime: null,
maxHeartRate: null,
state: 'not_started',
}
);
Expand Down Expand Up @@ -297,6 +307,7 @@ export const DataContextProvider = ({ clockWorker, children }: Props) => {
timeElapsed: data.timeElapsed,
startingTime: data.startingTime,
distance: data.distance,
maxHeartRate: data.maxHeartRate,
speed: data.speed,
start,
stop,
Expand Down

0 comments on commit 8f98c7c

Please sign in to comment.