From 665bb18cb54827ae1d24dcc4aced71b2f448dcf6 Mon Sep 17 00:00:00 2001 From: Alexis <35.alexis.pele@gmail.com> Date: Tue, 9 Mar 2021 17:43:39 +0100 Subject: [PATCH 01/12] Refactored Celestials vue to use the composition API (just a test) --- src/plugins/methods/index.ts | 9 ++++++-- src/views/celestials/Celestials.vue | 36 ++++++++++++----------------- 2 files changed, 22 insertions(+), 23 deletions(-) diff --git a/src/plugins/methods/index.ts b/src/plugins/methods/index.ts index cad386a..57f7d9e 100644 --- a/src/plugins/methods/index.ts +++ b/src/plugins/methods/index.ts @@ -21,6 +21,11 @@ export const addCelestialType = (celestial: any) => { return celestial; }; -export default { - addCelestialType +export const addCelestialsType = (celestials: any) => { + return celestials.map((e: any) => addCelestialType(e)); }; + +export default { + addCelestialType, + addCelestialsType +}; \ No newline at end of file diff --git a/src/views/celestials/Celestials.vue b/src/views/celestials/Celestials.vue index dd50182..10e20b9 100644 --- a/src/views/celestials/Celestials.vue +++ b/src/views/celestials/Celestials.vue @@ -16,12 +16,12 @@ From 5b3f4d19ec02b46d4c49ce52aa3ec686b7e0e2ab Mon Sep 17 00:00:00 2001 From: Alexis <35.alexis.pele@gmail.com> Date: Fri, 12 Mar 2021 16:34:29 +0100 Subject: [PATCH 02/12] Moved api functions to relevant folders --- src/api/le-systeme-solaire/index.ts | 30 +++++++++++++++++++++++++++++ src/api/wikipedia/index.ts | 0 src/plugins/methods/index.ts | 2 +- src/views/celestials/Celestial.vue | 18 +++-------------- src/views/celestials/Celestials.vue | 14 ++------------ 5 files changed, 36 insertions(+), 28 deletions(-) create mode 100644 src/api/le-systeme-solaire/index.ts create mode 100644 src/api/wikipedia/index.ts diff --git a/src/api/le-systeme-solaire/index.ts b/src/api/le-systeme-solaire/index.ts new file mode 100644 index 0000000..c5e29ba --- /dev/null +++ b/src/api/le-systeme-solaire/index.ts @@ -0,0 +1,30 @@ +import axios from "axios"; + +/** + * Fetches the API for all celestial bodies + * @returns Array of celestials in the API + */ +export const fetchCelestials = (): Promise => { + return axios + .get("https://api.le-systeme-solaire.net/rest/bodies/") + .then(res => { + return res.data.bodies; + }); +}; + +/** + * Fetches the API for all celestial bodies + * @returns Array of celestials in the API + */ +export const fetchCelestial = (slug: string): Promise => { + return axios + .get(`https://api.le-systeme-solaire.net/rest/bodies/${slug}`) + .then(res => { + return res.data; + }); +}; + +export default { + fetchCelestials, + fetchCelestial +}; diff --git a/src/api/wikipedia/index.ts b/src/api/wikipedia/index.ts new file mode 100644 index 0000000..e69de29 diff --git a/src/plugins/methods/index.ts b/src/plugins/methods/index.ts index 57f7d9e..acdde32 100644 --- a/src/plugins/methods/index.ts +++ b/src/plugins/methods/index.ts @@ -28,4 +28,4 @@ export const addCelestialsType = (celestials: any) => { export default { addCelestialType, addCelestialsType -}; \ No newline at end of file +}; diff --git a/src/views/celestials/Celestial.vue b/src/views/celestials/Celestial.vue index 332d796..576553e 100644 --- a/src/views/celestials/Celestial.vue +++ b/src/views/celestials/Celestial.vue @@ -19,7 +19,8 @@ import { defineComponent } from "vue"; // API -import axios from "axios"; +import { fetchCelestial } from "@/api/le-systeme-solaire"; + // Global methods import { addCelestialType } from "@/plugins/methods"; import NestLoader from "@/components/NestLoader.vue"; @@ -47,7 +48,7 @@ export default defineComponent({ mounted() { // Fetches from API... - this.fetchCelestial() + fetchCelestial(this.slug) .then(res => { // Adds type after fake loading (it's just to showcase the spinner tbh) setTimeout(() => { @@ -58,19 +59,6 @@ export default defineComponent({ .catch(() => { this.error = "Impossible de récupérer l'astre demandé."; }); - }, - - methods: { - /** - * Fetches celestial body from API - */ - fetchCelestial(): Promise { - return axios - .get(`https://api.le-systeme-solaire.net/rest/bodies/${this.slug}`) - .then(res => { - return res.data; - }); - } } }); diff --git a/src/views/celestials/Celestials.vue b/src/views/celestials/Celestials.vue index 10e20b9..57685a1 100644 --- a/src/views/celestials/Celestials.vue +++ b/src/views/celestials/Celestials.vue @@ -19,7 +19,8 @@ import { defineComponent, onMounted, ref } from "vue"; // API -import axios from "axios"; +import { fetchCelestials } from "@/api/le-systeme-solaire"; + // Global methods import { addCelestialsType } from "@/plugins/methods"; @@ -41,17 +42,6 @@ export default defineComponent({ setup() { const celestials = ref(Array()); - /** - * Fetches celestial bodies from API - */ - const fetchCelestials = (): Promise => { - return axios - .get("https://api.le-systeme-solaire.net/rest/bodies/") - .then(res => { - return res.data.bodies; - }); - }; - const getCelestials = async () => { celestials.value = await fetchCelestials(); celestials.value = addCelestialsType(celestials.value); From 49252a2c14509e8d5ad9ff45733058a95eb509d3 Mon Sep 17 00:00:00 2001 From: Alexis <35.alexis.pele@gmail.com> Date: Fri, 19 Mar 2021 17:33:51 +0100 Subject: [PATCH 03/12] Added store functions to add a favourite --- src/store/index.ts | 38 +++++++++++++++++++++++++++--- src/views/celestials/Celestial.vue | 29 ++++++++++++++++------- 2 files changed, 56 insertions(+), 11 deletions(-) diff --git a/src/store/index.ts b/src/store/index.ts index 187b4cb..765e2f0 100644 --- a/src/store/index.ts +++ b/src/store/index.ts @@ -1,8 +1,40 @@ import { createStore } from "vuex"; export default createStore({ - state: {}, - mutations: {}, - actions: {}, + state: () => ({ + user: { + favourites: Array<{ id: string }>() + } + }), + getters: { + // Returns the number of favs for the user + favCount: (state): number => { + return state.user.favourites.length; + }, + // Returns true if celestial is fav + isAlreadyFav: state => (celestialId: string) => { + return state.user.favourites.find(fav => fav.id === celestialId); + } + }, + mutations: { + addFav: (state, celestialId: string) => { + state.user.favourites.push({ id: celestialId }); + }, + removeFav: (state, celestialId: string) => { + state.user.favourites = state.user.favourites.filter(fav => fav.id != celestialId); + } + }, + actions: { + toggleFav: ({ commit, getters }, celestialId: string) => { + // If the celestial is not faved + if (!getters.isAlreadyFav(celestialId)) { + // ... favs it + commit("addFav", celestialId); + } else { + // ...else unfavs + commit("removeFav", celestialId); + } + } + }, modules: {} }); diff --git a/src/views/celestials/Celestial.vue b/src/views/celestials/Celestial.vue index 576553e..50cb7cc 100644 --- a/src/views/celestials/Celestial.vue +++ b/src/views/celestials/Celestial.vue @@ -1,6 +1,6 @@ diff --git a/src/assets/scss/_animations.scss b/src/assets/scss/_animations.scss index db14edc..164ec77 100644 --- a/src/assets/scss/_animations.scss +++ b/src/assets/scss/_animations.scss @@ -36,6 +36,15 @@ } } +@keyframes slideFromRight { + from { + transform: translateX(100%); + } + to { + transform: translateX(0); + } +} + @keyframes paneBgAround { 0% { background-position: -10vw 0%; diff --git a/src/assets/scss/_variables.scss b/src/assets/scss/_variables.scss index 12c47f9..bec6060 100644 --- a/src/assets/scss/_variables.scss +++ b/src/assets/scss/_variables.scss @@ -8,6 +8,16 @@ $space-blue-600: #234e69; $space-blue-500: #457b9d; $space-blue-300: #a8dadc; +$blue: #306BAC; +$green: #1c8267; +$orange: #ff9844; +$red: #9f2042; + +$info: $blue; +$valid: $green; +$warning: $orange; +$danger: $red; + $primary: $space-blue-700; $primary-light: $space-blue-600; diff --git a/src/components/toast/ToastCard.vue b/src/components/toast/ToastCard.vue new file mode 100644 index 0000000..2f8fb8e --- /dev/null +++ b/src/components/toast/ToastCard.vue @@ -0,0 +1,61 @@ + + + + + diff --git a/src/components/toast/ToastsList.vue b/src/components/toast/ToastsList.vue new file mode 100644 index 0000000..22c4c3d --- /dev/null +++ b/src/components/toast/ToastsList.vue @@ -0,0 +1,63 @@ + + + + + From ea83e946d87f029b5c0415f30380e0ac36f2d26d Mon Sep 17 00:00:00 2001 From: Alexis <35.alexis.pele@gmail.com> Date: Sat, 20 Mar 2021 00:03:23 +0100 Subject: [PATCH 10/12] Added basic wikipedia thing idk if i'll have time lmao --- src/api/wikipedia/index.ts | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/src/api/wikipedia/index.ts b/src/api/wikipedia/index.ts index e69de29..05c5d77 100644 --- a/src/api/wikipedia/index.ts +++ b/src/api/wikipedia/index.ts @@ -0,0 +1,36 @@ +import axios from "axios"; + +/** + * Get the excerpt of the wikipedia (fr) article for the specific celestial object + * @param celestial A celestial object + */ +export const fetchWikipediaExcerpt = async (celestial: any): Promise => { + let query = 'https://fr.wikipedia.org/w/api.php?action=opensearch'; + + switch (celestial.id) { + case "soleil": + case "lune": + query += `&search=${celestial.id}`; + break; + + case "planète à lunes": + query += `&search=${celestial.id}%20planète`; + break; + + default: + query += `&search=${celestial.id}%20${celestial.type}`; + break; + } + + query += "&limit=1&namespace=0&format=json"; + + console.log(query); + + + const req = await axios.get(query); + return; +}; + +export default { + fetchWikipediaExcerpt +} \ No newline at end of file From bf9d3537b30eaab858029314a7badb85603886a9 Mon Sep 17 00:00:00 2001 From: Alexis <35.alexis.pele@gmail.com> Date: Sun, 21 Mar 2021 00:28:33 +0100 Subject: [PATCH 11/12] Added toast timer functions --- src/App.vue | 2 +- src/components/celestials/CelestialCard.vue | 24 ++++++++++-- src/components/toast/ToastCard.vue | 25 ++++++++++-- src/components/toast/ToastsList.vue | 43 +++++++-------------- src/store/index.ts | 11 +++++- src/store/toasts/index.ts | 21 ++++++++++ 6 files changed, 89 insertions(+), 37 deletions(-) create mode 100644 src/store/toasts/index.ts diff --git a/src/App.vue b/src/App.vue index 04fe9b4..c289db1 100644 --- a/src/App.vue +++ b/src/App.vue @@ -16,7 +16,7 @@ import ToastsList from "@/components/toast/ToastsList.vue"; export default defineComponent({ components: { Navbar, - ToastsList, + ToastsList } }); diff --git a/src/components/celestials/CelestialCard.vue b/src/components/celestials/CelestialCard.vue index 84e7d12..9297a2a 100644 --- a/src/components/celestials/CelestialCard.vue +++ b/src/components/celestials/CelestialCard.vue @@ -85,7 +85,7 @@