/ Refactored card icon to its own component
This commit is contained in:
@@ -1,38 +1,7 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="celestial-card">
|
<div class="celestial-card">
|
||||||
<div class="card-wrapper">
|
<div class="card-wrapper">
|
||||||
<div class="card-icon">
|
<celestial-card-icon :type="celestial.type" />
|
||||||
<img
|
|
||||||
v-if="celestial.type === 'planète à lunes'"
|
|
||||||
src="/icons/saturn-and-other-planets.svg"
|
|
||||||
class="fs-icon"
|
|
||||||
alt="planet icon"
|
|
||||||
>
|
|
||||||
<img
|
|
||||||
v-else-if="celestial.type === 'planète'"
|
|
||||||
src="/icons/saturn-planet-shape.svg"
|
|
||||||
class="fs-icon"
|
|
||||||
alt="planet icon"
|
|
||||||
>
|
|
||||||
<img
|
|
||||||
v-else-if="celestial.type === 'lune'"
|
|
||||||
src="/icons/moon-and-stars-in-a-cloud.svg"
|
|
||||||
class="fs-icon"
|
|
||||||
alt="moon icon"
|
|
||||||
>
|
|
||||||
<img
|
|
||||||
v-else-if="celestial.type === 'étoile'"
|
|
||||||
src="/icons/sun-shape.svg"
|
|
||||||
class="fs-icon"
|
|
||||||
alt="moon icon"
|
|
||||||
>
|
|
||||||
<img
|
|
||||||
v-else
|
|
||||||
src="/icons/stars-group.svg"
|
|
||||||
alt="moon icon"
|
|
||||||
class="fs-icon"
|
|
||||||
>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="card-header">
|
<div class="card-header">
|
||||||
<h3 class="heading-3">
|
<h3 class="heading-3">
|
||||||
@@ -86,7 +55,7 @@
|
|||||||
<button
|
<button
|
||||||
class="favourite no-style"
|
class="favourite no-style"
|
||||||
:class="isFav ? 'active' : ''"
|
:class="isFav ? 'active' : ''"
|
||||||
@click="toggleFav(celestial)"
|
@click="toggleFav()"
|
||||||
>
|
>
|
||||||
<span class="icon material-icons-round">favorite</span>
|
<span class="icon material-icons-round">favorite</span>
|
||||||
</button>
|
</button>
|
||||||
@@ -97,33 +66,31 @@
|
|||||||
|
|
||||||
<script>
|
<script>
|
||||||
import { v4 as uuidv4 } from 'uuid'
|
import { v4 as uuidv4 } from 'uuid'
|
||||||
|
import CelestialCardIcon from './CelestialCardIcon.vue'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'CelestialCard',
|
name: 'CelestialCard',
|
||||||
|
components: { CelestialCardIcon },
|
||||||
props: {
|
props: {
|
||||||
celestial: {
|
celestial: {
|
||||||
type: Object,
|
type: Object,
|
||||||
default: () => { return {} }
|
default: () => { return {} }
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
data () {
|
|
||||||
return {
|
|
||||||
type: 'unknown'
|
|
||||||
}
|
|
||||||
},
|
|
||||||
computed: {
|
computed: {
|
||||||
isFav () {
|
isFav () {
|
||||||
return this.$store.getters.isFav(this.celestial.id)
|
return this.$store.getters.isFav(this.celestial.id)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
methods: {
|
methods: {
|
||||||
toggleFav: (celestial) => {
|
toggleFav () {
|
||||||
this.$store.dispatch('toggleFav', celestial.id)
|
|
||||||
if (!this.isFav) {
|
if (!this.isFav) {
|
||||||
this.$store.dispatch('toasts/pushToast', {
|
this.$store.dispatch('toasts/pushToast', {
|
||||||
id: uuidv4(),
|
id: uuidv4(),
|
||||||
title: 'Favori ajouté',
|
title: 'Favori ajouté',
|
||||||
message: `${celestial.name} a été ajouté à la liste des favoris.`,
|
message: `${this.celestial.name} a été ajouté à la liste des favoris.`,
|
||||||
category: 'valid',
|
category: 'valid',
|
||||||
timer: 3
|
timer: 3
|
||||||
})
|
})
|
||||||
@@ -131,11 +98,12 @@ export default {
|
|||||||
this.$store.dispatch('toasts/pushToast', {
|
this.$store.dispatch('toasts/pushToast', {
|
||||||
id: uuidv4(),
|
id: uuidv4(),
|
||||||
title: 'Favori retiré',
|
title: 'Favori retiré',
|
||||||
message: `${celestial.name} a été retiré de la liste des favoris.`,
|
message: `${this.celestial.name} a été retiré de la liste des favoris.`,
|
||||||
category: 'valid',
|
category: 'valid',
|
||||||
timer: 3
|
timer: 3
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
this.$store.dispatch('toggleFav', this.celestial.id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -157,23 +125,6 @@ export default {
|
|||||||
flex-flow: column;
|
flex-flow: column;
|
||||||
align-items: stretch;
|
align-items: stretch;
|
||||||
|
|
||||||
.card-icon {
|
|
||||||
display: block;
|
|
||||||
position: absolute;
|
|
||||||
top: 20px;
|
|
||||||
bottom: 20px;
|
|
||||||
left: 0;
|
|
||||||
right: 0;
|
|
||||||
user-select: none;
|
|
||||||
pointer-events: none;
|
|
||||||
opacity: 4%;
|
|
||||||
img {
|
|
||||||
height: 100%;
|
|
||||||
width: 100%;
|
|
||||||
z-index: -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
> * {
|
> * {
|
||||||
flex: 0 1 auto;
|
flex: 0 1 auto;
|
||||||
}
|
}
|
||||||
|
|||||||
66
full-skies-nuxt/components/celestials/CelestialCardIcon.vue
Normal file
66
full-skies-nuxt/components/celestials/CelestialCardIcon.vue
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
<template>
|
||||||
|
<div class="card-icon">
|
||||||
|
<img
|
||||||
|
v-if="type === 'planète à lunes'"
|
||||||
|
src="/icons/saturn-and-other-planets.svg"
|
||||||
|
class="fs-icon"
|
||||||
|
alt="planet icon"
|
||||||
|
>
|
||||||
|
<img
|
||||||
|
v-else-if="type === 'planète'"
|
||||||
|
src="/icons/saturn-planet-shape.svg"
|
||||||
|
class="fs-icon"
|
||||||
|
alt="planet icon"
|
||||||
|
>
|
||||||
|
<img
|
||||||
|
v-else-if="type === 'lune'"
|
||||||
|
src="/icons/moon-and-stars-in-a-cloud.svg"
|
||||||
|
class="fs-icon"
|
||||||
|
alt="moon icon"
|
||||||
|
>
|
||||||
|
<img
|
||||||
|
v-else-if="type === 'étoile'"
|
||||||
|
src="/icons/sun-shape.svg"
|
||||||
|
class="fs-icon"
|
||||||
|
alt="moon icon"
|
||||||
|
>
|
||||||
|
<img
|
||||||
|
v-else
|
||||||
|
src="/icons/stars-group.svg"
|
||||||
|
alt="moon icon"
|
||||||
|
class="fs-icon"
|
||||||
|
>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
export default {
|
||||||
|
name: 'CelestialCardIcon',
|
||||||
|
|
||||||
|
props: {
|
||||||
|
type: {
|
||||||
|
type: String,
|
||||||
|
default: () => { return '' }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style lang="scss">
|
||||||
|
.card-icon {
|
||||||
|
display: block;
|
||||||
|
position: absolute;
|
||||||
|
top: 20px;
|
||||||
|
bottom: 20px;
|
||||||
|
left: 0;
|
||||||
|
right: 0;
|
||||||
|
user-select: none;
|
||||||
|
pointer-events: none;
|
||||||
|
opacity: 4%;
|
||||||
|
img {
|
||||||
|
height: 100%;
|
||||||
|
width: 100%;
|
||||||
|
z-index: -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
||||||
Reference in New Issue
Block a user