From 7a52c109d9e7815101ff7aacc394c09a750c6063 Mon Sep 17 00:00:00 2001 From: Rudo Kemper Date: Wed, 3 Sep 2025 22:30:41 -0400 Subject: [PATCH 1/2] fix: dont allow map request submission for wrong map style + token combo --- components/GenerateMap.vue | 57 +++++++++++++++++++++ components/GenerateMap/MapCanvas.vue | 22 +++++++- components/GenerateMap/MapSidebar.vue | 72 +++++++++++++++++++++++++-- i18n/locales/en.json | 14 ++++-- i18n/locales/es.json | 14 ++++-- i18n/locales/nl.json | 14 ++++-- i18n/locales/pt.json | 14 ++++-- 7 files changed, 183 insertions(+), 24 deletions(-) diff --git a/components/GenerateMap.vue b/components/GenerateMap.vue index 5fd8a40..8606104 100644 --- a/components/GenerateMap.vue +++ b/components/GenerateMap.vue @@ -32,6 +32,8 @@ const selectedLongitude = ref(props.mapLongitude); const selectedStyle = ref(props.availableMapStyles[0].url); const selectedZoom = ref(props.mapZoom); const showModal = ref(false); +const customMapboxStyleRendered = ref(false); +const mapLoadError = ref(false); const emit = defineEmits(["updateMapParams", "handleMapRequest"]); @@ -63,6 +65,14 @@ const updateMapParams = (updateObj: UpdateMapParams) => { selectedStyle.value = value as string; osmEnabled.value = false; emit("updateMapParams", { param: "OsmEnabled", value: false }); + // Reset custom mapbox style rendered state if switching to non-custom style + if ( + typeof value === "string" && + (!value.includes("mapbox://styles/") || + value.includes("mapbox://styles/mapbox/")) + ) { + customMapboxStyleRendered.value = false; + } break; case "Zoom": selectedZoom.value = value as number; @@ -71,6 +81,27 @@ const updateMapParams = (updateObj: UpdateMapParams) => { } }; +/** Handles map style loaded event. */ +const handleMapStyleLoaded = (data: { + style: string; + success: boolean; + error?: string; +}) => { + // Check if this is a custom mapbox style + if ( + data.style.includes("mapbox://styles/") && + !data.style.includes("mapbox://styles/mapbox/") + ) { + if (data.success) { + customMapboxStyleRendered.value = true; + mapLoadError.value = false; + } else { + customMapboxStyleRendered.value = false; + mapLoadError.value = true; + } + } +}; + /** Handles form submission and navigates to the home page. */ const handleFormSubmit = (formData: FormData) => { emit("handleMapRequest", formData); @@ -79,6 +110,27 @@ const handleFormSubmit = (formData: FormData) => { router.push("/"); }, 3000); }; + +/** Resets the map load error state. */ +const resetMapLoadError = () => { + mapLoadError.value = false; +}; + +/** Resets the map rendered state. */ +const resetMapRendered = () => { + customMapboxStyleRendered.value = false; +}; + +// Watch for access token changes to reset error state +watch( + () => localMapboxAccessToken.value, + (newVal) => { + // Reset error state when access token changes + if (newVal !== props.mapboxAccessToken) { + mapLoadError.value = false; + } + }, +);