Files
dancefinder-app/components/pages/origins/index.vue
T

123 lines
3.6 KiB
Vue
Raw Normal View History

2019-03-02 16:26:28 +01:00
<template>
<div :key="isAuthenticated">
<v-container fluid grid-list-md class="app-fade-in">
2019-03-02 16:26:28 +01:00
<v-layout row wrap>
<v-flex xs12>
<v-text-field
2020-01-25 14:59:14 +01:00
v-model="origin"
:label="$t('origins.origin')"
:placeholder="$t('origins.geolocation')"
2019-03-02 16:26:28 +01:00
>
<v-tooltip top slot="append-outer">
<template v-slot:activator="{ on }">
2020-01-25 14:59:14 +01:00
<v-icon v-on="on" v-on:click="fetchAddress()"
>mdi-crosshairs-gps</v-icon
>
</template>
2020-01-25 14:59:14 +01:00
<span v-text="$t('origins.fetchAddress')" />
2019-03-02 16:26:28 +01:00
</v-tooltip>
<v-tooltip top slot="prepend">
<template v-slot:activator="{ on }">
2020-01-25 14:59:14 +01:00
<v-icon
v-on="on"
:disabled="!origin"
v-on:click="saveOrigin(origin)"
>mdi-bookmark-plus-outline</v-icon
>
</template>
2020-01-25 14:59:14 +01:00
<span v-text="$t('origins.save')" />
2019-03-02 16:26:28 +01:00
</v-tooltip>
</v-text-field>
</v-flex>
</v-layout>
<template>
<v-layout row wrap v-for="origin in origins" :key="origin">
2020-01-25 14:59:14 +01:00
<v-flex xs12>
<v-tooltip top slot="prepend">
<template v-slot:activator="{ on }">
<v-icon v-on="on" v-on:click="removeOrigin(origin)"
>mdi-delete-outline
</v-icon>
</template>
<span v-text="$t('origins.remove')" />
</v-tooltip>
<span>{{ origin }}</span>
</v-flex>
</v-layout>
</template>
2019-03-02 16:26:28 +01:00
</v-container>
<v-snackbar
v-model="snackbar.active"
:color="snackbar.color"
:timeout="5000"
>
{{ snackbar.text }}
</v-snackbar>
2019-03-02 16:26:28 +01:00
</div>
</template>
<script>
2020-01-25 14:59:14 +01:00
import { ref } from '@vue/composition-api'
import { useMutations } from '@u3u/vue-hooks'
import {
fetchAddress,
findOrigins,
removeOrigin,
saveOrigin
} from '../../../utils/graph-client'
2020-04-06 10:52:55 +02:00
import {
useLazyQuery,
useMutation,
useQuery,
useResult
} from '../../../plugins/apollo'
import useAuth from '../../../plugins/auth'
2020-01-25 14:59:14 +01:00
import { useTranslation } from '../../../plugins/i18n'
2019-03-02 16:26:28 +01:00
2020-01-25 14:59:14 +01:00
export default {
setup() {
const { setTitle } = useMutations(['setTitle'])
const { t } = useTranslation()
setTitle(t('app.links.origins'))
const { isAuthenticated } = useAuth()
const { data, loading, refetch } = useQuery(findOrigins)
const origins = useResult(data, [])
2020-01-25 14:59:14 +01:00
const snackbar = ref({ active: false, color: 'success', text: '' })
const [doSaveOrigin] = useMutation(saveOrigin)
const [doRemoveOrigin] = useMutation(removeOrigin)
const [doFetchAddress] = useLazyQuery(fetchAddress)
2020-01-25 14:59:14 +01:00
const origin = ref('')
const fetchAddressFn = () => {
if (window.navigator) {
window.navigator.geolocation.getCurrentPosition(pos => {
doFetchAddress({
variables: {
latlng: `${pos.coords.latitude},${pos.coords.longitude}`
}
}).then(res => {
origin.value = res.address
2019-03-02 16:26:28 +01:00
})
2020-01-25 14:59:14 +01:00
})
}
2020-01-25 14:59:14 +01:00
}
const saveOriginFn = o =>
doSaveOrigin({ variables: { origin: o } }).then(() => {
refetch()
origin.value = ''
})
2020-01-25 14:59:14 +01:00
const removeOriginFn = o =>
doRemoveOrigin({ variables: { origin: o } }).then(() => refetch())
2020-01-25 14:59:14 +01:00
return {
isAuthenticated,
loading,
origins,
2020-01-25 14:59:14 +01:00
snackbar,
origin,
saveOrigin: saveOriginFn,
removeOrigin: removeOriginFn,
fetchAddress: fetchAddressFn
2019-03-02 16:26:28 +01:00
}
}
2020-01-25 14:59:14 +01:00
}
2019-03-02 16:26:28 +01:00
</script>