Files
dancefinder-app/components/pages/events/event-page.vue
T

238 lines
7.0 KiB
Vue
Raw Normal View History

2019-01-15 13:21:24 +01:00
<template>
2024-02-02 18:55:45 +01:00
<div :key="isAuthenticated ? 'true' : 'false'">
<v-container :key="range" fluid grid-list-md class="app-fade-in">
<v-row v-if="!isAuthenticated" wrap>
<v-col xs="12">
2020-06-21 19:06:41 +02:00
<p><b v-text="$t('events.login')" /></p>
</v-col>
</v-row>
<v-row wrap>
<v-col xs="12">
<v-text-field
v-model="origin"
2024-02-05 16:48:02 +01:00
variant="underlined"
2020-01-25 14:59:14 +01:00
:label="$t('origins.origin')"
:placeholder="$t('origins.geolocation')"
>
2024-02-05 16:48:02 +01:00
<template #append>
<v-tooltip top>
2024-02-05 16:48:02 +01:00
<template #activator="{ props }">
<v-icon
2024-02-05 16:48:02 +01:00
v-bind="props"
2024-02-02 18:55:45 +01:00
@click="fetchAddressFn()"
>
mdi-crosshairs-gps
</v-icon>
</template>
<span v-text="$t('origins.fetchAddress')" />
</v-tooltip>
</template>
<template #prepend>
<v-tooltip v-if="isAuthenticated" top>
2024-02-05 16:48:02 +01:00
<template #activator="{ props }">
<v-icon
:disabled="!origin"
2024-02-05 16:48:02 +01:00
v-bind="props"
2024-02-02 18:55:45 +01:00
@click="saveOriginFn(origin)"
>
mdi-bookmark-plus-outline
</v-icon>
</template>
<span v-text="$t('origins.save')" />
</v-tooltip>
</template>
</v-text-field>
</v-col>
</v-row>
<v-row wrap>
<v-col>
2020-01-25 14:59:14 +01:00
<v-btn-toggle
2024-02-05 16:48:02 +01:00
v-if="smAndUp"
v-model="state.range"
2020-01-25 14:59:14 +01:00
mandatory
>
2024-02-05 16:48:02 +01:00
<v-btn v-for="r in ranges" :key="r.value" variant="outlined" :value="r.value">
<span v-text="$t(`events.range.${r.value}`)" />
</v-btn>
2019-01-23 15:35:39 +01:00
</v-btn-toggle>
2020-01-25 14:59:14 +01:00
<v-select
v-else
v-model="state.range"
2024-02-05 16:48:02 +01:00
variant="outlined"
:items="ranges"
2024-02-05 16:48:02 +01:00
item-title="name"
item-value="value"
2020-01-25 14:59:14 +01:00
/>
</v-col>
</v-row>
2023-08-01 20:21:31 +02:00
<v-row wrap>
<v-col cols="12" sm="8">
2023-08-01 20:21:31 +02:00
<v-text-field
v-model="state.search"
2024-02-05 16:48:02 +01:00
variant="underlined"
append-outer-icon="mdi-magnify"
2023-08-01 20:21:31 +02:00
:label="$t('events.filter')"
:placeholder="$t('events.filter')"
/>
</v-col>
<v-col cols="12" sm="4">
2024-02-02 18:55:45 +01:00
<v-checkbox v-model="state.includeHidden" :label="$t('events.includeHidden')" />
2023-08-01 20:21:31 +02:00
</v-col>
</v-row>
2024-02-02 18:55:45 +01:00
<event-list
:events="events"
:has-user="isAuthenticated"
:toggle-ignore="toggleIgnore"
2020-01-25 14:59:14 +01:00
/>
2019-01-21 20:58:25 +01:00
</v-container>
<v-snackbar
v-model="snackbar.active"
:color="snackbar.color"
:timeout="5000"
>
{{ snackbar.text }}
</v-snackbar>
2019-01-15 13:21:24 +01:00
</div>
</template>
2024-02-02 18:55:45 +01:00
<script setup lang='ts'>
import { computed, ref, watch } from 'vue'
2024-02-05 16:48:02 +01:00
import { useAuth0 } from '@auth0/auth0-vue'
import { useDisplay } from 'vuetify'
import { useI18n } from '#i18n'
import EventList from './event-list.vue'
import {
2024-02-05 16:48:02 +01:00
type FindEventsQueryVariables,
useFetchAddressLazyQuery,
2023-08-01 20:21:31 +02:00
useFindEventsQuery,
useSaveOriginMutation,
useToggleIgnoreBandMutation,
useToggleIgnoreCityMutation,
useToggleIgnoreDanceHallMutation,
useToggleIgnoreMunicipalityMutation,
2024-02-05 16:48:02 +01:00
useToggleIgnoreStateMutation,
} from '~/graphql/generated/operations'
2023-08-01 20:21:31 +02:00
import { useState } from '~/store'
2020-01-25 14:59:14 +01:00
2024-02-02 18:55:45 +01:00
const state = useState()
2024-02-05 16:48:02 +01:00
const { smAndUp } = useDisplay()
2024-02-02 18:55:45 +01:00
const range = computed(() => state.range)
2024-02-05 16:48:02 +01:00
const { t } = useI18n()
2024-02-02 18:55:45 +01:00
state.setTitle(t('app.links.events'))
2024-02-05 16:48:02 +01:00
const { isAuthenticated } = useAuth0()
2024-02-02 18:55:45 +01:00
const variables = ref<FindEventsQueryVariables>({
range: state.range,
includeOrigins: isAuthenticated.value || false,
search: state.search,
2024-02-05 16:48:02 +01:00
includeHidden: state.includeHidden,
2024-02-02 18:55:45 +01:00
})
const { result, refetch } = useFindEventsQuery(() => variables.value)
watch([state, isAuthenticated], () => {
variables.value.range = state.range
variables.value.search = state.search
variables.value.includeHidden = state.includeHidden
variables.value.includeOrigins = isAuthenticated.value || false
refetch(variables.value)
})
const events = computed(() => result.value?.events ?? [])
const origins = computed(() => result.value?.origins ?? [])
const ranges = [
{ name: '1 vecka', value: 'ONE_WEEK' },
{ name: '2 veckor', value: 'TWO_WEEKS' },
{ name: '1 månad', value: 'ONE_MONTH' },
{ name: '1 kvartal', value: 'ONE_QUARTER' },
2024-02-05 16:48:02 +01:00
{ name: '1 år', value: 'ONE_YEAR' },
2024-02-02 18:55:45 +01:00
]
const snackbar = ref({ active: false, color: 'success', text: '' })
2020-06-21 19:06:41 +02:00
2024-02-02 18:55:45 +01:00
const origin = ref('')
const fetchEvents = () => {
const originsTemp = [...(origins.value || [])]
if (origin.value) {
originsTemp.push(origin.value)
}
variables.value = {
...variables.value,
range: state.range,
origins: originsTemp,
2024-02-05 16:48:02 +01:00
includeOrigins: isAuthenticated.value || false,
2024-02-02 18:55:45 +01:00
}
refetch(variables.value)
}
2020-01-25 14:59:14 +01:00
2024-02-02 18:55:45 +01:00
const { mutate: doToggleIgnoreBand } = useToggleIgnoreBandMutation({})
const { mutate: doToggleIgnoreDanceHall } = useToggleIgnoreDanceHallMutation({})
const { mutate: doToggleIgnoreCity } = useToggleIgnoreCityMutation({})
const { mutate: doToggleIgnoreMunicipality } = useToggleIgnoreMunicipalityMutation({})
const { mutate: doToggleIgnoreState } = useToggleIgnoreStateMutation({})
2020-01-25 14:59:14 +01:00
2024-02-02 18:55:45 +01:00
const toggleIgnoreSuccess = (name: string) => {
return () => {
fetchEvents()
snackbar.value.color = 'success'
snackbar.value.text = `${name} har dolts`
snackbar.value.active = true
}
}
2024-02-02 18:55:45 +01:00
const toggleIgnoreFailed = (name: string) => {
return () => {
snackbar.value.color = 'error'
snackbar.value.text = `${name} kunde inte döljas`
snackbar.value.active = true
}
}
2024-02-02 18:55:45 +01:00
const toggleIgnore = (type: string, name: string) => {
switch (type) {
case 'band':
doToggleIgnoreBand({ name })
.then(toggleIgnoreSuccess(name))
.catch(toggleIgnoreFailed)
break
case 'danceHall':
doToggleIgnoreDanceHall({ name })
.then(toggleIgnoreSuccess(name))
.catch(toggleIgnoreFailed)
break
case 'city':
doToggleIgnoreCity({ name })
.then(toggleIgnoreSuccess(name))
.catch(toggleIgnoreFailed)
break
case 'municipality':
doToggleIgnoreMunicipality({ name })
.then(toggleIgnoreSuccess(name))
.catch(toggleIgnoreFailed)
break
case 'state':
doToggleIgnoreState({ name })
.then(toggleIgnoreSuccess(name))
.catch(toggleIgnoreFailed)
break
default:
}
}
2024-02-02 18:55:45 +01:00
const { mutate: doSaveOrigin } = useSaveOriginMutation({})
const { refetch: doFetchAddress, load: loadFetchAddress } = useFetchAddressLazyQuery({ latlng: '' })
const fetchAddressFn = () => {
if (window.navigator) {
window.navigator.geolocation.getCurrentPosition((pos) => {
loadFetchAddress()
doFetchAddress({
2024-02-05 16:48:02 +01:00
latlng: `${pos.coords.latitude},${pos.coords.longitude}`,
2024-02-02 18:55:45 +01:00
})?.then((result) => {
origin.value = result.data.address
2020-06-21 19:06:41 +02:00
})
2024-02-02 18:55:45 +01:00
})
2020-01-25 14:59:14 +01:00
}
2024-02-02 18:55:45 +01:00
}
const saveOriginFn = (o: string) =>
doSaveOrigin({ origin: o }).then(() => {
origin.value = ''
fetchEvents()
})
2019-01-15 13:21:24 +01:00
</script>