Skip to content

Commit

Permalink
refactor: move event from prop to emit #401
Browse files Browse the repository at this point in the history
  • Loading branch information
wazolab committed Oct 28, 2024
1 parent 42a6aa5 commit 9ea7dfd
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 20 deletions.
11 changes: 7 additions & 4 deletions components/Home/Home.vue
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,10 @@ watch(isModeFavorites, async (isEnabled) => {
//
// Methods
//
function goToSelectedFeature() {
function goToSelectedFeature(feature?: ApiPoi) {
if (feature)
mapStore.setSelectedFeature(feature)
if (mapFeaturesRef.value)
mapFeaturesRef.value.goToSelectedFeature()
}
Expand Down Expand Up @@ -553,11 +556,11 @@ function handlePoiCardClose() {
>
<FavoriteMenu
v-if="favoritesModeEnabled"
:explore-around-selected-poi="toggleExploreAroundSelectedPoi"
:go-to-selected-poi="goToSelectedFeature"
:toggle-favorite="toggleFavorite"
@explore-click="toggleExploreAroundSelectedPoi"
@favorite-click="toggleFavorite"
@toggle-favorite-mode="toggleFavoriteMode"
@toggle-note-book-mode="toggleNoteBookMode"
@zoom-click="goToSelectedFeature"
/>
<NavMenu
id="nav-menu"
Expand Down
27 changes: 11 additions & 16 deletions components/MainMap/FavoriteMenu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,24 @@ import type { ApiPoi } from '~/lib/apiPois'
import { mapStore as useMapStore } from '~/stores/map'
import { favoriteStore as useFavoriteStore } from '~/stores/favorite'
const props = defineProps<{
exploreAroundSelectedPoi: Function
goToSelectedPoi: Function
toggleFavorite: Function
const emit = defineEmits<{
(e: 'exploreClick', poi: ApiPoi): void
(e: 'favoriteClick', poi: ApiPoi): void
(e: 'toggleFavoriteMode'): void
(e: 'toggleNoteBookMode'): void
(e: 'zoomClick', poi: ApiPoi): void
}>()
const emit = defineEmits(['toggleFavoriteMode', 'toggleNoteBookMode'])
const device = useDevice()
const notebookModal = ref<boolean>(false)
const mapStore = useMapStore()
const { isModeFavorites } = storeToRefs(mapStore)
const { favoriteCount } = storeToRefs(useFavoriteStore())
function explore(poi: ApiPoi) {
function onExploreClick(poi: ApiPoi) {
notebookModal.value = false
props.exploreAroundSelectedPoi(poi)
emit('exploreClick', poi)
}
function onClose() {
Expand All @@ -35,13 +35,8 @@ function onClose() {
}
function onZoomClick(poi: ApiPoi) {
mapStore.setSelectedFeature(poi)
notebookModal.value = false
props.goToSelectedPoi(poi)
}
function handleFavorite(poi: ApiPoi) {
props.toggleFavorite(poi)
emit('zoomClick', poi)
}
const { $tracking } = useNuxtApp()
Expand Down Expand Up @@ -107,8 +102,8 @@ async function toggleNoteBookMode() {
max-width="80rem"
>
<FavoriteNoteBook
@explore-click="explore"
@favorite-click="handleFavorite"
@explore-click="onExploreClick"
@favorite-click="$emit('favoriteClick', $event)"
@zoom-click="onZoomClick"
@on-close="onClose"
/>
Expand Down

0 comments on commit 9ea7dfd

Please sign in to comment.