From 84d0091de25a9eb732c13349c6b5316fafe7c85f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?No=C3=A9=20Viricel?= <38253764+wazolab@users.noreply.github.com> Date: Thu, 22 Feb 2024 10:48:50 +0100 Subject: [PATCH] fix: always one star on favorite notebook (#160) --- components/Fields/Stars.vue | 30 ++++++++++++++++++++++++++++-- stores/map.ts | 15 +++++++-------- 2 files changed, 35 insertions(+), 10 deletions(-) diff --git a/components/Fields/Stars.vue b/components/Fields/Stars.vue index f7b03de2e..2b25af0e0 100644 --- a/components/Fields/Stars.vue +++ b/components/Fields/Stars.vue @@ -1,18 +1,33 @@ diff --git a/stores/map.ts b/stores/map.ts index bdec8e354..3b035b3e8 100644 --- a/stores/map.ts +++ b/stores/map.ts @@ -44,26 +44,25 @@ export const mapStore = defineStore('map', { } else { const goodFeature = feature - const IsJsonString = (str: string) => { + function isJsonObject(item: string): boolean { + let value = false try { - JSON.parse(str) + value = JSON.parse(item) } catch (e) { return false } - return true + + return typeof value === 'object' && value !== null } if (feature?.properties) { const cleanProperties: { [key: string]: any } = {} Object.keys(feature.properties).forEach((key) => { - if (IsJsonString(feature.properties[key])) { + if (isJsonObject(feature.properties[key])) cleanProperties[key] = JSON.parse(feature.properties[key]) - } else { - cleanProperties[key] = feature.properties[key] - } + else cleanProperties[key] = feature.properties[key] }) - goodFeature.properties = cleanProperties as ApiPoiProperties }