Files
gold_land_user/src/pages/GamesPage.vue
T

88 lines
2.3 KiB
Vue
Raw Normal View History

2026-08-01 10:52:38 +02:00
<script setup lang="ts">
import { onMounted } from 'vue'
2026-08-01 10:52:38 +02:00
import { useRouter } from 'vue-router'
import AppHeader from '@/components/common/AppHeader.vue'
import GameCard from '@/components/common/GameCard.vue'
import PrimaryButton from '@/components/common/PrimaryButton.vue'
import { useGamesStore } from '@/stores/games'
import type { GameCatalogItem } from '@/types/catalog.types'
2026-08-01 10:52:38 +02:00
import { useToast } from '@/composables/useToast'
const router = useRouter()
const gamesStore = useGamesStore()
2026-08-01 10:52:38 +02:00
const toast = useToast()
onMounted(() => {
void gamesStore.loadCatalog()
})
function retryLoad() {
void gamesStore.loadCatalog({ force: true })
}
function startGame(game: GameCatalogItem) {
2026-08-01 10:52:38 +02:00
game.route ? router.push(game.route) : toast.show('به زودی!', 'info')
}
</script>
<template>
<div class="page-content page-content--no-nav">
<AppHeader title="بازی‌ها" show-back @back="router.back()" />
<div v-if="gamesStore.catalogLoadStatus === 'loading'" class="games-status card-enter">
در حال بارگذاری بازی‌ها...
</div>
<div
v-else-if="gamesStore.catalogLoadStatus === 'error'"
class="games-status games-status--error card-enter"
>
<p>{{ gamesStore.catalogLoadError ?? 'خطا در دریافت بازی‌ها' }}</p>
<PrimaryButton variant="gold" size="sm" @click="retryLoad">تلاش مجدد</PrimaryButton>
</div>
<div
v-else-if="gamesStore.catalogLoadStatus === 'ready' && gamesStore.catalog.length === 0"
class="games-status card-enter"
>
فعلاً بازی‌ای برای نمایش نیست.
</div>
<div v-else class="games-list">
2026-08-01 10:52:38 +02:00
<GameCard
v-for="(game, i) in gamesStore.catalog"
2026-08-01 10:52:38 +02:00
:key="game.id"
:id="game.id"
:title="game.title"
:description="game.description"
:icon="game.icon"
:color="game.color"
class="card-enter"
:style="{ animationDelay: `${i * 0.05}s` }"
@start="startGame(game)"
/>
</div>
</div>
</template>
<style scoped>
.games-list {
display: flex;
flex-direction: column;
gap: 12px;
}
.games-status {
text-align: center;
padding: 32px 16px;
color: var(--text-muted);
font-size: 0.9375rem;
font-weight: 600;
}
.games-status--error p {
margin-bottom: 14px;
color: #f87171;
}
2026-08-01 10:52:38 +02:00
</style>