Skip to content

Commit

Permalink
refactor: set favorites mode feature flag in store #408
Browse files Browse the repository at this point in the history
  • Loading branch information
wazolab committed Oct 28, 2024
1 parent 9bba529 commit c6fa887
Show file tree
Hide file tree
Showing 14 changed files with 19 additions and 38 deletions.
1 change: 0 additions & 1 deletion components/Home/Embedded.vue
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,6 @@ function toggleExploreAroundSelectedPoi() {
<PoiCardContent
:details-is-external="true"
:poi="selectedFeature"
:favorites-mode-enabled="false"
@explore-click="toggleExploreAroundSelectedPoi"
@zoom-click="goToSelectedFeature"
/>
Expand Down
10 changes: 3 additions & 7 deletions components/Home/Home.vue
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ const menuStore = useMenuStore()
const { apiMenuCategory, features, selectedCategoryIds } = storeToRefs(menuStore)
const favoriteStore = useFavoriteStore()
const { favoritesIds, favoriteAddresses, favoriteFeatures, favoriteCount } = storeToRefs(favoriteStore)
const { config, settings, contents } = useSiteStore()
const siteStore = useSiteStore()
const { config, settings, contents } = siteStore
const { favoritesModeEnabled } = storeToRefs(siteStore)
const { $tracking } = useNuxtApp()
const route = useRoute()
const router = useRouter()
Expand Down Expand Up @@ -141,10 +143,6 @@ onMounted(async () => {
//
// Computed
//
const favoritesModeEnabled = computed(() => {
return settings!.themes[0]?.favorites_mode ?? true
})
const isBottomMenuOpened = computed(() => {
return ((device.value.smallScreen && isPoiCardShown.value) || isMenuItemOpen.value)
})
Expand Down Expand Up @@ -622,7 +620,6 @@ function handlePoiCardClose() {
"
:poi="selectedFeature"
class="tw-grow-0"
:favorites-mode-enabled="favoritesModeEnabled"
@explore-click="toggleExploreAroundSelectedPoi(undefined)"
@favorite-click="toggleFavorite"
@zoom-click="goToSelectedFeature"
Expand Down Expand Up @@ -652,7 +649,6 @@ function handlePoiCardClose() {
"
:poi="selectedFeature"
class="tw-grow-0 tw-text-left tw-h-full"
:favorites-mode-enabled="favoritesModeEnabled"
@explore-click="toggleExploreAroundSelectedPoi(undefined)"
@favorite-click="toggleFavorite"
@zoom-click="goToSelectedFeature"
Expand Down
1 change: 0 additions & 1 deletion components/MainMap/FavoriteNoteBook.vue
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ function removeFavorites() {
<PoisDeck
:pois="favoriteFeatures"
:is-card-light="false"
:favorites-mode-enabled="true"
class="tw-pb-4"
@explore-click="$emit('exploreClick', $event)"
@favorite-click="$emit('favoriteClick', $event)"
Expand Down
1 change: 0 additions & 1 deletion components/PoisCard/PoiCard.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ export default {

const defaultProps = {
poi,
favoritesModeEnabled: false,
}

export const Default = bind(PoiCard, {
Expand Down
1 change: 0 additions & 1 deletion components/PoisCard/PoiCard.story.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import type { ApiPoi } from '~/lib/apiPois'
const defaultProps = {
poi: poi as ApiPoi,
favoritesModeEnabled: false,
}
const props = {
Expand Down
2 changes: 0 additions & 2 deletions components/PoisCard/PoiCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import type { ApiPoi } from '~/lib/apiPois'
withDefaults(defineProps<{
canClose?: boolean
poi: ApiPoi
favoritesModeEnabled: boolean
showImage?: boolean
}>(), {
canClose: true,
Expand Down Expand Up @@ -84,7 +83,6 @@ const closeBtnStyles = reactive({

<PoiCardContent
:poi="poi"
:favorites-mode-enabled="favoritesModeEnabled"
class="tw-px-4 tw-py-5 tw-flex tw-flex-col md:tw-overflow-y-auto tw-flex-grow md:tw-max-h-full tw-box-border tw-w-full md:tw-h-80 md:tw-w-96"
@explore-click="$emit('exploreClick', $event)"
@favorite-click="$emit('favoriteClick', $event)"
Expand Down
3 changes: 1 addition & 2 deletions components/PoisCard/PoiCardContent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import IsochroneTrigger from '~/components/Isochrone/IsochroneTrigger.vue'
//
const props = withDefaults(defineProps<{
detailsIsExternal?: boolean
favoritesModeEnabled: boolean
poi: ApiPoi
}>(), {
detailsIsExternal: false,
Expand All @@ -43,7 +42,7 @@ const { contribMode, isContribEligible, getContributorFields } = useContrib()
const { isModeExplorer } = storeToRefs(useMapStore())
const device = useDevice()
const { enabled: isochroneEnabled } = useIsochrone()
const { explorerModeEnabled } = storeToRefs(useSiteStore())
const { explorerModeEnabled, favoritesModeEnabled } = storeToRefs(useSiteStore())
//
// Data
Expand Down
1 change: 0 additions & 1 deletion components/PoisCard/PoisDeck.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ const defaultProps = {
),
),
selectedPoiIds: points.map(feature => feature.properties.id),
favoritesModeEnabled: false,
}

export const Default = bind(PoisDeck, {
Expand Down
1 change: 0 additions & 1 deletion components/PoisCard/PoisDeck.story.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ const defaultProps = {
),
),
selectedPoiIds: points.map(feature => feature.properties.id as ApiPoiId),
favoritesModeEnabled: false,
isCardLight: true,
}
Expand Down
8 changes: 2 additions & 6 deletions components/PoisCard/PoisDeck.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,10 @@ import type { ApiPoi } from '~/lib/apiPois'
import PoiCard from '~/components/PoisCard/PoiCard.vue'
import PoiCardLight from '~/components/PoisCard/PoiCardLight.vue'
withDefaults(defineProps<{
favoritesModeEnabled?: boolean
defineProps<{
pois: ApiPoi[]
isCardLight: boolean
}>(), {
favoritesModeEnabled: false,
})
}>()
defineEmits<{
(e: 'exploreClick', poi: ApiPoi): void
Expand All @@ -36,7 +33,6 @@ defineEmits<{
:can-close="false"
:poi="item"
class="tw-grow-1 poi-deck"
:favorites-mode-enabled="favoritesModeEnabled"
@explore-click="$emit('exploreClick', $event)"
@favorite-click="$emit('favoriteClick', $event)"
@zoom-click="$emit('zoomClick', $event)"
Expand Down
5 changes: 0 additions & 5 deletions components/PoisDetails/PoiDetails.vue
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,6 @@ export default defineNuxtComponent({
return PropertyTranslationsContextEnum.Details
},
favoritesModeEnabled(): boolean {
return this.settings.themes[0]?.favorites_mode ?? true
},
properties(): ApiPoi['properties'] {
if (!this.isLargeLayeout) {
return this.poi.properties
Expand Down Expand Up @@ -306,7 +302,6 @@ export default defineNuxtComponent({
:route="poiDeps"
:color-fill="colorFill"
:color-line="colorLine"
:favorites-mode-enabled="favoritesModeEnabled"
/>
</template>

Expand Down
4 changes: 0 additions & 4 deletions components/PoisDetails/Route/RouteMap.vue
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,6 @@ export default defineNuxtComponent({
type: String as PropType<string>,
required: true,
},
favoritesModeEnabled: {
type: Boolean,
required: true,
},
},
data(): {
Expand Down
16 changes: 10 additions & 6 deletions pages/embedded.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ import { mapStore as useMapStore } from '~/stores/map'
// Composables
//
const { params, query, path } = useRoute()
const siteStore = useSiteStore()
const mapStore = useMapStore()
const { config, settings } = storeToRefs(siteStore)
const { API_ENDPOINT, API_PROJECT, API_THEME } = config.value!
const siteStore = useSiteStore()
const { config, settings } = siteStore
const { favoritesModeEnabled } = storeToRefs(siteStore)
const { API_ENDPOINT, API_PROJECT, API_THEME } = config!
const { $trackingInit } = useNuxtApp()
//
Expand All @@ -28,12 +29,12 @@ const categoryIds = ref<number[]>()
// Hooks
//
onBeforeMount(() => {
$trackingInit(config.value!)
$trackingInit(config!)
})
const { boundary } = query
if (boundary && typeof boundary === 'string' && settings.value!.polygons_extra) {
const boundaryObject = settings.value!.polygons_extra[boundary]
if (boundary && typeof boundary === 'string' && settings!.polygons_extra) {
const boundaryObject = settings!.polygons_extra[boundary]
if (boundaryObject) {
if (typeof boundaryObject.data === 'string') {
const geojson = (await (await fetch(boundaryObject.data)).json()) as GeoJSON
Expand Down Expand Up @@ -78,6 +79,9 @@ if (categoryIds.value && poiId.value) {
mapStore.setSelectedFeature(data.value!)
}
// Disable Favorite Mode
favoritesModeEnabled.value = false
</script>

<template>
Expand Down
3 changes: 3 additions & 0 deletions stores/site.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ interface State {
locale: string | null
config: VidoConfig | undefined
explorerModeEnabled: boolean
favoritesModeEnabled: boolean
settings: Settings | undefined
contents: ContentEntry[] | undefined
translations: PropertyTranslations | undefined
Expand All @@ -19,6 +20,7 @@ export const siteStore = defineStore('site', {
locale: null,
config: undefined,
explorerModeEnabled: false,
favoritesModeEnabled: false,
settings: undefined,
contents: undefined,
translations: undefined,
Expand All @@ -28,6 +30,7 @@ export const siteStore = defineStore('site', {
this.config = vidoConfig(headers)
this.settings = await getSettings(this.config)
this.explorerModeEnabled = this.settings?.themes[0]?.explorer_mode || true
this.favoritesModeEnabled = this.settings?.themes[0]?.favorites_mode || true
this.contents = await getContents(this.config)
this.translations = await getPropertyTranslations(this.config)
},
Expand Down

0 comments on commit c6fa887

Please sign in to comment.