Added error message (no formatting yet) and loader
This commit is contained in:
84
src/components/NestLoader.vue
Normal file
84
src/components/NestLoader.vue
Normal file
@@ -0,0 +1,84 @@
|
|||||||
|
<template>
|
||||||
|
<div class="fs-loader-wrapper">
|
||||||
|
<div class="fs-loader"></div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script lang="ts">
|
||||||
|
import { defineComponent } from "vue";
|
||||||
|
|
||||||
|
export default defineComponent({
|
||||||
|
name: "nest-loader"
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style lang="scss">
|
||||||
|
.fs-loader-wrapper {
|
||||||
|
padding: 100px 0;
|
||||||
|
.fs-loader {
|
||||||
|
display: block;
|
||||||
|
position: relative;
|
||||||
|
height: 100px;
|
||||||
|
width: 100px;
|
||||||
|
margin: -25px auto 0 auto;
|
||||||
|
border: 2px solid transparent;
|
||||||
|
border-top-color: $white;
|
||||||
|
border-radius: 50%;
|
||||||
|
-webkit-animation: spin7 1.5s ease infinite;
|
||||||
|
animation: spin7 1.5s ease infinite;
|
||||||
|
|
||||||
|
&:before {
|
||||||
|
content: "";
|
||||||
|
position: absolute;
|
||||||
|
top: 14px;
|
||||||
|
right: 14px;
|
||||||
|
bottom: 14px;
|
||||||
|
left: 14px;
|
||||||
|
border: 2px solid transparent;
|
||||||
|
border-radius: 50%;
|
||||||
|
border-top-color: $white;
|
||||||
|
-webkit-animation: spin7 3s linear infinite;
|
||||||
|
animation: spin7 3s linear infinite;
|
||||||
|
}
|
||||||
|
|
||||||
|
&:after {
|
||||||
|
content: "";
|
||||||
|
position: absolute;
|
||||||
|
top: 30px;
|
||||||
|
right: 30px;
|
||||||
|
bottom: 30px;
|
||||||
|
left: 30px;
|
||||||
|
border: 2px solid transparent;
|
||||||
|
border-radius: 50%;
|
||||||
|
border-top-color: $white;
|
||||||
|
-webkit-animation: spin7 1.5s ease infinite;
|
||||||
|
animation: spin7 1.5s ease infinite;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@-webkit-keyframes spin7 {
|
||||||
|
from {
|
||||||
|
-webkit-transform: rotate(0deg);
|
||||||
|
transform: rotate(0deg);
|
||||||
|
}
|
||||||
|
to {
|
||||||
|
-webkit-transform: rotate(359deg);
|
||||||
|
transform: rotate(359deg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@keyframes spin7 {
|
||||||
|
from {
|
||||||
|
-webkit-transform: rotate(0deg);
|
||||||
|
transform: rotate(0deg);
|
||||||
|
-webkit-transform: rotate(0deg);
|
||||||
|
transform: rotate(0deg);
|
||||||
|
}
|
||||||
|
to {
|
||||||
|
-webkit-transform: rotate(359deg);
|
||||||
|
transform: rotate(359deg);
|
||||||
|
-webkit-transform: rotate(359deg);
|
||||||
|
transform: rotate(359deg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -3,6 +3,10 @@
|
|||||||
<header>
|
<header>
|
||||||
<h1 class="heading-1">{{ celestial.name }}</h1>
|
<h1 class="heading-1">{{ celestial.name }}</h1>
|
||||||
</header>
|
</header>
|
||||||
|
<div class="section-content">
|
||||||
|
<div v-if="error">Une erreur est survenue : {{ error }}</div>
|
||||||
|
<div v-if="celestial">{{ celestial }}</div>
|
||||||
|
</div>
|
||||||
</section>
|
</section>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
@@ -18,7 +22,7 @@ export default defineComponent({
|
|||||||
name: "Celestial",
|
name: "Celestial",
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
celestial: {},
|
celestial: Object,
|
||||||
error: ""
|
error: ""
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
@@ -28,6 +32,7 @@ export default defineComponent({
|
|||||||
required: true
|
required: true
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
mounted() {
|
mounted() {
|
||||||
// Fetches from API...
|
// Fetches from API...
|
||||||
this.fetchCelestial()
|
this.fetchCelestial()
|
||||||
@@ -35,23 +40,20 @@ export default defineComponent({
|
|||||||
// ...and add type
|
// ...and add type
|
||||||
this.celestial = addCelestialType(res);
|
this.celestial = addCelestialType(res);
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(() => {
|
||||||
this.error = err.message;
|
this.error = "Impossible de récupérer l'astre demandé.";
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
methods: {
|
methods: {
|
||||||
/**
|
/**
|
||||||
* Fetches celestial bodies from API
|
* Fetches celestial body from API
|
||||||
*/
|
*/
|
||||||
fetchCelestial(): Promise<any> {
|
fetchCelestial(): Promise<any> {
|
||||||
return axios
|
return axios
|
||||||
.get(`https://api.le-systeme-solaire.net/rest/bodies/${this.slug}`)
|
.get(`https://api.le-systeme-solaire.net/rest/bodies/${this.slug}`)
|
||||||
.then(res => {
|
.then(res => {
|
||||||
return res.data;
|
return res.data;
|
||||||
})
|
|
||||||
.catch(err => {
|
|
||||||
this.error = err.message;
|
|
||||||
return [];
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,13 @@
|
|||||||
<h1 class="heading-1">Le système solaire</h1>
|
<h1 class="heading-1">Le système solaire</h1>
|
||||||
</header>
|
</header>
|
||||||
<div class="section-content">
|
<div class="section-content">
|
||||||
<celestials-list :celestials="celestials" />
|
<div v-if="error">Une erreur est survenue : {{ error }}</div>
|
||||||
|
<div v-if="celestials.length > 1">
|
||||||
|
<celestials-list :celestials="celestials" />
|
||||||
|
</div>
|
||||||
|
<div v-else>
|
||||||
|
<nest-loader />
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
</template>
|
</template>
|
||||||
@@ -18,17 +24,31 @@ import axios from "axios";
|
|||||||
import { addCelestialType } from "@/plugins/methods";
|
import { addCelestialType } from "@/plugins/methods";
|
||||||
|
|
||||||
import CelestialsList from "@/components/celestials/CelestialsList.vue";
|
import CelestialsList from "@/components/celestials/CelestialsList.vue";
|
||||||
|
import NestLoader from "@/components/NestLoader.vue";
|
||||||
|
|
||||||
export default defineComponent({
|
export default defineComponent({
|
||||||
name: "Celestials",
|
name: "Celestials",
|
||||||
components: {
|
components: {
|
||||||
CelestialsList
|
CelestialsList,
|
||||||
|
NestLoader
|
||||||
},
|
},
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
celestials: Array<any>()
|
celestials: Array<any>(),
|
||||||
|
error: ""
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
|
mounted() {
|
||||||
|
this.fetchCelestials()
|
||||||
|
.then(res => {
|
||||||
|
this.celestials = this.addType(res);
|
||||||
|
})
|
||||||
|
.catch(() => {
|
||||||
|
this.error = "Impossible de récupérer les astres.";
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
methods: {
|
methods: {
|
||||||
/**
|
/**
|
||||||
* Fetches celestial bodies from API
|
* Fetches celestial bodies from API
|
||||||
@@ -38,10 +58,6 @@ export default defineComponent({
|
|||||||
.get("https://api.le-systeme-solaire.net/rest/bodies/")
|
.get("https://api.le-systeme-solaire.net/rest/bodies/")
|
||||||
.then(res => {
|
.then(res => {
|
||||||
return res.data.bodies;
|
return res.data.bodies;
|
||||||
})
|
|
||||||
.catch(err => {
|
|
||||||
console.log(err);
|
|
||||||
return [];
|
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
@@ -50,15 +66,6 @@ export default defineComponent({
|
|||||||
addType(bodies: Array<any>): Array<any> {
|
addType(bodies: Array<any>): Array<any> {
|
||||||
return bodies.map((e: any) => addCelestialType(e));
|
return bodies.map((e: any) => addCelestialType(e));
|
||||||
}
|
}
|
||||||
},
|
|
||||||
mounted() {
|
|
||||||
this.fetchCelestials()
|
|
||||||
.then(res => {
|
|
||||||
this.celestials = this.addType(res);
|
|
||||||
})
|
|
||||||
.catch(err => {
|
|
||||||
console.log(err);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
Reference in New Issue
Block a user