chore: migrate to script setup style

This commit is contained in:
2024-02-02 18:55:45 +01:00
parent d1bcaf423f
commit 171e1039a7
15 changed files with 3468 additions and 4540 deletions
+4 -12
View File
@@ -16,27 +16,19 @@
</v-layout> </v-layout>
</template> </template>
<script lang='ts'> <script setup lang='ts'>
import { computed, defineComponent, PropType } from 'vue' import { computed, PropType } from 'vue'
import { DanceHallDistance } from '~/graphql/generated/operations' import { DanceHallDistance } from '~/graphql/generated/operations'
export default defineComponent({ const props = defineProps({
name: 'DistanceDisplay',
props: {
distance: { distance: {
type: Object as PropType<DanceHallDistance>, type: Object as PropType<DanceHallDistance>,
required: true required: true
} }
}, })
setup (props) {
const numericDistance = computed(() => const numericDistance = computed(() =>
Number(props.distance.distance / 1000).toLocaleString('sv-SE', { Number(props.distance.distance / 1000).toLocaleString('sv-SE', {
minimumFractionDigits: 2, minimumFractionDigits: 2,
maximumFractionDigits: 2 maximumFractionDigits: 2
})) }))
return {
numericDistance
}
}
})
</script> </script>
+4 -14
View File
@@ -107,19 +107,16 @@
</v-card> </v-card>
</template> </template>
<script lang='ts'> <script setup lang='ts'>
import { format, formatDistanceToNow, parseISO } from 'date-fns' import { format, formatDistanceToNow, parseISO } from 'date-fns'
import { enGB, sv } from 'date-fns/locale' import { enGB, sv } from 'date-fns/locale'
import { computed, defineComponent, getCurrentInstance, PropType } from 'vue' import { computed, getCurrentInstance, PropType } from 'vue'
import { Event } from '~/graphql/generated/operations' import { Event } from '~/graphql/generated/operations'
import DistanceDisplay from '~/components/pages/events/Event/distance.vue' import DistanceDisplay from '~/components/pages/events/Event/distance.vue'
export default defineComponent({ const props = defineProps({
name: 'EventDetail',
components: { DistanceDisplay },
props: {
event: { event: {
type: Object as PropType<Event>, type: Object as PropType<Event>,
required: true required: true
@@ -132,8 +129,7 @@ export default defineComponent({
type: Function, type: Function,
required: true required: true
} }
}, })
setup (props) {
const instance = getCurrentInstance() const instance = getCurrentInstance()
const locale = computed(() => (instance?.proxy.$i18n.locale ?? 'sv') === 'en' ? enGB : sv) const locale = computed(() => (instance?.proxy.$i18n.locale ?? 'sv') === 'en' ? enGB : sv)
const time = computed(() => (props.event.time || '').split('-')[0].replace('.', ':')) const time = computed(() => (props.event.time || '').split('-')[0].replace('.', ':'))
@@ -142,10 +138,4 @@ export default defineComponent({
addSuffix: true, addSuffix: true,
locale: locale.value locale: locale.value
})) }))
return {
weekday,
daysUntil
}
}
})
</script> </script>
+8 -12
View File
@@ -2,7 +2,7 @@
<div> <div>
<v-row v-for="event in events" :key="event.id" wrap> <v-row v-for="event in events" :key="event.id" wrap>
<v-flex xs12> <v-flex xs12>
<Event <event-card
:event="event" :event="event"
:has-user="hasUser" :has-user="hasUser"
:toggle-ignore="toggleIgnore" :toggle-ignore="toggleIgnore"
@@ -12,15 +12,12 @@
</div> </div>
</template> </template>
<script> <script setup lang='ts'>
import Event from '../Event' import { type PropType } from 'vue'
import EventCard from '../Event/index.vue'
import { type Event } from '~/graphql/generated/operations'
export default { defineProps({
name: 'EventList',
components: {
Event
},
props: {
hasUser: { hasUser: {
type: Boolean, type: Boolean,
required: true required: true
@@ -30,9 +27,8 @@ export default {
required: true required: true
}, },
events: { events: {
type: Array, type: Array as PropType<Event[]>,
required: true required: true
} }
} })
}
</script> </script>
+10 -33
View File
@@ -1,5 +1,5 @@
<template> <template>
<div :key="isAuthenticated"> <div :key="isAuthenticated ? 'true' : 'false'">
<v-container :key="range" fluid grid-list-md class="app-fade-in"> <v-container :key="range" fluid grid-list-md class="app-fade-in">
<v-row v-if="!isAuthenticated" wrap> <v-row v-if="!isAuthenticated" wrap>
<v-col xs="12"> <v-col xs="12">
@@ -18,7 +18,7 @@
<template #activator="{ on }"> <template #activator="{ on }">
<v-icon <v-icon
v-on="on" v-on="on"
@click="fetchAddress()" @click="fetchAddressFn()"
> >
mdi-crosshairs-gps mdi-crosshairs-gps
</v-icon> </v-icon>
@@ -32,7 +32,7 @@
<v-icon <v-icon
:disabled="!origin" :disabled="!origin"
v-on="on" v-on="on"
@click="saveOrigin(origin)" @click="saveOriginFn(origin)"
> >
mdi-bookmark-plus-outline mdi-bookmark-plus-outline
</v-icon> </v-icon>
@@ -74,10 +74,10 @@
/> />
</v-col> </v-col>
<v-col cols="12" sm="4"> <v-col cols="12" sm="4">
<v-checkbox v-model="state.includeHidden" :label="$t(&quot;events.includeHidden&quot;)" /> <v-checkbox v-model="state.includeHidden" :label="$t('events.includeHidden')" />
</v-col> </v-col>
</v-row> </v-row>
<list <event-list
:events="events" :events="events"
:has-user="isAuthenticated" :has-user="isAuthenticated"
:toggle-ignore="toggleIgnore" :toggle-ignore="toggleIgnore"
@@ -93,10 +93,9 @@
</div> </div>
</template> </template>
<script lang='ts'> <script setup lang='ts'>
import { computed, defineComponent, ref, watch } from 'vue' import { computed, ref, watch } from 'vue'
import EventList from './List/index.vue'
import List from './List/index.vue'
import { useAuth } from '~/plugins/auth' import { useAuth } from '~/plugins/auth'
import { useTranslation } from '~/plugins/i18n' import { useTranslation } from '~/plugins/i18n'
import { import {
@@ -112,16 +111,11 @@ import {
} from '~/graphql/generated/operations' } from '~/graphql/generated/operations'
import { useState } from '~/store' import { useState } from '~/store'
export default defineComponent({
name: 'EventsPage',
components: {
List
},
setup () {
const state = useState() const state = useState()
const range = computed(() => state.range)
const { t } = useTranslation() const { t } = useTranslation()
state.setTitle(t('app.links.events')) state.setTitle(t('app.links.events'))
const { loading: authLoading, isAuthenticated } = useAuth() const { isAuthenticated } = useAuth()
const variables = ref<FindEventsQueryVariables>({ const variables = ref<FindEventsQueryVariables>({
range: state.range, range: state.range,
includeOrigins: isAuthenticated.value || false, includeOrigins: isAuthenticated.value || false,
@@ -138,7 +132,6 @@ export default defineComponent({
}) })
const events = computed(() => result.value?.events ?? []) const events = computed(() => result.value?.events ?? [])
const origins = computed(() => result.value?.origins ?? []) const origins = computed(() => result.value?.origins ?? [])
const submitting = ref(true)
const ranges = [ const ranges = [
{ name: '1 vecka', value: 'ONE_WEEK' }, { name: '1 vecka', value: 'ONE_WEEK' },
{ name: '2 veckor', value: 'TWO_WEEKS' }, { name: '2 veckor', value: 'TWO_WEEKS' },
@@ -237,20 +230,4 @@ export default defineComponent({
fetchEvents() fetchEvents()
}) })
return {
authLoading,
isAuthenticated,
state,
events,
origins,
submitting,
ranges,
snackbar,
toggleIgnore,
origin,
fetchAddress: fetchAddressFn,
saveOrigin: saveOriginFn
}
}
})
</script> </script>
+3 -6
View File
@@ -21,10 +21,8 @@
</v-card> </v-card>
</template> </template>
<script> <script setup lang='ts'>
export default { defineProps({
name: 'FiltersList',
props: {
model: { model: {
type: Array, type: Array,
required: true required: true
@@ -41,6 +39,5 @@ export default {
type: Function, type: Function,
required: true required: true
} }
} })
}
</script> </script>
+2 -23
View File
@@ -60,9 +60,8 @@
</div> </div>
</template> </template>
<script lang='ts'> <script setup lang='ts'>
import { computed, ref } from 'vue' import { computed, ref } from 'vue'
import List from './List/index.vue' import List from './List/index.vue'
import { useAuth } from '~/plugins/auth' import { useAuth } from '~/plugins/auth'
import { useTranslation } from '~/plugins/i18n' import { useTranslation } from '~/plugins/i18n'
@@ -76,17 +75,11 @@ import {
} from '~/graphql/generated/operations' } from '~/graphql/generated/operations'
import { useState } from '~/store' import { useState } from '~/store'
export default {
name: 'FiltersPage',
components: {
List
},
setup () {
const state = useState() const state = useState()
const { t } = useTranslation() const { t } = useTranslation()
state.setTitle(t('app.links.filters')) state.setTitle(t('app.links.filters'))
const { isAuthenticated } = useAuth() const { isAuthenticated } = useAuth()
const { result, loading, refetch } = useFetchFiltersQuery() const { result, refetch } = useFetchFiltersQuery()
const bands = computed(() => result.value?.bands ?? []) const bands = computed(() => result.value?.bands ?? [])
const cities = computed(() => result.value?.cities ?? []) const cities = computed(() => result.value?.cities ?? [])
const danceHalls = computed(() => result.value?.danceHalls ?? []) const danceHalls = computed(() => result.value?.danceHalls ?? [])
@@ -146,18 +139,4 @@ export default {
default: default:
} }
} }
return {
isAuthenticated,
loading,
bands,
danceHalls,
cities,
municipalities,
states,
snackbar,
toggleIgnore
}
}
}
</script> </script>
+7 -22
View File
@@ -1,5 +1,5 @@
<template> <template>
<div :key="isAuthenticated"> <div :key="isAuthenticated ? 'true' : 'false'">
<v-container fluid grid-list-md class="app-fade-in"> <v-container fluid grid-list-md class="app-fade-in">
<v-layout row wrap> <v-layout row wrap>
<v-flex xs12> <v-flex xs12>
@@ -13,7 +13,7 @@
<template #activator="{ on }"> <template #activator="{ on }">
<v-icon <v-icon
v-on="on" v-on="on"
@click="fetchAddress()" @click="fetchAddressFn()"
> >
mdi-crosshairs-gps mdi-crosshairs-gps
</v-icon> </v-icon>
@@ -27,7 +27,7 @@
<v-icon <v-icon
:disabled="!origin" :disabled="!origin"
v-on="on" v-on="on"
@click="saveOrigin(origin)" @click="saveOriginFn(origin)"
> >
mdi-bookmark-plus-outline mdi-bookmark-plus-outline
</v-icon> </v-icon>
@@ -44,7 +44,7 @@
<template #activator="{ on }"> <template #activator="{ on }">
<v-icon <v-icon
v-on="on" v-on="on"
@click="removeOrigin(o)" @click="removeOriginFn(o)"
> >
mdi-delete-outline mdi-delete-outline
</v-icon> </v-icon>
@@ -65,8 +65,8 @@
</div> </div>
</template> </template>
<script lang='ts'> <script setup lang='ts'>
import { computed, defineComponent, ref } from 'vue' import { computed, ref } from 'vue'
import { useAuth } from '~/plugins/auth' import { useAuth } from '~/plugins/auth'
import { useTranslation } from '~/plugins/i18n' import { useTranslation } from '~/plugins/i18n'
import { import {
@@ -77,14 +77,11 @@ import {
} from '~/graphql/generated/operations' } from '~/graphql/generated/operations'
import { useState } from '~/store' import { useState } from '~/store'
export default defineComponent({
name: 'OriginsPage',
setup () {
const state = useState() const state = useState()
const { t } = useTranslation() const { t } = useTranslation()
state.setTitle(t('app.links.origins')) state.setTitle(t('app.links.origins'))
const { isAuthenticated } = useAuth() const { isAuthenticated } = useAuth()
const { result, loading, refetch } = useFindOriginsQuery() const { result, refetch } = useFindOriginsQuery()
const origins = computed(() => result.value?.origins ?? []) const origins = computed(() => result.value?.origins ?? [])
const snackbar = ref({ active: false, color: 'success', text: '' }) const snackbar = ref({ active: false, color: 'success', text: '' })
const { mutate: doSaveOrigin } = useSaveOriginMutation({}) const { mutate: doSaveOrigin } = useSaveOriginMutation({})
@@ -110,16 +107,4 @@ export default defineComponent({
}) })
const removeOriginFn = (o: string) => const removeOriginFn = (o: string) =>
doRemoveOrigin({ origin: o }).then(() => refetch()) doRemoveOrigin({ origin: o }).then(() => refetch())
return {
isAuthenticated,
loading,
origins,
snackbar,
origin,
saveOrigin: saveOriginFn,
removeOrigin: removeOriginFn,
fetchAddress: fetchAddressFn
}
}
})
</script> </script>
+1 -6
View File
@@ -4,18 +4,13 @@
</div> </div>
</template> </template>
<script> <script setup lang='ts'>
import { getCurrentInstance } from 'vue' import { getCurrentInstance } from 'vue'
import { useState } from '~/store' import { useState } from '~/store'
export default {
name: 'ThemedLayout',
setup () {
const instance = getCurrentInstance() const instance = getCurrentInstance()
const state = useState() const state = useState()
if (instance) { if (instance) {
instance.proxy.$vuetify.theme.dark = state.darkMode instance.proxy.$vuetify.theme.dark = state.darkMode
} }
}
}
</script> </script>
+6 -23
View File
@@ -78,20 +78,14 @@
</v-app> </v-app>
</template> </template>
<script> <script setup lang='ts'>
import { computed, getCurrentInstance, provide, ref } from 'vue' import { computed, getCurrentInstance, provide, ref } from 'vue'
import { DefaultApolloClient } from '@vue/apollo-composable' import { DefaultApolloClient } from '@vue/apollo-composable'
import Themed from './components/themed' import Themed from './components/themed.vue'
import { useAuth } from '~/plugins/auth' import { useAuth } from '~/plugins/auth'
import { useState } from '~/store' import { useState } from '~/store'
export default {
name: 'DefaultLayout',
components: {
Themed
},
setup () {
const instance = getCurrentInstance() const instance = getCurrentInstance()
if (instance) { if (instance) {
provide(DefaultApolloClient, instance.proxy.$apollo) provide(DefaultApolloClient, instance.proxy.$apollo)
@@ -108,7 +102,9 @@ export default {
const { loading, isAuthenticated, user, loginWithRedirect, logout } = const { loading, isAuthenticated, user, loginWithRedirect, logout } =
useAuth(onRedirectCallback) useAuth(onRedirectCallback)
const doLogin = () => { const doLogin = () => {
loginWithRedirect() loginWithRedirect({
appState: { targetUrl: window.location.pathname }
})
} }
const doLogout = () => { const doLogout = () => {
logout({ logout({
@@ -140,18 +136,5 @@ export default {
const nav = ref(false) const nav = ref(false)
locale.value = instance.proxy.$i18n.locale locale.value = instance.proxy.$i18n.locale
const title = computed(() => state.title)
return {
title: state.title,
loading,
isAuthenticated,
user,
doLogin,
doLogout,
darkMode,
locale,
nav
}
}
}
</script> </script>
+4 -1
View File
@@ -6,6 +6,9 @@ export default defineNuxtConfig({
alias: { alias: {
tslib: 'tslib/tslib.es6.js' tslib: 'tslib/tslib.es6.js'
}, },
bridge: {
meta: true
},
build: { build: {
extend (config) { extend (config) {
config.module.rules.push({ config.module.rules.push({
@@ -33,7 +36,7 @@ export default defineNuxtConfig({
prettify: false prettify: false
} }
}, },
transpile: ['date-fns'] transpile: ['date-fns', '@unhead/vue', 'unhead']
}, },
buildModules: [ buildModules: [
// https://go.nuxtjs.dev/eslint // https://go.nuxtjs.dev/eslint
+1
View File
@@ -67,6 +67,7 @@
"eslint-plugin-nuxt": "^4.0.0", "eslint-plugin-nuxt": "^4.0.0",
"eslint-plugin-vue": "^9.21.1", "eslint-plugin-vue": "^9.21.1",
"husky": "^9.0.10", "husky": "^9.0.10",
"nuxi": "^3.10.0",
"postcss-html": "^1.6.0", "postcss-html": "^1.6.0",
"stylelint": "^14.16.1", "stylelint": "^14.16.1",
"stylelint-config-recommended-vue": "^1.5.0", "stylelint-config-recommended-vue": "^1.5.0",
+6 -13
View File
@@ -2,20 +2,13 @@
<filters /> <filters />
</template> </template>
<script> <script setup lang='ts'>
import Filters from '../components/pages/filters' import { useHead } from '@unhead/vue'
import { useTranslation } from '../plugins/i18n' import Filters from '../components/pages/filters/index.vue'
import { useTranslation } from '~/plugins/i18n'
export default {
name: 'FiltersPage',
components: {
Filters
},
head () {
const { t } = useTranslation() const { t } = useTranslation()
return { useHead({
title: t('filters.title') title: t('filters.title')
} })
}
}
</script> </script>
+4 -11
View File
@@ -2,20 +2,13 @@
<events /> <events />
</template> </template>
<script lang='ts'> <script setup lang='ts'>
import { useHead } from '@unhead/vue'
import Events from '~/components/pages/events/index.vue' import Events from '~/components/pages/events/index.vue'
import { useTranslation } from '~/plugins/i18n' import { useTranslation } from '~/plugins/i18n'
export default {
name: 'IndexPage',
components: {
Events
},
head () {
const { t } = useTranslation() const { t } = useTranslation()
return { useHead({
title: t('events.title') title: t('events.title')
} })
}
}
</script> </script>
+6 -13
View File
@@ -2,20 +2,13 @@
<origins /> <origins />
</template> </template>
<script> <script setup lang='ts'>
import Origins from '../components/pages/origins' import { useHead } from '@unhead/vue'
import { useTranslation } from '../plugins/i18n' import Origins from '../components/pages/origins/index.vue'
import { useTranslation } from '~/plugins/i18n'
export default {
name: 'OriginsPage',
components: {
Origins
},
head () {
const { t } = useTranslation() const { t } = useTranslation()
return { useHead({
title: t('origins.title') title: t('origins.title')
} })
}
}
</script> </script>
+3099 -4048
View File
File diff suppressed because it is too large Load Diff