Skip to content

Commit

Permalink
chore: remove device plugin + use composable in components
Browse files Browse the repository at this point in the history
  • Loading branch information
wazolab committed Mar 6, 2024
1 parent 33562a7 commit 68ffaef
Show file tree
Hide file tree
Showing 10 changed files with 61 additions and 58 deletions.
15 changes: 10 additions & 5 deletions components/Fields/Phone.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type { PropType } from 'vue'
import { defineNuxtComponent } from '#app'
import ExternalLink from '~/components/UI/ExternalLink.vue'
import useDevice from '~/composables/useDevice'
export default defineNuxtComponent({
components: {
Expand All @@ -16,22 +17,26 @@ export default defineNuxtComponent({
},
},
setup() {
const device = useDevice()
return {
device,
}
},
computed: {
numberFormated(): string {
return this.number.replaceAll(' ', ' ')
},
phone(): boolean {
return this.$device.value.phone
},
},
})
</script>

<template>
<client-only>
<ExternalLink
v-if="phone"
v-if="device.phone"
:href="`tel:${number}`"
:title="$t('fields.phone.callNumber')"
>
Expand Down
13 changes: 9 additions & 4 deletions components/Home/ExplorerOrFavoritesBack.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { mapState } from 'pinia'
import { defineNuxtComponent } from '#app'
import { mapStore } from '~/stores/map'
import useDevice from '~/composables/useDevice'
export default defineNuxtComponent({
components: {
Expand All @@ -12,10 +13,14 @@ export default defineNuxtComponent({
computed: {
...mapState(mapStore, ['isModeFavorites']),
},
device() {
return this.$device
},
setup() {
const device = useDevice()
return {
device,
}
},
emits: {
Expand All @@ -42,7 +47,7 @@ export default defineNuxtComponent({
<p class="tw-ml-2">
{{
$t(
device.value.smallScreen
device.smallScreen
? isModeFavorites
? 'headerMenu.backToMenuFavorites'
: 'headerMenu.backToMenuExplorer'
Expand Down
10 changes: 7 additions & 3 deletions components/Home/Home.vue
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import { menuStore } from '~/stores/menu'
import { Mode, OriginEnum } from '~/utils/types'
import { getHashPart, setHashParts } from '~/utils/url'
import { flattenFeatures } from '~/utils/utilities'
import useDevice from '~/composables/useDevice'
export default defineNuxtComponent({
components: {
Expand Down Expand Up @@ -59,8 +60,11 @@ export default defineNuxtComponent({
},
setup() {
const device = useDevice()
return {
bottomMenu: ref<InstanceType<typeof HTMLDivElement>>(),
device,
}
},
Expand Down Expand Up @@ -111,7 +115,7 @@ export default defineNuxtComponent({
isBottomMenuOpened(): boolean {
return (
(this.$device.value.smallScreen && this.isPoiCardVisible)
(this.device.smallScreen && this.isPoiCardVisible)
|| this.isMenuItemOpen
)
},
Expand All @@ -127,7 +131,7 @@ export default defineNuxtComponent({
},
fitBoundsPaddingOptions(): FitBoundsOptions['padding'] {
if (this.$device.value.smallScreen) {
if (this.device.smallScreen) {
return {
top: 100,
bottom: 50,
Expand Down Expand Up @@ -335,7 +339,7 @@ export default defineNuxtComponent({
this.mode = Mode.EXPLORER
this.goToSelectedFeature()
if (this.$device.value.smallScreen)
if (this.device.smallScreen)
this.showPoi = false
}
else {
Expand Down
14 changes: 10 additions & 4 deletions components/MainMap/FavoriteMenu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import FavoriteIcon from '~/components/UI/FavoriteIcon.vue'
import type { ApiPoi, ApiPoiId } from '~/lib/apiPois'
import { getPois } from '~/lib/apiPois'
import { mapStore } from '~/stores/map'
import useDevice from '~/composables/useDevice'
export default defineNuxtComponent({
components: {
Expand Down Expand Up @@ -47,6 +48,14 @@ export default defineNuxtComponent({
toggleFavorites: () => true,
},
setup() {
const device = useDevice()
return {
device,
}
},
data(): {
isCopied: boolean
favs: ApiPoi[]
Expand All @@ -61,9 +70,6 @@ export default defineNuxtComponent({
computed: {
...mapState(mapStore, ['isModeFavorites']),
smallScreen(): boolean {
return this.$device.value.smallScreen
},
},
methods: {
async fetchFavorites(ids: number[]) {
Expand Down Expand Up @@ -153,7 +159,7 @@ export default defineNuxtComponent({
<div>
<v-dialog
v-model="notebookModal"
:fullscreen="smallScreen"
:fullscreen="device.smallScreen"
max-width="80rem"
>
<FavoriteNoteBook
Expand Down
9 changes: 5 additions & 4 deletions components/MainMap/MapFeatures.vue
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import { filterRouteByCategories, filterRouteByPoiIds } from '~/utils/styles'
import type { LatLng } from '~/utils/types'
import { MapStyleEnum } from '~/utils/types'
import { getHashPart } from '~/utils/url'
import useDevice from '~/composables/useDevice'
type ITMarker = InstanceType<typeof Marker>
Expand Down Expand Up @@ -111,8 +112,12 @@ export default defineNuxtComponent({
default: undefined,
},
},
setup() {
const device = useDevice()
return {
device,
mapBase: ref<InstanceType<typeof MapBase>>(),
}
},
Expand All @@ -136,10 +141,6 @@ export default defineNuxtComponent({
...mapState(menuStore, ['isLoadingFeatures']),
...mapWritableState(mapStore, ['center']),
device() {
return this.$device.value
},
availableStyles(): MapStyleEnum[] {
return [MapStyleEnum.vector, MapStyleEnum.aerial, MapStyleEnum.bicycle]
},
Expand Down
15 changes: 10 additions & 5 deletions components/PoisCard/PoiCardContent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { mapStore } from '~/stores/map'
import { isIOS } from '~/utils/isIOS'
import ContribFieldGroup from '~/components/Fields/ContribFieldGroup.vue'
import type { ContribFields } from '~/composables/useContrib'
import useDevice from '~/composables/useDevice'
export default defineNuxtComponent({
components: {
Expand All @@ -38,6 +39,14 @@ export default defineNuxtComponent({
},
},
setup() {
const device = useDevice()
return {
device,
}
},
data(): {
contribMode: boolean
isContribEligible: (properties: ApiPoiProperties) => boolean
Expand All @@ -56,10 +65,6 @@ export default defineNuxtComponent({
...mapState(mapStore, ['isModeExplorer']),
...mapState(favoritesStore, ['favoritesIds']),
device() {
return this.$device
},
id(): ApiPoiId {
return this.poi.properties.metadata.id
},
Expand Down Expand Up @@ -256,7 +261,7 @@ export default defineNuxtComponent({
class="tw-flex tw-items-center tw-space-x-2 tw-justify-evenly tw-shrink-0 tw-bottom-0 tw-pt-2"
>
<a
v-if="device.value.phone && coordinatesHref"
v-if="device.phone && coordinatesHref"
:href="coordinatesHref"
class="tw-flex tw-flex-col tw-items-center tw-flex-1 tw-h-full tw-p-2 tw-space-y-2 tw-rounded-lg hover:tw-bg-zinc-100"
:title="$t('poiCard.findRoute')"
Expand Down
17 changes: 10 additions & 7 deletions components/PoisDetails/Carousel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { VCarousel, VCarouselItem } from 'vuetify/components/VCarousel'
import { defineNuxtComponent } from '#app'
import UIPicture from '~/components/UI/UIPicture.vue'
import useDevice from '~/composables/useDevice'
export default defineNuxtComponent({
components: {
Expand All @@ -12,10 +13,12 @@ export default defineNuxtComponent({
VCarouselItem,
},
computed: {
smallScreen(): boolean {
return this.$device.value.smallScreen
},
setup() {
const device = useDevice()
return {
device,
}
},
props: {
Expand All @@ -31,7 +34,7 @@ export default defineNuxtComponent({
<div v-if="images.length === 1" class="tw-margin tw-slide tw-mb-14">
<UIPicture
:src="images[0]"
:media-size="smallScreen ? '100vw' : '66vw'"
:media-size="device.smallScreen ? '100vw' : '66vw'"
:alt="$t('poiCard.image')"
/>
</div>
Expand All @@ -40,12 +43,12 @@ export default defineNuxtComponent({
:show-arrows="false"
:hide-delimiter-background="true"
class="tw-mb-14 print:tw-mb-6"
:height="smallScreen ? 300 : 500"
:height="device.smallScreen ? 300 : 500"
>
<v-carousel-item v-for="(image, i) in images" :key="i">
<UIPicture
:src="image"
:media-size="smallScreen ? '100vw' : '66vw'"
:media-size="device.smallScreen ? '100vw' : '66vw'"
:alt="$t('poiCard.image')"
:img-attrs="{ class: 'h-100 tw-object-cover' }"
/>
Expand Down
1 change: 0 additions & 1 deletion nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ export default defineNuxtConfig({
'@/plugins/settings.ts',
'@/plugins/fontawesome.ts',
'@/plugins/touch.ts',
'@/plugins/device.ts',
{ src: '@/plugins/tracking.ts', mode: 'client' },
'@/plugins/property-translations.ts',
{ src: '@/plugins/pinia-shared-state.ts', mode: 'client' },
Expand Down
19 changes: 0 additions & 19 deletions plugins/device.ts

This file was deleted.

6 changes: 0 additions & 6 deletions utils/histoire-setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,6 @@ export const setupVue3 = defineSetupVue3(({ app, _story, _variant }) => {
p: (field, _context) => field,
pv: (_field, property, _context) => property,
}
app.config.globalProperties.$device = ref({
smallScreen: false,
touch: true,
phone: true,
})

// Plugins
vuetify({ vueApp: app })
})

0 comments on commit 68ffaef

Please sign in to comment.