fix: show both tags if unique
This commit is contained in:
parent
7b3bf2c51e
commit
6f17a69e26
1 changed files with 31 additions and 11 deletions
|
|
@ -3,7 +3,9 @@
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import type { Cell } from 'wx-svelte-grid'
|
import type { Cell } from 'wx-svelte-grid'
|
||||||
import type { Character } from '$lib/types/api/entities'
|
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 CharacterTag from '$lib/components/tags/CharacterTag.svelte'
|
||||||
|
import { CHARACTER_SEASON_NAMES, CHARACTER_SERIES_NAMES } from '$lib/types/enums'
|
||||||
|
|
||||||
const { row }: Cell = $props()
|
const { row }: Cell = $props()
|
||||||
|
|
||||||
|
|
@ -18,26 +20,44 @@
|
||||||
return nameObj.en || nameObj.ja || '—'
|
return nameObj.en || nameObj.ja || '—'
|
||||||
})
|
})
|
||||||
|
|
||||||
// Check if character has season (seasonal variant)
|
// Get season text for comparison
|
||||||
const hasSeason = $derived(
|
const seasonText = $derived.by(() => {
|
||||||
character.season !== undefined && character.season !== null && character.season > 0
|
if (character.season === undefined || character.season === null || character.season <= 0) {
|
||||||
)
|
return null
|
||||||
|
}
|
||||||
// Check if character has series (need to check for non-empty array)
|
return CHARACTER_SEASON_NAMES[character.season] ?? null
|
||||||
const hasSeries = $derived.by(() => {
|
|
||||||
if (!character.series || !Array.isArray(character.series)) return false
|
|
||||||
return character.series.length > 0
|
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// 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>
|
</script>
|
||||||
|
|
||||||
<div class="name-cell">
|
<div class="name-cell">
|
||||||
<span class="name">{displayName}</span>
|
<span class="name">{displayName}</span>
|
||||||
{#if hasSeason || hasSeries}
|
{#if hasSeason || hasDistinctSeries}
|
||||||
<div class="tags">
|
<div class="tags">
|
||||||
{#if hasSeason}
|
{#if hasSeason}
|
||||||
<CharacterTag {character} type="season" />
|
<CharacterTag {character} type="season" />
|
||||||
{/if}
|
{/if}
|
||||||
{#if !hasSeason && hasSeries}
|
{#if hasDistinctSeries}
|
||||||
<CharacterTag {character} type="series" />
|
<CharacterTag {character} type="series" />
|
||||||
{/if}
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue