add element tag to related characters section
This commit is contained in:
parent
cde15428da
commit
d5a2d4e4c8
2 changed files with 12 additions and 3 deletions
|
|
@ -1,16 +1,23 @@
|
||||||
<svelte:options runes={true} />
|
<svelte:options runes={true} />
|
||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import type { Character } from '$lib/types/api/entities'
|
|
||||||
import type { CharacterSeriesRef } from '$lib/types/api/characterSeries'
|
import type { CharacterSeriesRef } from '$lib/types/api/characterSeries'
|
||||||
import { getElementLabel } from '$lib/utils/element'
|
import { getElementLabel } from '$lib/utils/element'
|
||||||
import { CHARACTER_SEASON_NAMES, CHARACTER_SERIES_NAMES } from '$lib/types/enums'
|
import { CHARACTER_SEASON_NAMES, CHARACTER_SERIES_NAMES } from '$lib/types/enums'
|
||||||
|
|
||||||
type TagType = 'element' | 'season' | 'series'
|
type TagType = 'element' | 'season' | 'series'
|
||||||
|
|
||||||
|
/** Minimal character data needed for tag display */
|
||||||
|
interface CharacterForTag {
|
||||||
|
element?: number | null
|
||||||
|
season?: number | null
|
||||||
|
series?: (number | CharacterSeriesRef)[] | null
|
||||||
|
seriesNames?: string[] | null
|
||||||
|
}
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
/** The character to display the tag for */
|
/** The character to display the tag for */
|
||||||
character: Character
|
character: CharacterForTag
|
||||||
/** Which characteristic to display */
|
/** Which characteristic to display */
|
||||||
type: TagType
|
type: TagType
|
||||||
/** Optional specific series index to display (for multi-series characters) */
|
/** Optional specific series index to display (for multi-series characters) */
|
||||||
|
|
@ -44,7 +51,7 @@
|
||||||
const displayText = $derived.by(() => {
|
const displayText = $derived.by(() => {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case 'element':
|
case 'element':
|
||||||
return getElementLabel(character.element)
|
return getElementLabel(character.element ?? undefined)
|
||||||
|
|
||||||
case 'season':
|
case 'season':
|
||||||
if (character.season === undefined || character.season === null) return null
|
if (character.season === undefined || character.season === null) return null
|
||||||
|
|
|
||||||
|
|
@ -37,6 +37,7 @@
|
||||||
buildKamigameUrl
|
buildKamigameUrl
|
||||||
} from '$lib/utils/external-links'
|
} from '$lib/utils/external-links'
|
||||||
import Button from '$lib/components/ui/Button.svelte'
|
import Button from '$lib/components/ui/Button.svelte'
|
||||||
|
import CharacterTag from '$lib/components/tags/CharacterTag.svelte'
|
||||||
|
|
||||||
// Types
|
// Types
|
||||||
import type { PageData } from './$types'
|
import type { PageData } from './$types'
|
||||||
|
|
@ -324,6 +325,7 @@
|
||||||
class="related-image"
|
class="related-image"
|
||||||
/>
|
/>
|
||||||
<span class="related-name">{related.name.en}</span>
|
<span class="related-name">{related.name.en}</span>
|
||||||
|
<CharacterTag character={related} type="element" />
|
||||||
</a>
|
</a>
|
||||||
{/each}
|
{/each}
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue