loader
This commit is contained in:
@@ -1,33 +1,34 @@
|
|||||||
<template>
|
<template>
|
||||||
<v-select
|
<v-btn-toggle
|
||||||
:items="generations"
|
|
||||||
v-model="internalSelected"
|
v-model="internalSelected"
|
||||||
label="Filtrer par génération"
|
mandatory
|
||||||
multiple
|
class="mb-4"
|
||||||
/>
|
>
|
||||||
|
<v-btn :value="0">Tout</v-btn>
|
||||||
|
<v-btn v-for="gen in generations" :key="gen" :value="gen">
|
||||||
|
Génération {{ gen }}
|
||||||
|
</v-btn>
|
||||||
|
</v-btn-toggle>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
export default {
|
export default {
|
||||||
props: {
|
props: {
|
||||||
selected: {
|
selected: {
|
||||||
type: Array,
|
type: [Number],
|
||||||
default: () => []
|
default: 0
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
generations: [1,2,3,4,5,6,7,8,9],
|
generations: [1,2,3,4,5,6,7,8,9],
|
||||||
internalSelected: []
|
internalSelected: this.selected
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
created() {
|
|
||||||
this.internalSelected = this.selected.length ? [...this.selected] : [...this.generations]
|
|
||||||
},
|
|
||||||
watch: {
|
watch: {
|
||||||
selected(newVal) {
|
selected(newVal) {
|
||||||
if (JSON.stringify(newVal) !== JSON.stringify(this.internalSelected)) {
|
if(newVal !== this.internalSelected) {
|
||||||
this.internalSelected = [...newVal]
|
this.internalSelected = newVal
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
internalSelected(newVal) {
|
internalSelected(newVal) {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<template>
|
<template>
|
||||||
<v-app-bar 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">Mon pokédex</v-toolbar-title>
|
||||||
</v-app-bar>
|
</v-app-bar>
|
||||||
</template>
|
</template>
|
||||||
|
|||||||
@@ -1,12 +1,18 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="p-4">
|
<div class="p-4">
|
||||||
<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 pokemons"
|
||||||
:key="poke.pokedex_id"
|
:key="poke.pokedex_id"
|
||||||
:pokemon="poke"
|
:pokemon="poke"
|
||||||
|
v-if="!loading"
|
||||||
/>
|
/>
|
||||||
</v-row>
|
</v-row>
|
||||||
</v-container>
|
</v-container>
|
||||||
@@ -22,8 +28,9 @@ export default {
|
|||||||
components: { PokemonCard, GenerationFilter },
|
components: { PokemonCard, GenerationFilter },
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
selectedGen: [1, 2, 3, 4, 5, 6, 7, 8, 9],
|
selectedGen: 0,
|
||||||
pokemons: [],
|
pokemons: [],
|
||||||
|
loading: false,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
async mounted() {
|
async mounted() {
|
||||||
@@ -31,18 +38,26 @@ export default {
|
|||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
async loadPokemons() {
|
async loadPokemons() {
|
||||||
|
this.loading = true
|
||||||
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
|
||||||
this.pokemons = all.filter(p => this.selectedGen.includes(p.generation))
|
if (this.selectedGen === 0) {
|
||||||
|
this.pokemons = all
|
||||||
|
} else {
|
||||||
|
this.pokemons = all.filter(p => p.generation === this.selectedGen)
|
||||||
|
}
|
||||||
} 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 = []
|
||||||
|
} finally {
|
||||||
|
this.loading = false
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
async onGenChange(gen) {
|
async onGenChange(gen) {
|
||||||
this.selectedGen = Array.isArray(gen) ? gen : [gen]
|
this.selectedGen = gen
|
||||||
await this.loadPokemons()
|
await this.loadPokemons()
|
||||||
},
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
Reference in New Issue
Block a user