Skip to content

Commit

Permalink
fix: always one star on favorite notebook (#160)
Browse files Browse the repository at this point in the history
  • Loading branch information
wazolab authored and frodrigo committed Feb 22, 2024
1 parent 5b1ee9a commit 84d0091
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 10 deletions.
30 changes: 28 additions & 2 deletions components/Fields/Stars.vue
Original file line number Diff line number Diff line change
@@ -1,28 +1,54 @@
<template>
<div class="stars-data tw-text-amber-500 tw-mb-1">
<FontAwesomeIcon
v-for="index in new Array(stars)"
v-for="(_item, index) in numericProp"
:key="index"
icon="star"
/>
{{ isSNotation ? 'S' : '' }}
</div>
</template>

<script lang="ts">
import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome'
import type { PropType } from 'vue'
import { defineNuxtComponent } from '#app'
enum StarsEnum {
One = '1',
OneS = '1S',
Two = '2',
TwoS = '2S',
Three = '3',
ThreeS = '3S',
Four = '4',
FourS = '4S',
Five = '5',
FiveS = '5S',
}
export default defineNuxtComponent({
components: {
FontAwesomeIcon,
},
props: {
stars: {
type: Number,
type: String as PropType<StarsEnum>,
required: true,
},
},
computed: {
isSNotation(): boolean {
return Boolean(this.stars.includes('S'))
},
numericProp(): number {
let stars: string = this.stars
if (this.isSNotation) stars = this.stars.slice(0, -1)
return Number(stars)
},
},
})
</script>
15 changes: 7 additions & 8 deletions stores/map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit 84d0091

Please sign in to comment.