-
Notifications
You must be signed in to change notification settings - Fork 26
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
Super-Code774
wants to merge
1
commit into
Magic-Fish-Labs:working
Choose a base branch
from
Super-Code774:main
base: working
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+22
−12
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; | ||
|
||
import { AppContext } from "../../../App"; | ||
import { | ||
|
@@ -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 | ||
|
@@ -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); | ||
|
@@ -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) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 { | ||
|
@@ -58,7 +69,7 @@ export default function StreakScore({ streakScore, streakHighScore=0, className= | |
if (intervalId.current) { | ||
clearInterval(intervalId.current); | ||
} | ||
} | ||
}; | ||
}, [streakScore]); | ||
|
||
useEffect(() => { | ||
|
@@ -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}> | ||
|
@@ -118,5 +128,5 @@ export default function StreakScore({ streakScore, streakHighScore=0, className= | |
</div> | ||
</WindowContent> | ||
</Window> | ||
) | ||
} | ||
); | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
;
optionnel mais OK