fix: correct target and needed calculation in award detail view

Fixes incorrect calculation of target and needed values in award detail page:
- Changed award.target to award.rules?.target (correct path in JSON structure)
- Added missing Target display card for non-points awards (DXCC, DLD, etc.)
- Added null checks to prevent broken calculations for awards without targets

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2026-01-23 09:33:42 +01:00
parent 36453c8922
commit 24e0e3bfdb

View File

@@ -550,8 +550,8 @@
<div class="summary"> <div class="summary">
{#if entities.length > 0 && entities[0].points !== undefined} {#if entities.length > 0 && entities[0].points !== undefined}
{@const earnedPoints = filteredEntities.reduce((sum, e) => sum + (e.confirmed ? e.points : 0), 0)} {@const earnedPoints = filteredEntities.reduce((sum, e) => sum + (e.confirmed ? e.points : 0), 0)}
{@const targetPoints = award.target} {@const targetPoints = award.rules?.target}
{@const neededPoints = Math.max(0, targetPoints - earnedPoints)} {@const neededPoints = targetPoints !== undefined ? Math.max(0, targetPoints - earnedPoints) : null}
<div class="summary-card"> <div class="summary-card">
<span class="summary-label">Total Combinations:</span> <span class="summary-label">Total Combinations:</span>
<span class="summary-value">{filteredEntities.length}</span> <span class="summary-value">{filteredEntities.length}</span>
@@ -564,6 +564,7 @@
<span class="summary-label">Points:</span> <span class="summary-label">Points:</span>
<span class="summary-value">{earnedPoints}</span> <span class="summary-value">{earnedPoints}</span>
</div> </div>
{#if neededPoints !== null}
<div class="summary-card unworked"> <div class="summary-card unworked">
<span class="summary-label">Needed:</span> <span class="summary-label">Needed:</span>
<span class="summary-value">{neededPoints}</span> <span class="summary-value">{neededPoints}</span>
@@ -572,8 +573,10 @@
<span class="summary-label">Target:</span> <span class="summary-label">Target:</span>
<span class="summary-value">{targetPoints}</span> <span class="summary-value">{targetPoints}</span>
</div> </div>
{/if}
{:else} {:else}
{@const neededCount = award.target ? Math.max(0, award.target - uniqueEntityProgress.worked) : uniqueEntityProgress.total - uniqueEntityProgress.worked} {@const targetCount = award.rules?.target}
{@const neededCount = targetCount !== undefined ? Math.max(0, targetCount - uniqueEntityProgress.worked) : null}
<div class="summary-card"> <div class="summary-card">
<span class="summary-label">Total:</span> <span class="summary-label">Total:</span>
<span class="summary-value">{uniqueEntityProgress.total}</span> <span class="summary-value">{uniqueEntityProgress.total}</span>
@@ -586,10 +589,16 @@
<span class="summary-label">Worked:</span> <span class="summary-label">Worked:</span>
<span class="summary-value">{uniqueEntityProgress.worked}</span> <span class="summary-value">{uniqueEntityProgress.worked}</span>
</div> </div>
{#if neededCount !== null}
<div class="summary-card unworked"> <div class="summary-card unworked">
<span class="summary-label">Needed:</span> <span class="summary-label">Needed:</span>
<span class="summary-value">{neededCount}</span> <span class="summary-value">{neededCount}</span>
</div> </div>
<div class="summary-card" style="background-color: #e3f2fd; border-color: #2196f3;">
<span class="summary-label">Target:</span>
<span class="summary-value">{targetCount}</span>
</div>
{/if}
{/if} {/if}
</div> </div>