This commit is contained in:
parent
b86fb3a609
commit
e2d9a23974
@ -20,7 +20,7 @@ type Props = {
|
|||||||
beatSaverMap?: BeatSaverMap;
|
beatSaverMap?: BeatSaverMap;
|
||||||
alwaysSingleLine?: boolean;
|
alwaysSingleLine?: boolean;
|
||||||
setIsLeaderboardExpanded?: (isExpanded: boolean) => void;
|
setIsLeaderboardExpanded?: (isExpanded: boolean) => void;
|
||||||
setScore?: (score: ScoreSaberScoreToken) => void;
|
updateScore?: (score: ScoreSaberScoreToken) => void;
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function ScoreButtons({
|
export default function ScoreButtons({
|
||||||
@ -29,7 +29,7 @@ export default function ScoreButtons({
|
|||||||
beatSaverMap,
|
beatSaverMap,
|
||||||
alwaysSingleLine,
|
alwaysSingleLine,
|
||||||
setIsLeaderboardExpanded,
|
setIsLeaderboardExpanded,
|
||||||
setScore,
|
updateScore,
|
||||||
}: Props) {
|
}: Props) {
|
||||||
const [leaderboardExpanded, setLeaderboardExpanded] = useState(false);
|
const [leaderboardExpanded, setLeaderboardExpanded] = useState(false);
|
||||||
const { toast } = useToast();
|
const { toast } = useToast();
|
||||||
@ -84,8 +84,8 @@ export default function ScoreButtons({
|
|||||||
className={`flex gap-2 ${alwaysSingleLine ? "flex-row" : "flex-row lg:flex-col"} items-center justify-center`}
|
className={`flex gap-2 ${alwaysSingleLine ? "flex-row" : "flex-row lg:flex-col"} items-center justify-center`}
|
||||||
>
|
>
|
||||||
{/* Edit score button */}
|
{/* Edit score button */}
|
||||||
{score && leaderboard && setScore && (
|
{score && leaderboard && updateScore && (
|
||||||
<ScoreEditorButton score={score} leaderboard={leaderboard} setScore={setScore} />
|
<ScoreEditorButton score={score} leaderboard={leaderboard} updateScore={updateScore} />
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{/* View Leaderboard button */}
|
{/* View Leaderboard button */}
|
||||||
|
@ -12,10 +12,10 @@ import Tooltip from "@/components/tooltip";
|
|||||||
type ScoreEditorButtonProps = {
|
type ScoreEditorButtonProps = {
|
||||||
score: ScoreSaberScoreToken;
|
score: ScoreSaberScoreToken;
|
||||||
leaderboard: ScoreSaberLeaderboardToken;
|
leaderboard: ScoreSaberLeaderboardToken;
|
||||||
setScore: (score: ScoreSaberScoreToken) => void;
|
updateScore: (score: ScoreSaberScoreToken) => void;
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function ScoreEditorButton({ score, leaderboard, setScore }: ScoreEditorButtonProps) {
|
export default function ScoreEditorButton({ score, leaderboard, updateScore }: ScoreEditorButtonProps) {
|
||||||
const [isScoreEditMode, setIsScoreEditMode] = useState(false);
|
const [isScoreEditMode, setIsScoreEditMode] = useState(false);
|
||||||
|
|
||||||
const maxScore = leaderboard.maxScore || 1; // Use 1 to prevent division by zero
|
const maxScore = leaderboard.maxScore || 1; // Use 1 to prevent division by zero
|
||||||
@ -24,14 +24,14 @@ export default function ScoreEditorButton({ score, leaderboard, setScore }: Scor
|
|||||||
const handleSliderChange = (value: number[]) => {
|
const handleSliderChange = (value: number[]) => {
|
||||||
const newAccuracy = Math.max(0, Math.min(value[0], 100)); // Ensure the accuracy stays within 0-100
|
const newAccuracy = Math.max(0, Math.min(value[0], 100)); // Ensure the accuracy stays within 0-100
|
||||||
const newBaseScore = (newAccuracy / 100) * maxScore;
|
const newBaseScore = (newAccuracy / 100) * maxScore;
|
||||||
setScore({
|
updateScore({
|
||||||
...score,
|
...score,
|
||||||
baseScore: newBaseScore,
|
baseScore: newBaseScore,
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleSliderReset = () => {
|
const handleSliderReset = () => {
|
||||||
setScore({
|
updateScore({
|
||||||
...score,
|
...score,
|
||||||
baseScore: (accuracy / 100) * maxScore,
|
baseScore: (accuracy / 100) * maxScore,
|
||||||
});
|
});
|
||||||
|
@ -60,7 +60,7 @@ export default function Score({ player, playerScore }: Props) {
|
|||||||
beatSaverMap={beatSaverMap}
|
beatSaverMap={beatSaverMap}
|
||||||
score={score}
|
score={score}
|
||||||
setIsLeaderboardExpanded={setIsLeaderboardExpanded}
|
setIsLeaderboardExpanded={setIsLeaderboardExpanded}
|
||||||
setScore={score => {
|
updateScore={score => {
|
||||||
setBaseScore(score.baseScore);
|
setBaseScore(score.baseScore);
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
Reference in New Issue
Block a user