diff --git a/frontend/src/views/Gallery/Base.vue b/frontend/src/views/Gallery/Base.vue index ba72035a9..8d81c280f 100644 --- a/frontend/src/views/Gallery/Base.vue +++ b/frontend/src/views/Gallery/Base.vue @@ -8,6 +8,7 @@ import romApi from "@/services/api/rom"; import storeGalleryFilter from "@/stores/galleryFilter"; import storeGalleryView from "@/stores/galleryView"; import storeRoms from "@/stores/roms"; +import storePlatforms from "@/stores/platforms"; import type { Events } from "@/types/emitter"; import type { RomSelectEvent } from "@/types/rom"; import { normalizeString, toTop, views } from "@/utils"; @@ -33,6 +34,7 @@ const { searchCursor, platform, } = storeToRefs(romsStore); +const platforms = storePlatforms(); // Event listeners bus const emitter = inject>("emitter"); @@ -184,9 +186,17 @@ function onScroll() { } onMounted(async () => { - const { data: platform } = await platformApi.getPlatform( - Number(route.params.platform) - ); + const platform = platforms.get(Number(route.params.platform)); + if (!platform) { + emitter?.emit("snackbarShow", { + msg: `Platform ${route.params.platform} not found`, + icon: "mdi-close-circle", + color: "red", + timeout: 4000, + }); + return; + } + romsStore.setPlatform(platform); // If platform is different, reset store and fetch roms @@ -219,9 +229,17 @@ onBeforeRouteUpdate(async (to, _) => { // Triggers when change query param of the same route // Reset store if switching to another platform resetGallery(); - const { data: newPlatform } = await platformApi.getPlatform( - Number(to.params.platform) - ); + const newPlatform = platforms.get(Number(route.params.platform)); + if (!newPlatform) { + emitter?.emit("snackbarShow", { + msg: `Platform ${route.params.platform} not found`, + icon: "mdi-close-circle", + color: "red", + timeout: 4000, + }); + return; + } + romsStore.setPlatform(newPlatform); await fetchRoms(); setFilters();