From d95046ad42eea34a6eb7cb9583e8f4049e8262e3 Mon Sep 17 00:00:00 2001 From: Stian Fredrik Aune Date: Sun, 7 Mar 2021 18:14:20 +0100 Subject: [PATCH] / and stonks --- my-bois/src/components/Bois.jsx | 23 +++++++++++++---------- my-bois/src/components/Misc.jsx | 2 +- my-bois/src/components/Score.jsx | 4 ++-- my-bois/src/helpers/color.js | 8 +++++++- my-bois/src/hooks/net.js | 1 + 5 files changed, 24 insertions(+), 14 deletions(-) diff --git a/my-bois/src/components/Bois.jsx b/my-bois/src/components/Bois.jsx index 1411047..3a35187 100644 --- a/my-bois/src/components/Bois.jsx +++ b/my-bois/src/components/Bois.jsx @@ -1,4 +1,4 @@ -import React, {useContext, useEffect, useState} from 'react'; +import React, {useCallback, useContext, useEffect, useState} from 'react'; import "./Bois.css"; import {StatusContext} from "./Contexts"; @@ -17,7 +17,7 @@ const Boi = ({type, children}) => { }; export const LeftBoi = () => { - const {prevLongDiff, workout, workoutStatus, program, hidden} = useContext(StatusContext); + const {prevDiff, prevLongDiff, workout, workoutStatus, program, hidden} = useContext(StatusContext); if (workoutStatus === null || workout === null || program === null || hidden) { return null; } @@ -30,7 +30,7 @@ export const LeftBoi = () => { return ( - + @@ -110,15 +110,22 @@ export const CentreBoi = () => { return false; }); - useKey("Escape", () => { + const showHide = useCallback(() => { + setHidden(!hidden); + }, [setHidden, hidden]); + + const stopRun = useCallback(() => { if (state === "connected") { stop(); + setHidden(false); return true; } - }); + }, [state, stop, setHidden]); + + useKey("Escape", stopRun); - useKey(["H", "h"], () => showHide()); + useKey(["H", "h", "/"], showHide); useKey("*", () => { if (state === "started" || state === "connected") { @@ -126,10 +133,6 @@ export const CentreBoi = () => { } }); - function showHide() { - setHidden(!hidden); - } - if (hidden) { return null; } diff --git a/my-bois/src/components/Misc.jsx b/my-bois/src/components/Misc.jsx index 47c34c3..a6b2ecf 100644 --- a/my-bois/src/components/Misc.jsx +++ b/my-bois/src/components/Misc.jsx @@ -1,5 +1,5 @@ import React from 'react'; -import {COLOR_VERY_BAD, colorByDiff} from "../helpers/color"; +import {colorByDiff} from "../helpers/color"; import "./Misc.css"; import {diffString} from "../helpers/diff"; diff --git a/my-bois/src/components/Score.jsx b/my-bois/src/components/Score.jsx index 2c5da83..7d8c4d6 100644 --- a/my-bois/src/components/Score.jsx +++ b/my-bois/src/components/Score.jsx @@ -40,8 +40,8 @@ export const Timer = ({minutes, seconds, cooldownMin}) => { ); }; -export const CalorieScore = ({calories, diff, prevDiff}) => ( - +export const CalorieScore = ({calories, diff, prevDiff, stonks}) => ( + ); export const LevelScore = ({level}) => ; diff --git a/my-bois/src/helpers/color.js b/my-bois/src/helpers/color.js index 02f752a..d27ae9e 100644 --- a/my-bois/src/helpers/color.js +++ b/my-bois/src/helpers/color.js @@ -5,7 +5,13 @@ export const COLOR_NEUTRAL = "#FFF"; export const COLOR_GOOD = "#BFB"; export const COLOR_VERY_GOOD = "#6F6"; -export const colorByDiff = (diff, prevDiff) => { +export const COLOR_STONKS_GOOD = "#3A3"; + +export const colorByDiff = (diff, prevDiff, stonksDiff = 0) => { + if (stonksDiff > 0 && diff > 0 && diff > stonksDiff) { + return COLOR_STONKS_GOOD + } + if (diff < 0) { return diff < prevDiff ? COLOR_VERY_BAD : COLOR_BAD; } else { diff --git a/my-bois/src/hooks/net.js b/my-bois/src/hooks/net.js index 0d690f8..71ffdd8 100644 --- a/my-bois/src/hooks/net.js +++ b/my-bois/src/hooks/net.js @@ -43,6 +43,7 @@ export function openWebsocket(workout) { async function runBack(query) { return new Promise((resolve, reject) => { + /* global chrome */ chrome.runtime.sendMessage(query, result => { if (result.success) { resolve(result.data)