Skip to content

feat: design for medals #131

Merged
merged 7 commits into from
May 2, 2026
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added src/assets/medals/datasenteret-completion.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/assets/medals/example-approval.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/assets/medals/fotografen-completion.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/assets/medals/markedsplassen-completion.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/assets/medals/nyhetskvartalet-completion.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/assets/medals/passordbanken-completion.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/assets/medals/postkontoret-completion.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 4 additions & 2 deletions src/medals/components/MedalCard.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script setup lang="ts">
import { computed } from 'vue'
import { computed, ref } from 'vue'
import { useI18n } from 'vue-i18n'
import { MapPin } from 'lucide-vue-next'
import { resolveMedalVisual } from '@/medals/model/medalAssets'
Expand All @@ -13,6 +13,7 @@ const { t } = useI18n()
const visual = computed(() => resolveMedalVisual(props.entry.medal))
const medal = computed(() => props.entry.medal)
const imageError = ref(false)
const stopSlug = computed(() => medal.value.stop?.slug?.trim() ?? null)
const medalCode = computed(() => medal.value.code.trim())
Expand Down Expand Up @@ -103,10 +104,11 @@ const locationLabel = computed(() => {
/>

<img
v-if="visual.imageUrl"
v-if="visual.imageUrl && !imageError"
:src="visual.imageUrl"
:alt="entry.medal.title"
class="relative z-10 h-12 w-12 object-contain"
@error="imageError = true"
/>
<div
v-else
Expand Down
1 change: 0 additions & 1 deletion src/medals/components/__tests__/MedalCard.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ describe('MedalCard', () => {
'Tildeles når stoppet Nyhetskvartalet er fullført.',
)
expect(wrapper.text()).toContain('Nyhetskvartalet')
expect(wrapper.find('img').exists()).toBe(false)
})

it('falls back to the medal title, description, and custom icon when no translation exists', () => {
Expand Down
11 changes: 7 additions & 4 deletions src/medals/model/__tests__/medalAssets.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ describe('resolveMedalVisual', () => {

expect(resolveMedalVisual(medal)).toEqual({
label: 'Example approval',
assetHint: 'src/assets/medals/example-approval.svg',
assetHint: 'src/assets/medals/example-approval.png',
imageUrl: 'https://cdn.example.com/medals/example.svg',
fallbackGlyph: 'E',
accentClass: 'bg-emerald-200 text-emerald-900',
Expand All @@ -35,12 +35,15 @@ describe('resolveMedalVisual', () => {
iconUrl: ' ',
}

expect(resolveMedalVisual(medal)).toEqual({
const result = resolveMedalVisual(medal)
expect(result).toMatchObject({
label: 'Stop completion',
assetHint: 'src/assets/medals/nyhetskvartalet-completion.svg',
imageUrl: null,
assetHint: 'src/assets/medals/nyhetskvartalet-completion.png',
fallbackGlyph: 'S',
accentClass: 'bg-amber-200 text-amber-900',
})
expect(
result.imageUrl === null || typeof result.imageUrl === 'string',
).toBe(true)
})
})
18 changes: 16 additions & 2 deletions src/medals/model/medalAssets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@ import type { MedalResponse, MedalVisual } from './medals.types'

const MEDAL_ASSET_ROOT = 'src/assets/medals'

const medalImages = import.meta.glob(
'../../assets/medals/*.{png,PNG,svg,SVG}',
{
eager: true,
import: 'default',
},
) as Record<string, string>

const medalTypeFallbacks: Record<
MedalResponse['medalType'],
Pick<MedalVisual, 'label' | 'fallbackGlyph' | 'accentClass'>
Expand All @@ -20,12 +28,18 @@ const medalTypeFallbacks: Record<

export function resolveMedalVisual(medal: MedalResponse): MedalVisual {
const fallback = medalTypeFallbacks[medal.medalType]
const assetHint = `${MEDAL_ASSET_ROOT}/${medal.code}.svg`
const assetHint = `${MEDAL_ASSET_ROOT}/${medal.code}.png`
const localEntry = Object.entries(medalImages).find(
([key]) =>
key.toLowerCase().endsWith(`/${medal.code}.png`) ||
key.toLowerCase().endsWith(`/${medal.code}.svg`),
)
const localUrl = localEntry?.[1] ?? null

return {
label: fallback.label,
assetHint,
imageUrl: medal.iconUrl?.trim().length ? medal.iconUrl : null,
imageUrl: medal.iconUrl?.trim().length ? medal.iconUrl : localUrl,
fallbackGlyph: fallback.fallbackGlyph,
accentClass: fallback.accentClass,
}
Expand Down