From 0ec0f681b24142bd63f6cc753f82b6faec21d7b9 Mon Sep 17 00:00:00 2001 From: Nathan Tien You Date: Wed, 8 Jul 2026 08:54:04 +0200 Subject: [PATCH] fix: prevent fetching clusters when no route is selected --- app/components/map/map.client.vue | 3 +++ app/composables/useSvgImage.ts | 16 ++++++++++++++++ nuxt.config.ts | 28 ++++------------------------ 3 files changed, 23 insertions(+), 24 deletions(-) create mode 100644 app/composables/useSvgImage.ts diff --git a/app/components/map/map.client.vue b/app/components/map/map.client.vue index bafdb58..93df332 100644 --- a/app/components/map/map.client.vue +++ b/app/components/map/map.client.vue @@ -36,6 +36,9 @@ const map = useMap("main"); watchEffect(async () => { const allClusters = []; for (const routeId of store.selectedRouteIds) { + if (routeId === undefined) { + continue; + } const apiClusters = await $fetch( `https://data.mobilites-m.fr/api/routers/default/index/routes/${routeId}/clusters`, ); diff --git a/app/composables/useSvgImage.ts b/app/composables/useSvgImage.ts new file mode 100644 index 0000000..5bc0a41 --- /dev/null +++ b/app/composables/useSvgImage.ts @@ -0,0 +1,16 @@ +const clustersRequest = $fetch( + "https://pass.mobilites-m.fr/assets/icons/clusters.svg", +); + +const image = new Image(); +const imageLoadPromise = new Promise((resolve) => { + image.onload = resolve; +}); +clustersRequest.then((blob) => { + image.src = URL.createObjectURL(blob); +}); +await Promise.all([imageLoadPromise, clustersRequest]); // Wait for the image to load + +export const useSvgImage = () => { + return useState("cluster.svg", () => image); +}; diff --git a/nuxt.config.ts b/nuxt.config.ts index e1b957c..d357b3c 100644 --- a/nuxt.config.ts +++ b/nuxt.config.ts @@ -1,27 +1,7 @@ // https://nuxt.com/docs/api/configuration/nuxt-config export default defineNuxtConfig({ - compatibilityDate: "2025-07-15", - devtools: { enabled: false }, - modules: ["@nuxt/eslint", "nuxt-maplibre", "@pinia/nuxt"], - vite: { - optimizeDeps: { - // noDiscovery: true, - // include: ["maplibre-gl"], - }, - }, - // hooks: { - // "pages:extend"(pages) { - // pages.push({ - // name: "lines", - // path: "/lines/", - // file: "~/pages/lines/[line_id]/cluster/[cluster_id]/index.vue", - // }); - // pages.push({ - // name: "line_id", - // path: "/lines/:id()", - - // file: "~/pages/lines/[line_id]/cluster/[cluster_id]/index.vue", - // }); - // }, - // }, + compatibilityDate: "2025-07-15", + devtools: { enabled: false }, + modules: ["@nuxt/eslint", "nuxt-maplibre", "@pinia/nuxt"], + ssr: true, });