|
@ -2,11 +2,11 @@ import React, {useContext, useEffect, useState} from 'react'; |
|
|
|
|
|
|
|
|
import "./Bois.css"; |
|
|
import "./Bois.css"; |
|
|
import {StatusContext} from "./Contexts"; |
|
|
import {StatusContext} from "./Contexts"; |
|
|
import {CalorieScore, CpmScore, DistanceScore, RpmScore, Timer} from "./Score"; |
|
|
import {CalorieScore, CpmScore, LevelScore, RpmScore, Timer} from "./Score"; |
|
|
import calculateDiff from "../helpers/diff"; |
|
|
import calculateDiff from "../helpers/diff"; |
|
|
import useKey from "../hooks/useKey"; |
|
|
import useKey from "../hooks/useKey"; |
|
|
import {Milestones} from "./Milestones"; |
|
|
import {Milestones} from "./Milestones"; |
|
|
import {Info, InfoTable, StateFilter, Warning} from "./Misc"; |
|
|
import {Info, InfoTable, StateFilter, Differ} from "./Misc"; |
|
|
|
|
|
|
|
|
const Boi = ({type, children}) => { |
|
|
const Boi = ({type, children}) => { |
|
|
return ( |
|
|
return ( |
|
@ -17,22 +17,23 @@ const Boi = ({type, children}) => { |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
export const LeftBoi = () => { |
|
|
export const LeftBoi = () => { |
|
|
const {prevLongDiff, workoutStatus, program, hidden} = useContext(StatusContext); |
|
|
const {prevLongDiff, workout, workoutStatus, program, hidden} = useContext(StatusContext); |
|
|
if (workoutStatus === null || program === null || hidden) { |
|
|
if (workoutStatus === null || workout === null || program === null || hidden) { |
|
|
return null; |
|
|
return null; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
const {minutes, seconds, calories, distance, rpm} = workoutStatus; |
|
|
const {cooldownMin} = workout; |
|
|
const diff = calculateDiff(program, minutes, seconds, calories); |
|
|
const {minutes, seconds, calories, level, rpm} = workoutStatus; |
|
|
|
|
|
const diff = calculateDiff({program, cooldownMin, minutes, seconds, calories}); |
|
|
const cpm = calories / (minutes + (seconds / 60)); |
|
|
const cpm = calories / (minutes + (seconds / 60)); |
|
|
|
|
|
|
|
|
return ( |
|
|
return ( |
|
|
<Boi type="left"> |
|
|
<Boi type="left"> |
|
|
<Timer minutes={minutes} seconds={seconds}/> |
|
|
<Timer minutes={minutes} seconds={seconds} cooldownMin={cooldownMin}/> |
|
|
<CalorieScore calories={calories} diff={diff} prevDiff={prevLongDiff}/> |
|
|
<CalorieScore calories={calories} diff={diff} prevDiff={prevLongDiff}/> |
|
|
<DistanceScore distance={distance}/> |
|
|
|
|
|
<RpmScore rpm={rpm}/> |
|
|
<RpmScore rpm={rpm}/> |
|
|
<CpmScore cpm={cpm}/> |
|
|
<CpmScore cpm={cpm}/> |
|
|
|
|
|
<LevelScore level={level}/> |
|
|
</Boi> |
|
|
</Boi> |
|
|
); |
|
|
); |
|
|
}; |
|
|
}; |
|
@ -42,6 +43,9 @@ export const CentreBoi = () => { |
|
|
state, program, setProgram, bike, setBike, bikes, programs, |
|
|
state, program, setProgram, bike, setBike, bikes, programs, |
|
|
start, pause, stop, create, workoutStatus, |
|
|
start, pause, stop, create, workoutStatus, |
|
|
hidden, setHidden, |
|
|
hidden, setHidden, |
|
|
|
|
|
workout, |
|
|
|
|
|
prevLongDiff, |
|
|
|
|
|
toggleCooldown, |
|
|
} = useContext(StatusContext); |
|
|
} = useContext(StatusContext); |
|
|
const [options, setOptions] = useState(null); |
|
|
const [options, setOptions] = useState(null); |
|
|
const [current, setCurrent] = useState(0); |
|
|
const [current, setCurrent] = useState(0); |
|
@ -115,6 +119,12 @@ export const CentreBoi = () => { |
|
|
|
|
|
|
|
|
useKey(["H", "h"], () => showHide()); |
|
|
useKey(["H", "h"], () => showHide()); |
|
|
|
|
|
|
|
|
|
|
|
useKey("*", () => { |
|
|
|
|
|
if (state === "started") { |
|
|
|
|
|
toggleCooldown(); |
|
|
|
|
|
} |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
function showHide() { |
|
|
function showHide() { |
|
|
setHidden(!hidden); |
|
|
setHidden(!hidden); |
|
|
} |
|
|
} |
|
@ -124,13 +134,14 @@ export const CentreBoi = () => { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if (state === "started" && workoutStatus !== null) { |
|
|
if (state === "started" && workoutStatus !== null) { |
|
|
|
|
|
const {cooldownMin} = workout; |
|
|
const {minutes, seconds, calories} = workoutStatus; |
|
|
const {minutes, seconds, calories} = workoutStatus; |
|
|
const diff = calculateDiff(program, minutes, seconds, calories); |
|
|
const diff = calculateDiff({program, cooldownMin, minutes, seconds, calories}); |
|
|
|
|
|
|
|
|
if (diff < 0) { |
|
|
if (diff < 0 || (minutes > 0 && seconds === 0)) { |
|
|
return ( |
|
|
return ( |
|
|
<Boi type="centre"> |
|
|
<Boi type="centre"> |
|
|
<Warning>{diff}</Warning> |
|
|
<Differ diff={diff} prevDiff={prevLongDiff} /> |
|
|
</Boi> |
|
|
</Boi> |
|
|
); |
|
|
); |
|
|
} else { |
|
|
} else { |
|
@ -147,15 +158,13 @@ export const CentreBoi = () => { |
|
|
return ""; |
|
|
return ""; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if (options[current] === void(0)) { |
|
|
if (options[current] === void (0)) { |
|
|
return ""; |
|
|
return ""; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
return options[current].name; |
|
|
return options[current].name; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
console.log(state); |
|
|
|
|
|
|
|
|
|
|
|
return ( |
|
|
return ( |
|
|
<Boi type="centre"> |
|
|
<Boi type="centre"> |
|
|
<StateFilter current={state} required="stopped"> |
|
|
<StateFilter current={state} required="stopped"> |
|
|
xxxxxxxxxx