Skip to content

Update StreakScore.jsx #89

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: working
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 22 additions & 12 deletions src/components/app/Grades/StreakScore.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useState, useEffect, useRef, useContext } from 'react'
import { useState, useEffect, useRef, useContext } from 'react';

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

; optionnel mais OK


import { AppContext } from "../../../App";
import {
Expand All @@ -13,10 +13,8 @@ import InfoButton from "../../generic/Informative/InfoButton";
import Star from "../../graphics/Star";
import ArrowOutline from "../../graphics/ArrowOutline";


import "./StreakScore.css";


export default function StreakScore({ streakScore, streakHighScore=0, className="", ...props }) {
const [displayedStreakScore, setDisplayedStreakScore] = useState(0);
const [arrowsNumber, setArrowsNumber] = useState(0); // arrowsNumber on one side only
Expand All @@ -33,7 +31,7 @@ export default function StreakScore({ streakScore, streakHighScore=0, className=
useEffect(() => {
// animation du score de streak
currentStep.current = 0;

function lerp(start, end, t) {
// si on veut changer la "courbe" (t'as la ref) c'est ici, là c'est linéaire
return start + t * (end - start);
Expand All @@ -44,10 +42,23 @@ export default function StreakScore({ streakScore, streakHighScore=0, className=
setDisplayedStreakScore(Math.round(lerp(0, streakScore, (currentStep.current + 1) / max)));
currentStep.current++;
}
}
};

// Function to handle streak score calculation considering "Abs"
const calculateStreakScore = (scores) => {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok

let streak = 0;
for (let score of scores) {
if (score !== "Abs" && score !== "Disp" && score >= streakScore) {
streak++;
}
}
return streak;
};

if (displayMode.get() === "quality" && streakScore) {
const STEP_NUMBER = (streakScore < 15 ? streakScore : 12 + Math.floor(streakScore / 5)); // à ne pas confondre avec le sport qui consiste à monter et descendre des dizaines de fois par minutes
const scores = getScores(); // Assuming getScores() returns an array of scores
const streak = calculateStreakScore(scores);
const STEP_NUMBER = (streak < 15 ? streak : 12 + Math.floor(streak / 5));
const STEP_DURATION = 50;
intervalId.current = setInterval(() => newStep(STEP_NUMBER), STEP_DURATION);
} else {
Expand All @@ -58,7 +69,7 @@ export default function StreakScore({ streakScore, streakHighScore=0, className=
if (intervalId.current) {
clearInterval(intervalId.current);
}
}
};
}, [streakScore]);

useEffect(() => {
Expand All @@ -77,15 +88,14 @@ export default function StreakScore({ streakScore, streakHighScore=0, className=
} else {
setArrowsNumber(newArrowsNumber);
}
}
};
window.addEventListener("resize", arrowsNumberCalculation);
arrowsNumberCalculation();

return () => {
window.removeEventListener("resize", arrowsNumberCalculation);
}
};
}, []);


return (
<Window className={`streak-score ${className}`} allowFullscreen={true} growthFactor={.8} {...props}>
Expand Down Expand Up @@ -118,5 +128,5 @@ export default function StreakScore({ streakScore, streakHighScore=0, className=
</div>
</WindowContent>
</Window>
)
}
);
}