Skip to content

Commit

Permalink
feat: add enum type for stars component #147
Browse files Browse the repository at this point in the history
  • Loading branch information
wazolab committed Feb 19, 2024
1 parent 843a021 commit a7bbec3
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 5 deletions.
31 changes: 29 additions & 2 deletions components/Fields/Stars.vue
Original file line number Diff line number Diff line change
@@ -1,28 +1,55 @@
<script lang="ts">
import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome'
import type { PropType } from 'nuxt/dist/app/compat/capi'
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>

<template>
<div class="stars-data tw-text-amber-500 tw-mb-1">
<FontAwesomeIcon
v-for="index in stars"
v-for="(_item, index) in numericProp"
:key="index"
icon="star"
/>
{{ isSNotation ? 'S' : '' }}
</div>
</template>
5 changes: 2 additions & 3 deletions stores/map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,9 @@ export const mapStore = defineStore('map', {
const cleanProperties: { [key: string]: any } = {}

Object.keys(feature.properties).forEach((key) => {
if (IsJsonString(feature.properties[key]))
if (key !== 'stars' && IsJsonString(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 a7bbec3

Please sign in to comment.