This commit is contained in:
jleroy2023
2025-07-15 13:20:57 +02:00
parent e036481ce0
commit 9c25898e9d
3 changed files with 44 additions and 42 deletions

View File

@@ -1,6 +1,6 @@
<template> <template>
<v-app-bar app color="deep-purple accent-4" dark> <v-app-bar app color="deep-purple accent-4" dark>
<v-toolbar-title @click="$router.push('/')" class="text-white">Mon pokédex</v-toolbar-title> <v-toolbar-title @click="$router.push('/')" class="text-white cursor-pointer">Mon pokédex</v-toolbar-title>
</v-app-bar> </v-app-bar>
</template> </template>
<script> <script>

View File

@@ -1,19 +1,16 @@
<template> <template>
<div class="p-4"> <div class="p-4" @scroll.passive="onScroll" ref="scrollContainer" style="height: 80vh; overflow-y: auto;">
<GenerationFilter :selected="selectedGen" @change="onGenChange" /> <GenerationFilter :selected="selectedGen" @change="onGenChange" />
<v-container> <v-container>
<v-row> <v-row>
<v-col cols="12" class="text-center" v-if="loading">
<v-progress-circular indeterminate color="primary" size="48" />
</v-col>
<PokemonCard <PokemonCard
v-for="poke in pokemons" v-for="poke in displayedPokemons"
:key="poke.pokedex_id" :key="poke.pokedex_id"
:pokemon="poke" :pokemon="poke"
v-if="!loading"
/> />
<v-col cols="12" class="text-center" v-if="loadingMore">
<v-progress-circular indeterminate color="primary" size="48" />
</v-col>
</v-row> </v-row>
</v-container> </v-container>
</div> </div>
@@ -29,8 +26,13 @@ export default {
data() { data() {
return { return {
selectedGen: 0, selectedGen: 0,
pokemons: [], allPokemons: [],
displayedPokemons: [],
loading: false, loading: false,
loadingMore: false,
batchSize: 20,
offset: 0,
noMoreData: false,
} }
}, },
async mounted() { async mounted() {
@@ -42,21 +44,45 @@ export default {
try { try {
const res = await axios.get('https://tyradex.vercel.app/api/v1/pokemon') const res = await axios.get('https://tyradex.vercel.app/api/v1/pokemon')
const all = res.data const all = res.data
if (this.selectedGen === 0) { this.allPokemons = this.selectedGen === 0 ? all : all.filter(p => p.generation === this.selectedGen)
this.pokemons = all this.offset = 0
} else { this.noMoreData = false
this.pokemons = all.filter(p => p.generation === this.selectedGen) this.displayedPokemons = []
} this.loadMore()
} catch (error) { } catch (error) {
console.error('Erreur lors du chargement des pokémons :', error) console.error('Erreur lors du chargement des pokémons :', error)
this.pokemons = [] this.allPokemons = []
this.displayedPokemons = []
} finally { } finally {
this.loading = false this.loading = false
} }
}, },
loadMore() {
if (this.noMoreData) return
this.loadingMore = true
setTimeout(() => {
const nextBatch = this.allPokemons.slice(this.offset, this.offset + this.batchSize)
this.displayedPokemons.push(...nextBatch)
this.offset += this.batchSize
if (this.offset >= this.allPokemons.length) {
this.noMoreData = true
}
this.loadingMore = false
}, 500)
},
async onGenChange(gen) { async onGenChange(gen) {
this.selectedGen = gen this.selectedGen = gen
await this.loadPokemons() await this.loadPokemons()
},
onScroll() {
const container = this.$refs.scrollContainer
if (!container) return
if (container.scrollTop + container.clientHeight >= container.scrollHeight - 100) {
if (!this.loadingMore && !this.noMoreData) {
this.loadMore()
}
}
} }
} }
} }

View File

@@ -2,20 +2,16 @@
<v-container class="py-10"> <v-container class="py-10">
<v-card v-if="pokemon" class="mx-auto max-w-xl p-6"> <v-card v-if="pokemon" class="mx-auto max-w-xl p-6">
<h1 class="text-3xl font-bold mb-4">{{ pokemon.name.fr }}</h1> <h1 class="text-3xl font-bold mb-4">{{ pokemon.name.fr }}</h1>
<v-carousel hide-delimiter-background height="400" class="mb-6">
<!-- Carousel sprites -->
<v-carousel hide-delimiter-background height="200" class="mb-6">
<v-carousel-item <v-carousel-item
v-for="(sprite, index) in availableSprites" v-for="(sprite, index) in availableSprites"
:key="index" :key="index"
> >
<img :src="sprite.url" :alt="sprite.label" class="mx-auto h-40" /> <img :src="sprite.url" :alt="sprite.label" class="mx-auto h-80" />
<div class="text-center mt-2 font-semibold">{{ sprite.label }}</div> <div class="text-center mt-2 font-semibold">{{ sprite.label }}</div>
</v-carousel-item> </v-carousel-item>
</v-carousel> </v-carousel>
<p><strong>Génération :</strong> {{ pokemon.generation }}</p> <p><strong>Génération :</strong> {{ pokemon.generation }}</p>
<div class="mb-4"> <div class="mb-4">
<strong>Types :</strong> <strong>Types :</strong>
<span v-for="type in pokemon.types" :key="type.name" class="inline-flex items-center mr-3"> <span v-for="type in pokemon.types" :key="type.name" class="inline-flex items-center mr-3">
@@ -23,7 +19,6 @@
{{ type.name }} {{ type.name }}
</span> </span>
</div> </div>
<div class="mb-4"> <div class="mb-4">
<strong>Talents :</strong> <strong>Talents :</strong>
<ul> <ul>
@@ -32,7 +27,6 @@
</li> </li>
</ul> </ul>
</div> </div>
<div class="mb-4"> <div class="mb-4">
<strong>Stats :</strong> <strong>Stats :</strong>
<v-simple-table dense> <v-simple-table dense>
@@ -46,7 +40,6 @@
</tbody> </tbody>
</v-simple-table> </v-simple-table>
</div> </div>
<div class="mb-4"> <div class="mb-4">
<strong>Résistances :</strong> <strong>Résistances :</strong>
<div class="flex flex-wrap gap-3"> <div class="flex flex-wrap gap-3">
@@ -61,23 +54,6 @@
</span> </span>
</div> </div>
</div> </div>
<div class="mb-4">
<strong>Évolution :</strong>
<div>
<div v-if="pokemon.evolution.pre">Précédent: {{ pokemon.evolution.pre.name || 'N/A' }}</div>
<div v-if="pokemon.evolution.next && pokemon.evolution.next.length">
Suivant:
<ul>
<li v-for="evo in pokemon.evolution.next" :key="evo.pokedex_id">
{{ evo.name }} - {{ evo.condition }}
</li>
</ul>
</div>
<div v-if="pokemon.evolution.mega">Méga: {{ pokemon.evolution.mega.name || 'N/A' }}</div>
</div>
</div>
<div class="mb-4"> <div class="mb-4">
<strong>Taille :</strong> {{ pokemon.height }}<br /> <strong>Taille :</strong> {{ pokemon.height }}<br />
<strong>Poids :</strong> {{ pokemon.weight }}<br /> <strong>Poids :</strong> {{ pokemon.weight }}<br />