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 a2d71ab
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 19 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

Check failure on line 557 in components/Home/Home.vue

View workflow job for this annotation

GitHub Actions / Cypress (ubuntu-latest, 20)

Argument of type '{ onExploreClick: any; onFavoriteClick: any; onToggleFavoriteMode: any; onToggleNoteBookMode: any; onZoomClick: any; }' is not assignable to parameter of type 'Partial<{}> & Omit<{ readonly explorerModeEnabled: boolean; onFavoriteClick?: ((poi: ApiPoi) => any) | undefined; onExploreClick?: ((poi: ApiPoi) => any) | undefined; onZoomClick?: ((poi: ApiPoi) => any) | undefined; onToggleFavoriteMode?: (() => any) | undefined; onToggleNoteBookMode?: (() => any) | undefined; } & ...'.
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
29 changes: 14 additions & 15 deletions components/MainMap/FavoriteMenu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,17 @@ 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
defineProps<{
explorerModeEnabled: boolean
}>()
const emit = defineEmits(['toggleFavoriteMode', 'toggleNoteBookMode'])
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 device = useDevice()
const notebookModal = ref<boolean>(false)
Expand All @@ -24,9 +28,9 @@ 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 +39,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 +106,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 a2d71ab

Please sign in to comment.