Skip to content

Commit 8a28952

Browse files
committed
refactor(votes): extract shouldShowRelativeEvaluation derived to remove duplication
1 parent 9236efb commit 8a28952

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

src/features/votes/components/VotableGrade.svelte

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,12 @@
8585
return getRelativeEvaluationLabel(calcGradeDiff(taskResult.grade, latestMedianGrade));
8686
});
8787
88+
// Whether to show the relative evaluation label (badge + sr-only text).
89+
// Hidden only when showNeutralBadge is false and the label is exactly '±0'.
90+
const shouldShowRelativeEvaluation = $derived(
91+
showNeutralBadge || relativeEvaluationLabel !== '±0',
92+
);
93+
8894
let isOpening = $state(false);
8995
let votedGrade = $state<TaskGrade | null>(null);
9096
let voteAbortController: AbortController | null = null;
@@ -194,14 +200,14 @@
194200
>
195201
<span class="sr-only">
196202
Voted grade: {getTaskGradeLabel(displayGrade)}{relativeEvaluationLabel &&
197-
(showNeutralBadge || relativeEvaluationLabel !== '±0')
203+
shouldShowRelativeEvaluation
198204
? `, relative evaluation: ${relativeEvaluationLabel}`
199205
: ''}{isProvisional ? ', provisional' : ''}
200206
</span>
201207

202208
<GradeLabel taskGrade={displayGrade} {defaultPadding} {defaultWidth} {reducedWidth} />
203209

204-
{#if taskResult.grade !== TaskGrade.PENDING && latestMedianGrade && (showNeutralBadge || relativeEvaluationLabel !== '±0')}
210+
{#if taskResult.grade !== TaskGrade.PENDING && latestMedianGrade && shouldShowRelativeEvaluation}
205211
<RelativeEvaluationBadge
206212
officialGrade={taskResult.grade}
207213
medianGrade={latestMedianGrade}

0 commit comments

Comments
 (0)