fix: show both tags if unique

This commit is contained in:
Justin Edmund 2025-12-15 18:30:50 -08:00
parent 7b3bf2c51e
commit 6f17a69e26

View file

@ -3,7 +3,9 @@
<script lang="ts">
import type { Cell } from 'wx-svelte-grid'
import type { Character } from '$lib/types/api/entities'
import type { CharacterSeriesRef } from '$lib/types/api/characterSeries'
import CharacterTag from '$lib/components/tags/CharacterTag.svelte'
import { CHARACTER_SEASON_NAMES, CHARACTER_SERIES_NAMES } from '$lib/types/enums'
const { row }: Cell = $props()
@ -18,26 +20,44 @@
return nameObj.en || nameObj.ja || '—'
})
// Check if character has season (seasonal variant)
const hasSeason = $derived(
character.season !== undefined && character.season !== null && character.season > 0
)
// Check if character has series (need to check for non-empty array)
const hasSeries = $derived.by(() => {
if (!character.series || !Array.isArray(character.series)) return false
return character.series.length > 0
// Get season text for comparison
const seasonText = $derived.by(() => {
if (character.season === undefined || character.season === null || character.season <= 0) {
return null
}
return CHARACTER_SEASON_NAMES[character.season] ?? null
})
// Get first series text for comparison
const seriesText = $derived.by(() => {
if (!character.series || !Array.isArray(character.series) || character.series.length === 0) {
return null
}
const seriesValue = character.series[0] as number | CharacterSeriesRef
if (typeof seriesValue === 'object' && seriesValue !== null && 'name' in seriesValue) {
return seriesValue.name.en
}
if (typeof seriesValue === 'number') {
return CHARACTER_SERIES_NAMES[seriesValue] ?? null
}
return null
})
// Check if character has season (seasonal variant)
const hasSeason = $derived(seasonText !== null)
// Check if character has series with different text than season
const hasDistinctSeries = $derived(seriesText !== null && seriesText !== seasonText)
</script>
<div class="name-cell">
<span class="name">{displayName}</span>
{#if hasSeason || hasSeries}
{#if hasSeason || hasDistinctSeries}
<div class="tags">
{#if hasSeason}
<CharacterTag {character} type="season" />
{/if}
{#if !hasSeason && hasSeries}
{#if hasDistinctSeries}
<CharacterTag {character} type="series" />
{/if}
</div>