chore: add eslint and fix lint errors

This commit is contained in:
2020-01-25 14:59:14 +01:00
parent e6c87e2f46
commit ef2015f012
36 changed files with 1645 additions and 917 deletions
+37
View File
@@ -0,0 +1,37 @@
module.exports = {
env: {
browser: true,
es6: true,
},
extends: [
'airbnb-base',
"plugin:vue/recommended",
"eslint:recommended",
"prettier/vue",
"plugin:prettier/recommended",
],
globals: {
Atomics: 'readonly',
SharedArrayBuffer: 'readonly',
},
parserOptions: {
ecmaVersion: 2018,
sourceType: 'module',
},
plugins: [
'vue',
],
rules: {
'import/extensions': 0,
'import/no-unresolved': 0,
'no-param-reassign': 0,
'prettier/prettier': [
'error',
{
trailingComma: 'none',
singleQuote: true,
semi: false
}
],
},
};
+6
View File
@@ -0,0 +1,6 @@
{
"trailingComma": "none",
"tabWidth": 2,
"semi": false,
"singleQuote": true
}
+1 -1
View File
@@ -1,4 +1,4 @@
FROM cypress/base:10 as builder FROM cypress/base:12.14.0 as builder
WORKDIR /build WORKDIR /build
@@ -16,10 +16,9 @@ export default {
default: f => f default: f => f
} }
} }
}; }
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
.image { .image {
height: 100%; height: 100%;
@@ -32,7 +31,7 @@ export default {
transition: opacity 300ms ease; transition: opacity 300ms ease;
will-change: opacity; will-change: opacity;
&[lazy="loaded"] { &[lazy='loaded'] {
opacity: 1; opacity: 1;
} }
} }
+7 -8
View File
@@ -1,12 +1,12 @@
<template> <template>
<div :class="{ 'is-shown': show, 'is-contained': contained }" class="cover"> <div :class="{ 'is-shown': show, 'is-contained': contained }" class="cover">
<ul class="loader"> <ul class="loader">
<li/> <li />
<li/> <li />
<li/> <li />
<li/> <li />
<li/> <li />
<li/> <li />
</ul> </ul>
</div> </div>
</template> </template>
@@ -25,7 +25,7 @@ export default {
default: false default: false
} }
} }
}; }
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
@@ -94,4 +94,3 @@ export default {
} }
} }
</style> </style>
+3 -5
View File
@@ -6,7 +6,7 @@
</div> </div>
<h3>{{ message }}</h3> <h3>{{ message }}</h3>
<p>{{ description }}</p> <p>{{ description }}</p>
<slot name="extras"/> <slot name="extras" />
</div> </div>
</div> </div>
</template> </template>
@@ -21,13 +21,12 @@ export default {
description: { description: {
type: String, type: String,
required: false, required: false,
default: "" default: ''
} }
} }
}; }
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
.message-container { .message-container {
margin: 10vh auto; margin: 10vh auto;
@@ -52,4 +51,3 @@ export default {
} }
} }
</style> </style>
+93 -35
View File
@@ -1,29 +1,87 @@
<template> <template>
<v-card xs12> <v-card xs12>
<v-card-title primary-title> <v-card-title primary-title>
<h3 class="headline mb-0"><v-icon class="ml-1 mr-1" v-if="hasUser" v-on:click="toggleIgnore('band', event.band.name)" medium title="Dölj">mdi-eye-off</v-icon>{{event.band.name}}</h3> <h3 class="headline mb-0">
<v-icon
class="ml-1 mr-1"
v-if="hasUser"
v-on:click="toggleIgnore('band', event.band.name)"
medium
title="Dölj"
>mdi-eye-off</v-icon
>{{ event.band.name }}
</h3>
</v-card-title> </v-card-title>
<v-container> <v-container>
<v-layout row wrap> <v-layout row wrap>
<v-flex xs12 sm6><strong class="mr-1" v-text="$t('events.date')" />{{event.date}} ({{ weekday }} {{ daysUntil }})</v-flex> <v-flex xs12 sm6
<v-flex xs12 sm6 v-if="event.time"><strong class="mr-1" v-text="$t('events.time')" />{{event.time}}</v-flex> ><strong class="mr-1" v-text="$t('events.date')" />{{
event.date
}}
({{ weekday }} {{ daysUntil }})</v-flex
>
<v-flex xs12 sm6 v-if="event.time"
><strong class="mr-1" v-text="$t('events.time')" />{{
event.time
}}</v-flex
>
</v-layout> </v-layout>
<v-layout row wrap> <v-layout row wrap>
<v-flex xs12 sm6 md3><strong class="mr-1" v-text="$t('events.hall')" /><v-icon class="ml-1 mr-1" v-if="hasUser" v-on:click="toggleIgnore('danceHall', event.danceHall.name)" small :title="$t('events.hide')">mdi-eye-off</v-icon>{{event.danceHall.name}}</v-flex> <v-flex xs12 sm6 md3
<v-flex xs12 sm6 md3><strong class="mr-1" v-text="$t('events.city')" /><v-icon class="ml-1 mr-1" v-if="hasUser" v-on:click="toggleIgnore('city', event.danceHall.city)" small :title="$t('events.hide')">mdi-eye-off</v-icon>{{event.danceHall.city}}</v-flex> ><strong class="mr-1" v-text="$t('events.hall')" /><v-icon
<v-flex xs12 sm6 md3><strong class="mr-1" v-text="$t('events.municipality')" /><v-icon class="ml-1 mr-1" v-if="hasUser" v-on:click="toggleIgnore('municipality', event.danceHall.municipality)" small :title="$t('events.hide')">mdi-eye-off</v-icon>{{event.danceHall.municipality}}</v-flex> class="ml-1 mr-1"
<v-flex xs12 sm6 md3><strong class="mr-1" v-text="$t('events.state')" /><v-icon class="ml-1 mr-1" v-if="hasUser" v-on:click="toggleIgnore('state', event.danceHall.state)" small :title="$t('events.hide')">mdi-eye-off</v-icon>{{event.danceHall.state}}</v-flex> v-if="hasUser"
v-on:click="toggleIgnore('danceHall', event.danceHall.name)"
small
:title="$t('events.hide')"
>mdi-eye-off</v-icon
>{{ event.danceHall.name }}</v-flex
>
<v-flex xs12 sm6 md3
><strong class="mr-1" v-text="$t('events.city')" /><v-icon
class="ml-1 mr-1"
v-if="hasUser"
v-on:click="toggleIgnore('city', event.danceHall.city)"
small
:title="$t('events.hide')"
>mdi-eye-off</v-icon
>{{ event.danceHall.city }}</v-flex
>
<v-flex xs12 sm6 md3
><strong class="mr-1" v-text="$t('events.municipality')" /><v-icon
class="ml-1 mr-1"
v-if="hasUser"
v-on:click="
toggleIgnore('municipality', event.danceHall.municipality)
"
small
:title="$t('events.hide')"
>mdi-eye-off</v-icon
>{{ event.danceHall.municipality }}</v-flex
>
<v-flex xs12 sm6 md3
><strong class="mr-1" v-text="$t('events.state')" /><v-icon
class="ml-1 mr-1"
v-if="hasUser"
v-on:click="toggleIgnore('state', event.danceHall.state)"
small
:title="$t('events.hide')"
>mdi-eye-off</v-icon
>{{ event.danceHall.state }}</v-flex
>
</v-layout> </v-layout>
<v-layout row wrap v-for="distance in event.distances" :key="event.origin"> <v-layout row wrap v-for="distance in event.distances" :key="distance">
<v-flex xs12 sm6> <v-flex xs12 sm6>
<v-icon>mdi-home</v-icon> <v-icon>mdi-home</v-icon>
<span><strong>{{distance.origin}}</strong></span> <span
><strong>{{ distance.origin }}</strong></span
>
</v-flex> </v-flex>
<v-flex xs12 sm6> <v-flex xs12 sm6>
<v-icon>mdi-car</v-icon> <v-icon>mdi-car</v-icon>
<span>{{distance.distance / 1000 | numeral('0,0.00')}} km</span> <span>{{ (distance.distance / 1000) | numeral('0,0.00') }} km</span>
<v-icon>mdi-clock-outline</v-icon> <v-icon>mdi-clock-outline</v-icon>
<span>{{distance.duration}}</span> <span>{{ distance.duration }}</span>
</v-flex> </v-flex>
</v-layout> </v-layout>
</v-container> </v-container>
@@ -31,31 +89,31 @@
</template> </template>
<script> <script>
import dayjs from 'dayjs' import dayjs from 'dayjs'
export default { export default {
props: { props: {
event: { event: {
type: Object, type: Object,
required: true required: true
},
hasUser: {
type: Boolean,
required: true
},
toggleIgnore: {
type: Function,
required: true
}
}, },
setup(props) { hasUser: {
const time = (props.event.time || '').split('-')[0].replace('.', ':') type: Boolean,
const weekday = dayjs(props.event.date).format('dddd') required: true
const daysUntil = dayjs(`${props.event.date} ${time}`).fromNow()
return {
weekday,
daysUntil
}
}, },
}; toggleIgnore: {
type: Function,
required: true
}
},
setup(props) {
const time = (props.event.time || '').split('-')[0].replace('.', ':')
const weekday = dayjs(props.event.date).format('dddd')
const daysUntil = dayjs(`${props.event.date} ${time}`).fromNow()
return {
weekday,
daysUntil
}
}
}
</script> </script>
+11 -7
View File
@@ -1,19 +1,23 @@
<template> <template>
<div> <div v-if="events && events.events">
<v-layout row wrap v-for="event in events.events" :key="event.id" v-if="events && events.events"> <v-layout row wrap v-for="event in events.events" :key="event.id">
<v-flex xs12> <v-flex xs12>
<Event :event="event" :has-user="hasUser" :toggleIgnore="toggleIgnore"/> <Event
:event="event"
:has-user="hasUser"
:toggleIgnore="toggleIgnore"
/>
</v-flex> </v-flex>
</v-layout> </v-layout>
</div> </div>
</template> </template>
<script> <script>
import Event from '../Event'; import Event from '../Event'
export default { export default {
components: { components: {
Event, Event
}, },
props: { props: {
hasUser: { hasUser: {
@@ -27,7 +31,7 @@ export default {
events: { events: {
type: Object, type: Object,
required: true required: true
}, }
}, }
} }
</script> </script>
+223 -183
View File
@@ -3,40 +3,68 @@
<v-container fluid grid-list-md class="app-fade-in" :key="range"> <v-container fluid grid-list-md class="app-fade-in" :key="range">
<v-layout row wrap v-if="!isAuthenticated"> <v-layout row wrap v-if="!isAuthenticated">
<v-flex xs12> <v-flex xs12>
<p><b v-text="$t('events.login')"/></p> <p><b v-text="$t('events.login')" /></p>
</v-flex> </v-flex>
</v-layout> </v-layout>
<v-layout row wrap> <v-layout row wrap>
<v-flex xs12> <v-flex xs12>
<v-text-field <v-text-field
v-model="origin" v-model="origin"
:label="$t('origins.origin')" :label="$t('origins.origin')"
:placeholder="$t('origins.geolocation')" :placeholder="$t('origins.geolocation')"
> >
<v-tooltip top slot="append-outer"> <v-tooltip top slot="append-outer">
<template v-slot:activator="{ on }"> <template v-slot:activator="{ on }">
<v-icon v-on="on" v-on:click="fetchAddress()">mdi-crosshairs-gps</v-icon> <v-icon v-on="on" v-on:click="fetchAddress()"
>mdi-crosshairs-gps</v-icon
>
</template> </template>
<span v-text="$t('origins.fetchAddress')"/> <span v-text="$t('origins.fetchAddress')" />
</v-tooltip> </v-tooltip>
<v-tooltip top slot="prepend" v-if="isAuthenticated"> <v-tooltip top slot="prepend" v-if="isAuthenticated">
<template v-slot:activator="{ on }"> <template v-slot:activator="{ on }">
<v-icon v-on="on" :disabled="!origin" v-on:click="saveOrigin(origin)">mdi-bookmark-plus-outline</v-icon> <v-icon
v-on="on"
:disabled="!origin"
v-on:click="saveOrigin(origin)"
>mdi-bookmark-plus-outline</v-icon
>
</template> </template>
<span v-text="$t('origins.save')"/> <span v-text="$t('origins.save')" />
</v-tooltip> </v-tooltip>
</v-text-field> </v-text-field>
</v-flex> </v-flex>
</v-layout> </v-layout>
<v-layout row wrap> <v-layout row wrap>
<v-flex> <v-flex>
<v-btn-toggle v-if="$vuetify.breakpoint.smAndUp" v-model="range" mandatory> <v-btn-toggle
<v-btn text v-for="r in ranges" :key="r.value" :value="r.value" v-text="$t(`events.range.${r.value}`)"/> v-if="$vuetify.breakpoint.smAndUp"
v-model="range"
mandatory
>
<v-btn
text
v-for="r in ranges"
:key="r.value"
:value="r.value"
v-text="$t(`events.range.${r.value}`)"
/>
</v-btn-toggle> </v-btn-toggle>
<v-select outline v-if="$vuetify.breakpoint.xsOnly" v-model="range" :items="ranges" item-text="name" item-value="value"/> <v-select
outline
v-if="$vuetify.breakpoint.xsOnly"
v-model="range"
:items="ranges"
item-text="name"
item-value="value"
/>
</v-flex> </v-flex>
</v-layout> </v-layout>
<list :events="data" :has-user="isAuthenticated" :toggleIgnore="toggleIgnore" /> <list
:events="data"
:has-user="isAuthenticated"
:toggleIgnore="toggleIgnore"
/>
</v-container> </v-container>
<v-snackbar <v-snackbar
v-model="snackbar.active" v-model="snackbar.active"
@@ -49,203 +77,215 @@
</template> </template>
<script> <script>
import { useAuth } from '../../../plugins/auth' import { useRouter, useMutations } from '@u3u/vue-hooks'
import { computed, ref, watch } from '@vue/composition-api'
import useAuth from '../../../plugins/auth'
import List from './List' import List from './List'
import { useRouter, useMutations } from '@u3u/vue-hooks' import { useLazyQuery, useMutation } from '../../../plugins/apollo'
import { computed, ref, watch } from '@vue/composition-api' import {
import { useLazyQuery, useMutation } from '../../../plugins/apollo' fetchAddress,
import { findEvents,
fetchAddress, saveOrigin,
findEvents, toggleIgnoreBand,
saveOrigin, toggleIgnoreCity,
toggleIgnoreBand, toggleIgnoreDanceHall,
toggleIgnoreCity, toggleIgnoreMunicipality,
toggleIgnoreDanceHall, toggleIgnoreState
toggleIgnoreMunicipality, } from '../../../utils/graph-client'
toggleIgnoreState import { useTranslation } from '../../../plugins/i18n'
} from '../../../utils/graph-client'
import { useTranslation } from '../../../plugins/i18n'
export default { export default {
components: { components: {
List List
}, },
setup() { setup() {
const { setTitle } = useMutations(['setTitle']) const { setTitle } = useMutations(['setTitle'])
const { t } = useTranslation(); const { t } = useTranslation()
setTitle(t('app.links.events')) setTitle(t('app.links.events'))
const { loading: authLoading, isAuthenticated } = useAuth() const { loading: authLoading, isAuthenticated } = useAuth()
const { route, router } = useRouter(); const { route, router } = useRouter()
const range = computed({get: () => route.value.query.range || 'ONE_WEEK', set: value => router.push(`/?range=${value}`)}) const range = computed({
const [query, { loading, data, error, refetch }] = useLazyQuery(findEvents) get: () => route.value.query.range || 'ONE_WEEK',
watch(() => range.value, (r, o) => { set: value => router.push(`/?range=${value}`)
})
const [query, { data }] = useLazyQuery(findEvents)
watch(
() => range.value,
r => {
query({ query({
variables: { variables: {
range: r, range: r,
includeOrigins: isAuthenticated.value includeOrigins: isAuthenticated.value
} }
}) })
}, { lazy: false}) },
const submitting = ref(true) { lazy: false }
const ranges = [ )
{ name: '1 vecka', value: 'ONE_WEEK' }, const submitting = ref(true)
{ name: '2 veckor', value: 'TWO_WEEKS' }, const ranges = [
{ name: '1 månad', value: 'ONE_MONTH' }, { name: '1 vecka', value: 'ONE_WEEK' },
{ name: '1 kvartal', value: 'ONE_QUARTER' }, { name: '2 veckor', value: 'TWO_WEEKS' },
{ name: '1 år', value: 'ONE_YEAR' } { name: '1 månad', value: 'ONE_MONTH' },
] { name: '1 kvartal', value: 'ONE_QUARTER' },
const snackbar = ref({ active: false, color: 'success', text: '' }) { name: '1 år', value: 'ONE_YEAR' }
]
const snackbar = ref({ active: false, color: 'success', text: '' })
const origin = ref('') const origin = ref('')
const fetchEvents = () => { const fetchEvents = () => {
const origins = [...(data.value.origins || [])] const origins = [...(data.value.origins || [])]
if (origin.value) { if (origin.value) {
origins.push(origin.value) origins.push(origin.value)
}
query({
variables: {
range: range.value,
origins,
includeOrigins: isAuthenticated.value || false
} }
query({ })
variables: { }
range: range.value,
origins, const [doToggleIgnoreBand] = useMutation(toggleIgnoreBand)
includeOrigins: (isAuthenticated.value || false) const [doToggleIgnoreDanceHall] = useMutation(toggleIgnoreDanceHall)
} const [doToggleIgnoreCity] = useMutation(toggleIgnoreCity)
const [doToggleIgnoreMunicipality] = useMutation(toggleIgnoreMunicipality)
const [doToggleIgnoreState] = useMutation(toggleIgnoreState)
const toggleIgnoreSuccess = name => {
return () => {
fetchEvents()
snackbar.value.color = 'success'
snackbar.value.text = `${name} har dolts`
snackbar.value.active = true
}
}
const toggleIgnoreFailed = name => {
return () => {
snackbar.value.color = 'error'
snackbar.value.text = `${name} kunde inte döljas`
snackbar.value.active = true
}
}
const toggleIgnore = (type, name) => {
switch (type) {
case 'band':
doToggleIgnoreBand({ variables: { name } })
.then(toggleIgnoreSuccess(name))
.catch(toggleIgnoreFailed)
break
case 'danceHall':
doToggleIgnoreDanceHall({ variables: { name } })
.then(toggleIgnoreSuccess(name))
.catch(toggleIgnoreFailed)
break
case 'city':
doToggleIgnoreCity({ variables: { name } })
.then(toggleIgnoreSuccess(name))
.catch(toggleIgnoreFailed)
break
case 'municipality':
doToggleIgnoreMunicipality({ variables: { name } })
.then(toggleIgnoreSuccess(name))
.catch(toggleIgnoreFailed)
break
case 'state':
doToggleIgnoreState({ variables: { name } })
.then(toggleIgnoreSuccess(name))
.catch(toggleIgnoreFailed)
break
default:
}
}
const [doSaveOrigin] = useMutation(saveOrigin)
const [doFetchAddress, { data: address }] = useLazyQuery(fetchAddress)
const fetchAddressFn = () => {
if (window.navigator) {
window.navigator.geolocation.getCurrentPosition(pos => {
doFetchAddress({
variables: {
latlng: `${pos.coords.latitude},${pos.coords.longitude}`
}
}).then(() => {
origin.value = address.value.address
})
}) })
} }
}
const [doToggleIgnoreBand, {loading: ignoringBand, error: errorIgnoreBand}] = useMutation(toggleIgnoreBand) const saveOriginFn = o =>
const [doToggleIgnoreDanceHall, {loading: ignoringDanceHall, error: errorIgnoreDanceHall}] = useMutation(toggleIgnoreDanceHall) doSaveOrigin({ variables: { origin: o } }).then(() => {
const [doToggleIgnoreCity, {loading: ignoringCity, error: errorIgnoreCity}] = useMutation(toggleIgnoreCity)
const [doToggleIgnoreMunicipality, {loading: ignoringMunicipality, error: errorIgnoreMunicipality}] = useMutation(toggleIgnoreMunicipality)
const [doToggleIgnoreState, {loading: ignoringState, error: errorIgnoreState}] = useMutation(toggleIgnoreState)
const toggleIgnoreSuccess = (name) => {
return () => {
fetchEvents();
snackbar.value.color = 'success';
snackbar.value.text = `${name} har dolts`;
snackbar.value.active = true;
}
}
const toggleIgnoreFailed = (name) => {
return () => {
snackbar.value.color = 'error';
snackbar.value.text = `${name} kunde inte döljas`;
snackbar.value.active = true;
}
}
const toggleIgnore = (type, name) => {
switch (type) {
case 'band':
doToggleIgnoreBand({ variables: { name: name } })
.then(toggleIgnoreSuccess(name))
.catch(toggleIgnoreFailed);
break;
case 'danceHall':
doToggleIgnoreDanceHall({ variables: { name: name } })
.then(toggleIgnoreSuccess(name))
.catch(toggleIgnoreFailed);
break;
case 'city':
doToggleIgnoreCity({ variables: { name: name } })
.then(toggleIgnoreSuccess(name))
.catch(toggleIgnoreFailed);
break;
case 'municipality':
doToggleIgnoreMunicipality({ variables: { name: name } })
.then(toggleIgnoreSuccess(name))
.catch(toggleIgnoreFailed);
break;
case 'state':
doToggleIgnoreState({ variables: { name: name } })
.then(toggleIgnoreSuccess(name))
.catch(toggleIgnoreFailed);
break;
}
}
const [doSaveOrigin, {loading: savingOrigin, error: errorSaveOrigin}] = useMutation(saveOrigin)
const [doFetchAddress, {data: address, loading: fetchingAddress, error: errorFetchingAddress}] = useLazyQuery(fetchAddress)
const fetchAddressFn = () => {
if (window.navigator) {
window.navigator.geolocation.getCurrentPosition(pos => {
doFetchAddress({variables: {latlng: pos.coords.latitude + "," + pos.coords.longitude}})
.then(() => {
origin.value = address.value.address;
})
})
}
}
const saveOriginFn = o => doSaveOrigin({variables: { origin: o }}).then(() => {
origin.value = '' origin.value = ''
fetchEvents() fetchEvents()
}) })
return { return {
authLoading, authLoading,
isAuthenticated, isAuthenticated,
range, range,
data, data,
query: fetchEvents, query: fetchEvents,
submitting, submitting,
ranges, ranges,
snackbar, snackbar,
toggleIgnore, toggleIgnore,
origin, origin,
fetchAddress: fetchAddressFn, fetchAddress: fetchAddressFn,
saveOrigin: saveOriginFn saveOrigin: saveOriginFn
} }
}, }
}; }
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
.left {
padding: 1.5rem 1rem;
> * {
margin-bottom: 1.5rem;
}
hr {
border: 0;
border-top: 1px solid #eaeaea;
}
}
.left,
.right {
height: 100vh;
overflow: scroll;
overflow-x: hidden;
position: relative;
}
@media screen and(max-width: 1200px) {
.left { .left {
padding: 1.5rem 1rem; width: 40vw;
> * {
margin-bottom: 1.5rem;
}
hr {
border: 0;
border-top: 1px solid #eaeaea;
}
} }
.left,
.right { .right {
height: 100vh; width: 60vw;
overflow: scroll;
overflow-x: hidden;
position: relative;
} }
}
@media screen and(max-width: 1200px) { @media screen and(max-width: 1024px) {
.left { .left {
width: 40vw; width: 50vw;
}
.right {
width: 60vw;
}
} }
.right {
width: 50vw;
}
}
@media screen and(max-width: 1024px) { @media screen and(min-width: 1200px) {
.left { .left {
width: 50vw; width: 35vw;
}
.right {
width: 50vw;
}
} }
.right {
@media screen and(min-width: 1200px) { width: 65vw;
.left {
width: 35vw;
}
.right {
width: 65vw;
}
} }
}
</style> </style>
+22 -22
View File
@@ -2,7 +2,7 @@
<v-flex xs12 sm6 md4 lg3> <v-flex xs12 sm6 md4 lg3>
<v-card> <v-card>
<v-card-title> <v-card-title>
<span v-text="$tc(title, model.length)"/> <span v-text="$tc(title, model.length)" />
</v-card-title> </v-card-title>
<v-list> <v-list>
<v-list-item v-for="item in model" :key="item"> <v-list-item v-for="item in model" :key="item">
@@ -11,10 +11,10 @@
<template v-slot:activator="{ on }"> <template v-slot:activator="{ on }">
<v-icon v-on="on">mdi-delete-outline</v-icon> <v-icon v-on="on">mdi-delete-outline</v-icon>
</template> </template>
<span v-text="$t('filters.remove')"/> <span v-text="$t('filters.remove')" />
</v-tooltip> </v-tooltip>
</v-list-item-action> </v-list-item-action>
<v-list-item-title v-html="item"/> <v-list-item-title v-html="item" />
</v-list-item> </v-list-item>
</v-list> </v-list>
</v-card> </v-card>
@@ -22,24 +22,24 @@
</template> </template>
<script> <script>
export default { export default {
props: { props: {
model: { model: {
type: Array, type: Array,
required: true required: true
}, },
title: { title: {
type: String, type: String,
required: true required: true
}, },
type: { type: {
type: String, type: String,
required: true required: true
}, },
toggleIgnore: { toggleIgnore: {
type: Function, type: Function,
required: true required: true
}
} }
}; }
}
</script> </script>
+120 -92
View File
@@ -4,18 +4,45 @@
<v-layout row wrap> <v-layout row wrap>
<v-flex xs12> <v-flex xs12>
<v-card> <v-card>
<v-container <v-container fluid grid-list-md>
fluid
grid-list-md
>
<v-layout row wrap v-if="!loading && data"> <v-layout row wrap v-if="!loading && data">
<list :model="data.bands" title="filters.band" type="band" :toggleIgnore="toggleIgnore" v-if="data.bands"/> <list
:model="data.bands"
title="filters.band"
type="band"
:toggleIgnore="toggleIgnore"
v-if="data.bands"
/>
<v-flex xs12 sm6 md4 lg3> <v-flex xs12 sm6 md4 lg3>
<v-layout column> <v-layout column>
<list :model="data.states" title="filters.state" type="state" :toggleIgnore="toggleIgnore" v-if="data.states"/> <list
<list :model="data.municipalities" title="filters.municipality" type="municipality" :toggleIgnore="toggleIgnore" v-if="data.municipalities"/> :model="data.states"
<list :model="data.cities" title="filters.city" type="city" :toggleIgnore="toggleIgnore" v-if="data.cities"/> title="filters.state"
<list :model="data.danceHalls" title="filters.hall" type="danceHall" :toggleIgnore="toggleIgnore" v-if="data.danceHalls"/> type="state"
:toggleIgnore="toggleIgnore"
v-if="data.states"
/>
<list
:model="data.municipalities"
title="filters.municipality"
type="municipality"
:toggleIgnore="toggleIgnore"
v-if="data.municipalities"
/>
<list
:model="data.cities"
title="filters.city"
type="city"
:toggleIgnore="toggleIgnore"
v-if="data.cities"
/>
<list
:model="data.danceHalls"
title="filters.hall"
type="danceHall"
:toggleIgnore="toggleIgnore"
v-if="data.danceHalls"
/>
</v-layout> </v-layout>
</v-flex> </v-flex>
</v-layout> </v-layout>
@@ -35,93 +62,94 @@
</template> </template>
<script> <script>
import { import { ref } from '@vue/composition-api'
fetchFilters, import { useMutations } from '@u3u/vue-hooks'
toggleIgnoreBand, import {
toggleIgnoreCity, fetchFilters,
toggleIgnoreDanceHall, toggleIgnoreBand,
toggleIgnoreMunicipality, toggleIgnoreCity,
toggleIgnoreState, toggleIgnoreDanceHall,
} from "~/utils/graph-client"; toggleIgnoreMunicipality,
toggleIgnoreState
} from '~/utils/graph-client'
import List from "./List"; import List from './List'
import { useMutation, useQuery } from '../../../plugins/apollo' import { useMutation, useQuery } from '../../../plugins/apollo'
import { ref } from '@vue/composition-api' import useAuth from '../../../plugins/auth'
import { useAuth } from '../../../plugins/auth' import { useTranslation } from '../../../plugins/i18n'
import { useMutations } from '@u3u/vue-hooks'
import { useTranslation } from '../../../plugins/i18n'
export default { export default {
components: { components: {
List List
}, },
setup() { setup() {
const { setTitle } = useMutations(['setTitle']) const { setTitle } = useMutations(['setTitle'])
const { t } = useTranslation(); const { t } = useTranslation()
setTitle(t('app.links.filters')) setTitle(t('app.links.filters'))
const { loading: authLoading, isAuthenticated } = useAuth() const { isAuthenticated } = useAuth()
const {data, loading, error, refetch} = useQuery(fetchFilters) const { data, loading, refetch } = useQuery(fetchFilters)
const snackbar = ref({ active: false, color: 'success', text: '' }) const snackbar = ref({ active: false, color: 'success', text: '' })
const [doToggleIgnoreBand, {loading: ignoringBand, error: errorIgnoreBand}] = useMutation(toggleIgnoreBand) const [doToggleIgnoreBand] = useMutation(toggleIgnoreBand)
const [doToggleIgnoreDanceHall, {loading: ignoringDanceHall, error: errorIgnoreDanceHall}] = useMutation(toggleIgnoreDanceHall) const [doToggleIgnoreDanceHall] = useMutation(toggleIgnoreDanceHall)
const [doToggleIgnoreCity, {loading: ignoringCity, error: errorIgnoreCity}] = useMutation(toggleIgnoreCity) const [doToggleIgnoreCity] = useMutation(toggleIgnoreCity)
const [doToggleIgnoreMunicipality, {loading: ignoringMunicipality, error: errorIgnoreMunicipality}] = useMutation(toggleIgnoreMunicipality) const [doToggleIgnoreMunicipality] = useMutation(toggleIgnoreMunicipality)
const [doToggleIgnoreState, {loading: ignoringState, error: errorIgnoreState}] = useMutation(toggleIgnoreState) const [doToggleIgnoreState] = useMutation(toggleIgnoreState)
const toggleIgnoreSuccess = (name) => { const toggleIgnoreSuccess = name => {
return () => { return () => {
refetch.value(); refetch.value()
snackbar.value.color = 'success'; snackbar.value.color = 'success'
snackbar.value.text = t('filters.success', { name }); snackbar.value.text = t('filters.success', { name })
snackbar.value.active = true; snackbar.value.active = true
}
}
const toggleIgnoreFailed = (name) => {
return () => {
snackbar.value.color = 'error';
snackbar.value.text = t('filters.failure', { name });
snackbar.value.active = true;
}
}
const toggleIgnore = (type, name) => {
switch (type) {
case 'band':
doToggleIgnoreBand({ variables: { name: name } })
.then(toggleIgnoreSuccess(name))
.catch(toggleIgnoreFailed);
break;
case 'danceHall':
doToggleIgnoreDanceHall({ variables: { name: name } })
.then(toggleIgnoreSuccess(name))
.catch(toggleIgnoreFailed);
break;
case 'city':
doToggleIgnoreCity({ variables: { name: name } })
.then(toggleIgnoreSuccess(name))
.catch(toggleIgnoreFailed);
break;
case 'municipality':
doToggleIgnoreMunicipality({ variables: { name: name } })
.then(toggleIgnoreSuccess(name))
.catch(toggleIgnoreFailed);
break;
case 'state':
doToggleIgnoreState({ variables: { name: name } })
.then(toggleIgnoreSuccess(name))
.catch(toggleIgnoreFailed);
break;
}
}
return {
isAuthenticated,
loading,
data,
snackbar,
toggleIgnore
} }
} }
const toggleIgnoreFailed = name => {
return () => {
snackbar.value.color = 'error'
snackbar.value.text = t('filters.failure', { name })
snackbar.value.active = true
}
}
const toggleIgnore = (type, name) => {
switch (type) {
case 'band':
doToggleIgnoreBand({ variables: { name } })
.then(toggleIgnoreSuccess(name))
.catch(toggleIgnoreFailed)
break
case 'danceHall':
doToggleIgnoreDanceHall({ variables: { name } })
.then(toggleIgnoreSuccess(name))
.catch(toggleIgnoreFailed)
break
case 'city':
doToggleIgnoreCity({ variables: { name } })
.then(toggleIgnoreSuccess(name))
.catch(toggleIgnoreFailed)
break
case 'municipality':
doToggleIgnoreMunicipality({ variables: { name } })
.then(toggleIgnoreSuccess(name))
.catch(toggleIgnoreFailed)
break
case 'state':
doToggleIgnoreState({ variables: { name } })
.then(toggleIgnoreSuccess(name))
.catch(toggleIgnoreFailed)
break
default:
}
}
return {
isAuthenticated,
loading,
data,
snackbar,
toggleIgnore
}
} }
}
</script> </script>
+77 -61
View File
@@ -4,36 +4,47 @@
<v-layout row wrap> <v-layout row wrap>
<v-flex xs12> <v-flex xs12>
<v-text-field <v-text-field
v-model="origin" v-model="origin"
:label="$t('origins.origin')" :label="$t('origins.origin')"
:placeholder="$t('origins.geolocation')" :placeholder="$t('origins.geolocation')"
> >
<v-tooltip top slot="append-outer"> <v-tooltip top slot="append-outer">
<template v-slot:activator="{ on }"> <template v-slot:activator="{ on }">
<v-icon v-on="on" v-on:click="fetchAddress()">mdi-crosshairs-gps</v-icon> <v-icon v-on="on" v-on:click="fetchAddress()"
>mdi-crosshairs-gps</v-icon
>
</template> </template>
<span v-text="$t('origins.fetchAddress')"/> <span v-text="$t('origins.fetchAddress')" />
</v-tooltip> </v-tooltip>
<v-tooltip top slot="prepend"> <v-tooltip top slot="prepend">
<template v-slot:activator="{ on }"> <template v-slot:activator="{ on }">
<v-icon v-on="on" :disabled="!origin" v-on:click="saveOrigin(origin)">mdi-bookmark-plus-outline</v-icon> <v-icon
v-on="on"
:disabled="!origin"
v-on:click="saveOrigin(origin)"
>mdi-bookmark-plus-outline</v-icon
>
</template> </template>
<span v-text="$t('origins.save')"/> <span v-text="$t('origins.save')" />
</v-tooltip> </v-tooltip>
</v-text-field> </v-text-field>
</v-flex> </v-flex>
</v-layout> </v-layout>
<v-layout row wrap v-for="origin in data.origins" :key="origin" v-if="data && data.origins"> <template v-if="data && data.origins">
<v-flex xs12> <v-layout row wrap v-for="origin in data.origins" :key="origin">
<v-tooltip top slot="prepend"> <v-flex xs12>
<template v-slot:activator="{ on }"> <v-tooltip top slot="prepend">
<v-icon v-on="on" v-on:click="removeOrigin(origin)">mdi-delete-outline</v-icon> <template v-slot:activator="{ on }">
</template> <v-icon v-on="on" v-on:click="removeOrigin(origin)"
<span v-text="$t('origins.remove')"/> >mdi-delete-outline
</v-tooltip> </v-icon>
<span>{{origin}}</span> </template>
</v-flex> <span v-text="$t('origins.remove')" />
</v-layout> </v-tooltip>
<span>{{ origin }}</span>
</v-flex>
</v-layout>
</template>
</v-container> </v-container>
<v-snackbar <v-snackbar
v-model="snackbar.active" v-model="snackbar.active"
@@ -46,55 +57,60 @@
</template> </template>
<script> <script>
import { import { ref } from '@vue/composition-api'
findOrigins, import { useMutations } from '@u3u/vue-hooks'
saveOrigin, import {
removeOrigin, fetchAddress,
fetchAddress, findOrigins,
} from "../../../utils/graph-client"; removeOrigin,
import { useLazyQuery, useMutation, useQuery } from '../../../plugins/apollo' saveOrigin
import { ref } from '@vue/composition-api' } from '../../../utils/graph-client'
import { useAuth } from '../../../plugins/auth' import { useLazyQuery, useMutation, useQuery } from '../../../plugins/apollo'
import { useMutations } from '@u3u/vue-hooks' import useAuth from '../../../plugins/auth'
import { useTranslation } from '../../../plugins/i18n' import { useTranslation } from '../../../plugins/i18n'
export default { export default {
setup() { setup() {
const { setTitle } = useMutations(['setTitle']) const { setTitle } = useMutations(['setTitle'])
const { t } = useTranslation(); const { t } = useTranslation()
setTitle(t('app.links.origins')) setTitle(t('app.links.origins'))
const { loading: authLoading, isAuthenticated } = useAuth() const { isAuthenticated } = useAuth()
const {data, loading, error, refetch} = useQuery(findOrigins) const { data, loading, refetch } = useQuery(findOrigins)
const snackbar = ref({ active: false, color: 'success', text: '' }) const snackbar = ref({ active: false, color: 'success', text: '' })
const [doSaveOrigin, {loading: savingOrigin, error: errorSaveOrigin}] = useMutation(saveOrigin) const [doSaveOrigin] = useMutation(saveOrigin)
const [doRemoveOrigin, {loading: removingOrigin, error: errorRemoveOrigin}] = useMutation(removeOrigin) const [doRemoveOrigin] = useMutation(removeOrigin)
const [doFetchAddress, {data: address, loading: fetchingAddress, error: errorFetchingAddress}] = useLazyQuery(fetchAddress) const [doFetchAddress, { data: address }] = useLazyQuery(fetchAddress)
const origin = ref('') const origin = ref('')
const fetchAddressFn = () => { const fetchAddressFn = () => {
if (window.navigator) { if (window.navigator) {
window.navigator.geolocation.getCurrentPosition(pos => { window.navigator.geolocation.getCurrentPosition(pos => {
doFetchAddress({variables: {latlng: pos.coords.latitude + "," + pos.coords.longitude}}) doFetchAddress({
.then(() => { variables: {
origin.value = address.value.address; latlng: `${pos.coords.latitude},${pos.coords.longitude}`
}) }
}).then(() => {
origin.value = address.value.address
}) })
} })
} }
const saveOriginFn = o => doSaveOrigin({variables: { origin: o }}).then(() => { }
const saveOriginFn = o =>
doSaveOrigin({ variables: { origin: o } }).then(() => {
refetch.value() refetch.value()
origin.value = '' origin.value = ''
}) })
const removeOriginFn = o => doRemoveOrigin({variables: { origin: o }}).then(() => refetch.value()) const removeOriginFn = o =>
return { doRemoveOrigin({ variables: { origin: o } }).then(() => refetch.value())
isAuthenticated, return {
loading, isAuthenticated,
data, loading,
snackbar, data,
origin, snackbar,
saveOrigin: saveOriginFn, origin,
removeOrigin: removeOriginFn, saveOrigin: saveOriginFn,
fetchAddress: fetchAddressFn removeOrigin: removeOriginFn,
} fetchAddress: fetchAddressFn
} }
} }
}
</script> </script>
+40 -38
View File
@@ -1,15 +1,11 @@
<template> <template>
<v-app :key="$i18n.locale + isAuthenticated"> <v-app :key="$i18n.locale + isAuthenticated">
<themed> <themed>
<v-navigation-drawer <v-navigation-drawer v-model="nav" temporary app>
v-model="nav"
temporary
app
>
<v-list dense> <v-list dense>
<v-list-item> <v-list-item>
<v-list-item-action> <v-list-item-action>
<v-switch v-model="darkMode"/> <v-switch v-model="darkMode" />
</v-list-item-action> </v-list-item-action>
<v-list-item-title>{{ $t('app.darkMode') }}</v-list-item-title> <v-list-item-title>{{ $t('app.darkMode') }}</v-list-item-title>
</v-list-item> </v-list-item>
@@ -24,10 +20,10 @@
</v-list-item> </v-list-item>
<v-list-item v-if="isAuthenticated && user"> <v-list-item v-if="isAuthenticated && user">
<v-list-item-avatar> <v-list-item-avatar>
<v-img :src="user.picture" :alt="user.name"/> <v-img :src="user.picture" :alt="user.name" />
</v-list-item-avatar> </v-list-item-avatar>
<v-list-item-content> <v-list-item-content>
<v-list-item-title v-html="user.name"/> <v-list-item-title v-html="user.name" />
</v-list-item-content> </v-list-item-content>
</v-list-item> </v-list-item>
<v-list-item link to="/"> <v-list-item link to="/">
@@ -59,23 +55,23 @@
</v-list> </v-list>
</v-navigation-drawer> </v-navigation-drawer>
<v-app-bar app scroll-off-screen> <v-app-bar app scroll-off-screen>
<v-app-bar-nav-icon v-on:click="nav = !nav"/> <v-app-bar-nav-icon v-on:click="nav = !nav" />
<v-toolbar-title v-html="title"/> <v-toolbar-title v-html="title" />
<v-spacer/> <v-spacer />
<v-toolbar-items> <v-toolbar-items>
<v-list-item v-if="isAuthenticated && user"> <v-list-item v-if="isAuthenticated && user">
<v-list-item-avatar> <v-list-item-avatar>
<v-img :src="user.picture" :alt="user.name"/> <v-img :src="user.picture" :alt="user.name" />
</v-list-item-avatar> </v-list-item-avatar>
<v-list-item-content> <v-list-item-content>
<v-list-item-title v-html="user.name"/> <v-list-item-title v-html="user.name" />
</v-list-item-content> </v-list-item-content>
</v-list-item> </v-list-item>
</v-toolbar-items> </v-toolbar-items>
</v-app-bar> </v-app-bar>
<v-content> <v-content>
<v-container fluid v-if="!loading"> <v-container fluid v-if="!loading">
<nuxt/> <nuxt />
</v-container> </v-container>
</v-content> </v-content>
</themed> </themed>
@@ -83,32 +79,32 @@
</template> </template>
<style lang="scss"> <style lang="scss">
// We need this line to import all global styling // We need this line to import all global styling
@import "assets/scss/global.scss"; @import 'assets/scss/global.scss';
</style> </style>
<style lang="scss" scoped> <style lang="scss" scoped>
.layout { .layout {
background-color: white; background-color: white;
.log-out { .log-out {
cursor: pointer; cursor: pointer;
}
} }
}
</style> </style>
<script> <script>
import { useAuth } from '../plugins/auth'
import { computed, ref } from '@vue/composition-api' import { computed, ref } from '@vue/composition-api'
import Themed from './components/themed'
import { setDarkMode } from '../utils/localStorage'
import { useRouter, useState } from '@u3u/vue-hooks' import { useRouter, useState } from '@u3u/vue-hooks'
import dayjs from 'dayjs' import dayjs from 'dayjs'
import sv from 'dayjs/locale/sv' import sv from 'dayjs/locale/sv'
import { setDarkMode } from '../utils/localStorage'
import Themed from './components/themed'
import useAuth from '../plugins/auth'
export default { export default {
components: { components: {
Themed, Themed
}, },
setup(props, context) { setup(props, context) {
const { router } = useRouter() const { router } = useRouter()
@@ -118,16 +114,22 @@ export default {
appState && appState.targetUrl appState && appState.targetUrl
? appState.targetUrl ? appState.targetUrl
: window.location.pathname : window.location.pathname
); )
} }
const { loading, isAuthenticated, user, loginWithRedirect, logout } = useAuth(onRedirectCallback) const {
loading,
isAuthenticated,
user,
loginWithRedirect,
logout
} = useAuth(onRedirectCallback)
const doLogin = () => { const doLogin = () => {
loginWithRedirect.value(); loginWithRedirect.value()
} }
const doLogout = () => { const doLogout = () => {
logout.value({ logout.value({
returnTo: window.location.origin returnTo: window.location.origin
}); })
} }
const darkMode = computed({ const darkMode = computed({
get: () => context.root.$vuetify.theme.dark, get: () => context.root.$vuetify.theme.dark,
@@ -138,16 +140,16 @@ export default {
}) })
const locale = computed({ const locale = computed({
get: () => context.root.$i18n.locale, get: () => context.root.$i18n.locale,
set: locale => { set: newLocale => {
if (locale === 'en') { if (newLocale === 'en') {
dayjs.locale(locale) dayjs.locale(newLocale)
} else if (locale === 'sv') { } else if (newLocale === 'sv') {
dayjs.locale(sv) dayjs.locale(sv)
} }
context.root.$i18n.setLocaleCookie(locale) context.root.$i18n.setLocaleCookie(newLocale)
context.root.$vuetify.lang.current = locale context.root.$vuetify.lang.current = newLocale
context.root.$i18n.locale = locale context.root.$i18n.locale = newLocale
} }
}) })
@@ -165,6 +167,6 @@ export default {
locale, locale,
nav nav
} }
}, }
}; }
</script> </script>
+44 -18
View File
@@ -3,29 +3,58 @@ import numberFormats from './translations/numberFormats'
export default { export default {
env: { env: {
graphqlApi: process.env.GRAPHQL_API, graphqlApi: process.env.GRAPHQL_API
}, },
mode: 'spa', mode: 'spa',
head: { head: {
link: [ link: [
{rel: 'apple-touch-icon', sizes: '180x180', href: '/apple-touch-icon.png'}, {
{rel: 'icon', type: 'image/png', sizes: '32x32', href: '/favicon-32x32.png'}, rel: 'apple-touch-icon',
{rel: 'icon', type: 'image/png', sizes: '16x16', href: '/favicon-16x16.png'}, sizes: '180x180',
{rel: 'manifest', href: '/site.webmanifest'}, href: '/apple-touch-icon.png'
{rel: 'mask-icon', href: '/safari-pinned-tab.svg', color: '#7f0aff'}, },
{rel: 'icon', type: 'image/x-icon', href: '/favicon.ico'}, {
{rel: "stylesheet", href: 'https://fonts.googleapis.com/css?family=Roboto:100,300,400,500,700,900|Material+Icons'}, rel: 'icon',
{rel: "stylesheet", href: "https://fonts.googleapis.com/css?family=Material+Icons"}, type: 'image/png',
{rel: "stylesheet", href: "https://cdn.materialdesignicons.com/3.3.92/css/materialdesignicons.min.css"} sizes: '32x32',
href: '/favicon-32x32.png'
},
{
rel: 'icon',
type: 'image/png',
sizes: '16x16',
href: '/favicon-16x16.png'
},
{ rel: 'manifest', href: '/site.webmanifest' },
{ rel: 'mask-icon', href: '/safari-pinned-tab.svg', color: '#7f0aff' },
{ rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' },
{
rel: 'stylesheet',
href:
'https://fonts.googleapis.com/css?family=Roboto:100,300,400,500,700,900|Material+Icons'
},
{
rel: 'stylesheet',
href: 'https://fonts.googleapis.com/css?family=Material+Icons'
},
{
rel: 'stylesheet',
href:
'https://cdn.materialdesignicons.com/3.3.92/css/materialdesignicons.min.css'
}
], ],
meta: [ meta: [
{name: 'viewport', content: 'width=device-width, initial-scale=1, user-scalable=no, minimal-ui'} {
], name: 'viewport',
content:
'width=device-width, initial-scale=1, user-scalable=no, minimal-ui'
}
]
}, },
modules: [ modules: [
'nuxt-i18n', 'nuxt-i18n',
'@nuxtjs/vuetify', '@nuxtjs/vuetify',
['@nuxtjs/moment', { locales: ['sv'], defaultLocale: 'sv' }], ['@nuxtjs/moment', { locales: ['sv'], defaultLocale: 'sv' }]
], ],
i18n: { i18n: {
strategy: 'prefix_and_default', strategy: 'prefix_and_default',
@@ -55,10 +84,7 @@ export default {
vuetify: { vuetify: {
optionsPath: './vuetify.options.js' optionsPath: './vuetify.options.js'
}, },
css: [ css: ['vuetify/dist/vuetify.css', '~/assets/scss/global.scss'],
'vuetify/dist/vuetify.css',
'~/assets/scss/global.scss',
],
plugins: [ plugins: [
'~/plugins/composition', '~/plugins/composition',
'~/plugins/hooks', '~/plugins/hooks',
@@ -81,4 +107,4 @@ export default {
} }
} }
} }
}; }
+11 -3
View File
@@ -21,8 +21,6 @@
"apollo-link-http": "^1.5.15", "apollo-link-http": "^1.5.15",
"core-js": "3", "core-js": "3",
"dayjs": "^1.8.19", "dayjs": "^1.8.19",
"eslint": "^5.1.0",
"eslint-plugin-vue": "^4.5.0",
"graphql": "^14.4.2", "graphql": "^14.4.2",
"graphql-tag": "^2.10.1", "graphql-tag": "^2.10.1",
"moment": "^2.24.0", "moment": "^2.24.0",
@@ -39,7 +37,7 @@
"dev": "nuxt", "dev": "nuxt",
"build": "nuxt build", "build": "nuxt build",
"generate": "nuxt generate", "generate": "nuxt generate",
"lint": "eslint --ext .js,.vue --ignore-path .gitignore .", "lint": "eslint --quiet --fix --ext .js,.vue --ignore-path .gitignore .",
"precommit": "yarn lint", "precommit": "yarn lint",
"prepush": "yarn test", "prepush": "yarn test",
"start": "node server/index.js", "start": "node server/index.js",
@@ -51,7 +49,17 @@
}, },
"devDependencies": { "devDependencies": {
"@babel/runtime-corejs3": "^7.8.3", "@babel/runtime-corejs3": "^7.8.3",
"babel-eslint": "^10.0.3",
"cli-engine": "^4.7.6",
"cypress": "^3.1.0", "cypress": "^3.1.0",
"eslint": "^6.8.0",
"eslint-config-airbnb-base": "^14.0.0",
"eslint-config-prettier": "^6.9.0",
"eslint-loader": "^3.0.3",
"eslint-plugin-import": "^2.20.0",
"eslint-plugin-prettier": "^3.1.2",
"eslint-plugin-vue": "^6.1.2",
"prettier": "^1.19.1",
"wait-on": "^3.2.0" "wait-on": "^3.2.0"
}, },
"snyk": true "snyk": true
+12 -12
View File
@@ -3,18 +3,18 @@
</template> </template>
<script> <script>
import Filters from "~/components/pages/filters"; import Filters from '../components/pages/filters'
import { useTranslation } from '../plugins/i18n' import { useTranslation } from '../plugins/i18n'
export default { export default {
components: { components: {
Filters Filters
}, },
head() { head() {
const { t } = useTranslation() const { t } = useTranslation()
return { return {
title: t('filters.title') title: t('filters.title')
};
} }
}; }
}
</script> </script>
+3 -3
View File
@@ -3,7 +3,7 @@
</template> </template>
<script> <script>
import Events from "~/components/pages/events"; import Events from '../components/pages/events'
import { useTranslation } from '../plugins/i18n' import { useTranslation } from '../plugins/i18n'
export default { export default {
@@ -14,7 +14,7 @@ export default {
const { t } = useTranslation() const { t } = useTranslation()
return { return {
title: t('events.title') title: t('events.title')
}; }
} }
}; }
</script> </script>
+12 -12
View File
@@ -3,18 +3,18 @@
</template> </template>
<script> <script>
import Origins from "~/components/pages/origins"; import Origins from '../components/pages/origins'
import { useTranslation } from '../plugins/i18n' import { useTranslation } from '../plugins/i18n'
export default { export default {
components: { components: {
Origins Origins
}, },
head() { head() {
const { t } = useTranslation() const { t } = useTranslation()
return { return {
title: t('origins.title') title: t('origins.title')
};
} }
}; }
}
</script> </script>
+63 -65
View File
@@ -1,9 +1,9 @@
import { ApolloClient } from 'apollo-client' import { ApolloClient } from 'apollo-client'
import { createHttpLink } from 'apollo-link-http' import { createHttpLink } from 'apollo-link-http'
import { InMemoryCache } from 'apollo-cache-inmemory'; import { InMemoryCache } from 'apollo-cache-inmemory'
import { setContext } from 'apollo-link-context' import { setContext } from 'apollo-link-context'
import { useAuth } from './auth'
import { reactive, toRefs } from '@vue/composition-api' import { reactive, toRefs } from '@vue/composition-api'
import useAuth from './auth'
let instance = null let instance = null
@@ -13,23 +13,22 @@ const httpLink = createHttpLink({
uri: apiUrl uri: apiUrl
}) })
const getToken = async (options) => { const getToken = async options => {
const { getTokenSilently, isAuthenticated } = useAuth() const { getTokenSilently, isAuthenticated } = useAuth()
if (isAuthenticated.value) { if (isAuthenticated.value) {
return await getTokenSilently.value(options) return getTokenSilently.value(options)
} else {
return options
} }
}; return options
}
const authLink = setContext(async (_, { headers }) => { const authLink = setContext(async (_, { headers }) => {
const token = await getToken() const token = await getToken()
return { return {
headers: { headers: {
...headers, ...headers,
authorization: token ? `Bearer ${token}` : '', authorization: token ? `Bearer ${token}` : ''
} }
}; }
}) })
const client = new ApolloClient({ const client = new ApolloClient({
@@ -37,84 +36,83 @@ const client = new ApolloClient({
cache: new InMemoryCache(), cache: new InMemoryCache(),
defaultOptions: { defaultOptions: {
watchQuery: { watchQuery: {
fetchPolicy: 'cache-and-network', fetchPolicy: 'cache-and-network'
}, }
}, }
}) })
instance = client instance = client
export const useMutation = (mutation, options) => { export const useMutation = (mutation, options) => {
const opts = options;
const doMutate = options => new Promise((resolve, reject) => {
out.loading = true
instance.mutate({
mutation,
...opts,
...options
})
.then(result => {
out.loading = false
out.data = result.data
resolve(result)
})
.catch(e => {
out.loading = false
out.error = e
reject(e)
})
})
const out = reactive({ const out = reactive({
data: {}, data: {},
error: null, error: null,
loading: false, loading: false
}) })
const doMutate = mutateOptions =>
new Promise((resolve, reject) => {
out.loading = true
instance
.mutate({
mutation,
...options,
...mutateOptions
})
.then(result => {
out.loading = false
out.data = result.data
resolve(result)
})
.catch(e => {
out.loading = false
out.error = e
reject(e)
})
})
return [doMutate, toRefs(out)] return [doMutate, toRefs(out)]
} }
export const useLazyQuery = (query, options) => { export const useLazyQuery = (query, options) => {
const opts = options
let watchedQuery = null let watchedQuery = null
const doQuery = options => new Promise((resolve, reject) => { const out = reactive({
out.loading = true data: {},
let effectiveOptions = { error: null,
query, loading: false
...(opts || {}),
...(options || {})
}
watchedQuery = instance.watchQuery(effectiveOptions)
watchedQuery.subscribe(({loading, data}) => {
out.loading = loading
out.data = data || {}
out.error = null
resolve(data)
}, error => {
out.loading = false
out.error = error
reject(error)
})
}) })
const refetch = variables => { const doQuery = queryOptions =>
new Promise((resolve, reject) => {
out.loading = true
const effectiveOptions = {
query,
...(options || {}),
...(queryOptions || {})
}
watchedQuery = instance.watchQuery(effectiveOptions)
watchedQuery.subscribe(
({ loading, data }) => {
out.loading = loading
out.data = data || {}
out.error = null
resolve(data)
},
error => {
out.loading = false
out.error = error
reject(error)
}
)
})
out.refetch = variables => {
const opts = {} const opts = {}
if (variables) ( if (variables) opts.variables = variables
opts.variables = variables
)
doQuery(opts) doQuery(opts)
} }
const startPolling = interval => doQuery({pollInterval: interval}) out.startPolling = interval => doQuery({ pollInterval: interval })
const stopPolling = () => { out.stopPolling = () => {
if (watchedQuery) { if (watchedQuery) {
watchedQuery.stopPolling() watchedQuery.stopPolling()
} }
} }
const out = reactive({
data: {},
error: null,
loading: false,
refetch,
startPolling,
stopPolling
})
return [doQuery, toRefs(out)] return [doQuery, toRefs(out)]
} }
+55 -59
View File
@@ -3,23 +3,23 @@ import { reactive, toRefs } from '@vue/composition-api'
/** Define a default action to perform after authentication */ /** Define a default action to perform after authentication */
const DEFAULT_REDIRECT_CALLBACK = () => const DEFAULT_REDIRECT_CALLBACK = () =>
window.history.replaceState({}, document.title, window.location.pathname); window.history.replaceState({}, document.title, window.location.pathname)
let instance; let instance
const params = (new URL(window.location)).searchParams const params = new URL(window.location).searchParams
const domain = params.get('domain') || 'unbound.eu.auth0.com' const domain = params.get('domain') || 'unbound.eu.auth0.com'
export const useAuth = (onRedirectCallback = DEFAULT_REDIRECT_CALLBACK) => { export default (onRedirectCallback = DEFAULT_REDIRECT_CALLBACK) => {
if (instance) { if (instance) {
return toRefs(instance) return toRefs(instance)
} }
const options = { const options = {
domain: domain, domain,
client_id: 'orQfnvCPUR5C3mJkKoiWLQHOVQsBn60e', client_id: 'orQfnvCPUR5C3mJkKoiWLQHOVQsBn60e',
audience: 'http://dancefinder.unbound.se', audience: 'http://dancefinder.unbound.se',
redirect_uri: window.location.origin, redirect_uri: window.location.origin
} }
instance = reactive({ instance = reactive({
@@ -31,95 +31,91 @@ export const useAuth = (onRedirectCallback = DEFAULT_REDIRECT_CALLBACK) => {
error: null, error: null,
/** Authenticates the user using a popup window */ /** Authenticates the user using a popup window */
loginWithPopup: async o => { loginWithPopup: async o => {
this.popupOpen = true; this.popupOpen = true
try { try {
await instance.auth0Client.loginWithPopup(o); await instance.auth0Client.loginWithPopup(o)
} catch (e) { } catch (e) {
// eslint-disable-next-line // eslint-disable-next-line
console.error(e); console.error(e);
} finally { } finally {
instance.popupOpen = false; instance.popupOpen = false
} }
instance.user = await instance.auth0Client.getUser(); instance.user = await instance.auth0Client.getUser()
instance.isAuthenticated = true; instance.isAuthenticated = true
}, },
/** Handles the callback when logging in using a redirect */ /** Handles the callback when logging in using a redirect */
handleRedirectCallback: async () => { handleRedirectCallback: async () => {
instance.loading = true; instance.loading = true
try { try {
await instance.auth0Client.handleRedirectCallback(); await instance.auth0Client.handleRedirectCallback()
instance.user = await instance.auth0Client.getUser(); instance.user = await instance.auth0Client.getUser()
instance.isAuthenticated = true; instance.isAuthenticated = true
} catch (e) { } catch (e) {
instance.error = e; instance.error = e
} finally { } finally {
instance.loading = false; instance.loading = false
} }
}, },
/** Authenticates the user using the redirect method */ /** Authenticates the user using the redirect method */
loginWithRedirect: o => { loginWithRedirect: o => {
return instance.auth0Client.loginWithRedirect(o); return instance.auth0Client.loginWithRedirect(o)
}, },
/** Returns all the claims present in the ID token */ /** Returns all the claims present in the ID token */
getIdTokenClaims: o => { getIdTokenClaims: o => {
return instance.auth0Client.getIdTokenClaims(o); return instance.auth0Client.getIdTokenClaims(o)
}, },
/** Returns the access token. If the token is invalid or missing, a new one is retrieved */ /** Returns the access token. If the token is invalid or missing, a new one is retrieved */
getTokenSilently: o => { getTokenSilently: o => {
return instance.auth0Client.getTokenSilently(o); return instance.auth0Client.getTokenSilently(o)
}, },
/** Gets the access token using a popup window */ /** Gets the access token using a popup window */
getTokenWithPopup: o => { getTokenWithPopup: o => {
return instance.auth0Client.getTokenWithPopup(o); return instance.auth0Client.getTokenWithPopup(o)
}, },
/** Logs the user out and removes their session on the authorization server */ /** Logs the user out and removes their session on the authorization server */
logout: o => { logout: o => {
return instance.auth0Client.logout(o); return instance.auth0Client.logout(o)
} }
}) })
const fetchUser = () => { const fetchUser = () => {
instance.auth0Client.isAuthenticated() instance.auth0Client.isAuthenticated().then(a => {
.then(a => { instance.isAuthenticated = a
instance.isAuthenticated = a instance.auth0Client.getUser().then(u => {
instance.auth0Client.getUser() instance.user = u
.then(u => {
instance.user = u
instance.loading = false;
});
});
}
// Create a new instance of the SDK client using members of the given options object
createAuth0Client(options)
.then(client => {
instance.loading = true
instance.auth0Client = client
try {
// If the user is returning to the app after authentication..
if (
window.location.search.includes('code=') &&
window.location.search.includes('state=')
) {
// handle the redirect and retrieve tokens
instance.auth0Client.handleRedirectCallback()
.then(appState => {
// Notify subscribers that the redirect callback has happened, passing the appState
// (useful for retrieving any pre-authentication state)
onRedirectCallback(appState);
// Initialize our internal authentication state
fetchUser()
})
} else {
fetchUser()
}
} catch (e) {
instance.error = e;
} finally {
instance.loading = false instance.loading = false
} })
}) })
}
// Create a new instance of the SDK client using members of the given options object
createAuth0Client(options).then(client => {
instance.loading = true
instance.auth0Client = client
try {
// If the user is returning to the app after authentication..
if (
window.location.search.includes('code=') &&
window.location.search.includes('state=')
) {
// handle the redirect and retrieve tokens
instance.auth0Client.handleRedirectCallback().then(appState => {
// Notify subscribers that the redirect callback has happened, passing the appState
// (useful for retrieving any pre-authentication state)
onRedirectCallback(appState)
// Initialize our internal authentication state
fetchUser()
})
} else {
fetchUser()
}
} catch (e) {
instance.error = e
} finally {
instance.loading = false
}
})
return toRefs(instance) return toRefs(instance)
} }
+3 -3
View File
@@ -1,4 +1,4 @@
import Vue from 'vue'; import Vue from 'vue'
import VueCompositionApi from '@vue/composition-api'; import VueCompositionApi from '@vue/composition-api'
Vue.use(VueCompositionApi); Vue.use(VueCompositionApi)
+3 -3
View File
@@ -1,4 +1,4 @@
import Vue from 'vue'; import Vue from 'vue'
import hooks from '@u3u/vue-hooks'; import hooks from '@u3u/vue-hooks'
Vue.use(hooks); Vue.use(hooks)
+1 -1
View File
@@ -8,7 +8,7 @@ export const useTranslation = () => {
} }
} }
export default ({app}) => { export default ({ app }) => {
i18n = app.i18n i18n = app.i18n
localePath = app.localePath localePath = app.localePath
} }
+2 -2
View File
@@ -1,5 +1,5 @@
import Vue from 'vue' import Vue from 'vue'
import vueNumeralFilterInstaller from 'vue-numeral-filter'; import vueNumeralFilterInstaller from 'vue-numeral-filter'
// TODO: Switch to sv-se when PR (https://github.com/adamwdraper/Numeral-js/pull/534) is merged // TODO: Switch to sv-se when PR (https://github.com/adamwdraper/Numeral-js/pull/534) is merged
Vue.use(vueNumeralFilterInstaller, { locale: 'no' }); Vue.use(vueNumeralFilterInstaller, { locale: 'no' })
+1 -1
View File
@@ -1,4 +1,4 @@
import Vue from 'vue' import Vue from 'vue'
import Vuetify from 'vuetify' import Vuetify from 'vuetify'
Vue.use(Vuetify); Vue.use(Vuetify)
+5 -5
View File
@@ -1,9 +1,9 @@
export const state = () => ({ export const state = () => ({
title: "" title: ''
}); })
export const mutations = { export const mutations = {
setTitle(state, title) { setTitle(currentState, title) {
state.title = title currentState.title = title
} }
}; }
+7 -7
View File
@@ -5,9 +5,9 @@ export default {
logout: 'Log out', logout: 'Log out',
darkMode: 'Dark mode', darkMode: 'Dark mode',
links: { links: {
events: "Events", events: 'Events',
filters: "Filters", filters: 'Filters',
origins: "Origins", origins: 'Origins'
} }
}, },
sv: { sv: {
@@ -16,9 +16,9 @@ export default {
logout: 'Logga ut', logout: 'Logga ut',
darkMode: 'Mörkt läge', darkMode: 'Mörkt läge',
links: { links: {
events: "Evenemang", events: 'Evenemang',
filters: "Hantera filter", filters: 'Hantera filter',
origins: "Hantera startpunkter", origins: 'Hantera startpunkter'
}, }
} }
} }
+3 -3
View File
@@ -8,12 +8,12 @@ export default {
app: app.en, app: app.en,
events: events.en, events: events.en,
filters: filters.en, filters: filters.en,
origins: origins.en, origins: origins.en
}, },
sv: { sv: {
app: app.sv, app: app.sv,
events: events.sv, events: events.sv,
filters: filters.sv, filters: filters.sv,
origins: origins.sv, origins: origins.sv
}, }
} }
+6 -4
View File
@@ -1,12 +1,14 @@
export default { export default {
'en': { en: {
currency: { currency: {
style: 'currency', currency: 'USD' style: 'currency',
currency: 'USD'
} }
}, },
'sv': { sv: {
currency: { currency: {
style: 'currency', currency: 'SEK' style: 'currency',
currency: 'SEK'
} }
} }
} }
+2 -1
View File
@@ -9,7 +9,8 @@ export default {
dataTable: { dataTable: {
itemsPerPageText: 'Rader per sida:', itemsPerPageText: 'Rader per sida:',
ariaLabel: { ariaLabel: {
sortDescending: ': Sorterad minskande. Aktivera för att ta bort sortering.', sortDescending:
': Sorterad minskande. Aktivera för att ta bort sortering.',
sortAscending: ': Sorterad ökande. Aktivera för att sortera minskande.', sortAscending: ': Sorterad ökande. Aktivera för att sortera minskande.',
sortNone: ': Ej sorterad. Aktivera för att sortera ökande.' sortNone: ': Ej sorterad. Aktivera för att sortera ökande.'
} }
@@ -1,15 +0,0 @@
import {
findEvents,
} from '../index';
const verifyResponse = (response) => {
expect(response.errors).toBe(undefined);
};
const verifyError = (response) => {
expect(response.errors.length).toBeGreaterThan(0);
};
describe('GQL Queries', () => {
test('findEvents', () => findEvents().then(verifyResponse));
});
+2 -7
View File
@@ -1,9 +1,4 @@
export { export { findEvents, findOrigins, fetchAddress, fetchFilters } from './queries'
findEvents,
findOrigins,
fetchAddress,
fetchFilters,
} from './queries';
export { export {
toggleIgnoreBand, toggleIgnoreBand,
@@ -13,4 +8,4 @@ export {
toggleIgnoreState, toggleIgnoreState,
saveOrigin, saveOrigin,
removeOrigin removeOrigin
} from './mutations'; } from './mutations'
+28 -28
View File
@@ -1,37 +1,37 @@
import gql from 'graphql-tag' import gql from 'graphql-tag'
export const toggleIgnoreBand = gql` export const toggleIgnoreBand = gql`
mutation ToggleIgnoreBand($name: String!) { mutation ToggleIgnoreBand($name: String!) {
ignore: ToggleIgnoreBand(name: $name) ignore: ToggleIgnoreBand(name: $name)
} }
` `
export const toggleIgnoreDanceHall = gql` export const toggleIgnoreDanceHall = gql`
mutation ToggleIgnoreDanceHall($name: String!) { mutation ToggleIgnoreDanceHall($name: String!) {
ignore: ToggleIgnoreDanceHall(name: $name) ignore: ToggleIgnoreDanceHall(name: $name)
} }
` `
export const toggleIgnoreCity = gql` export const toggleIgnoreCity = gql`
mutation ToggleIgnoreCity($name: String!) { mutation ToggleIgnoreCity($name: String!) {
ignore: ToggleIgnoreCity(name: $name) ignore: ToggleIgnoreCity(name: $name)
} }
` `
export const toggleIgnoreMunicipality = gql` export const toggleIgnoreMunicipality = gql`
mutation ToggleIgnoreMunicipality($name: String!) { mutation ToggleIgnoreMunicipality($name: String!) {
ignore: ToggleIgnoreMunicipality(name: $name) ignore: ToggleIgnoreMunicipality(name: $name)
} }
` `
export const toggleIgnoreState = gql` export const toggleIgnoreState = gql`
mutation ToggleIgnoreState($name: String!) { mutation ToggleIgnoreState($name: String!) {
ignore: ToggleIgnoreState(name: $name) ignore: ToggleIgnoreState(name: $name)
} }
` `
export const saveOrigin = gql` export const saveOrigin = gql`
mutation SaveOrigin($origin: String!) { mutation SaveOrigin($origin: String!) {
saved: SaveOrigin(origin: $origin) saved: SaveOrigin(origin: $origin)
} }
` `
export const removeOrigin = gql` export const removeOrigin = gql`
mutation RemoveOrigin($origin: String!) { mutation RemoveOrigin($origin: String!) {
removed: RemoveOrigin(origin: $origin) removed: RemoveOrigin(origin: $origin)
} }
` `
+6 -6
View File
@@ -1,8 +1,8 @@
import gql from 'graphql-tag' import gql from 'graphql-tag'
export const findEvents = gql` export const findEvents = gql`
query events($range: Range $origins: [String!] $includeOrigins: Boolean!) { query events($range: Range, $origins: [String!], $includeOrigins: Boolean!) {
events: Events(range: $range origins: $origins) { events: Events(range: $range, origins: $origins) {
date date
time time
band { band {
@@ -23,19 +23,19 @@ export const findEvents = gql`
} }
origins: Origins @include(if: $includeOrigins) origins: Origins @include(if: $includeOrigins)
} }
`; `
export const findOrigins = gql` export const findOrigins = gql`
query origins { query origins {
origins: Origins origins: Origins
} }
`; `
export const fetchAddress = gql` export const fetchAddress = gql`
query adressFromLatLng($latlng: String!) { query adressFromLatLng($latlng: String!) {
address: AddressFromLatLng(latlng: $latlng) address: AddressFromLatLng(latlng: $latlng)
} }
`; `
export const fetchFilters = gql` export const fetchFilters = gql`
query { query {
@@ -45,4 +45,4 @@ export const fetchFilters = gql`
danceHalls: IgnoredDanceHalls danceHalls: IgnoredDanceHalls
municipalities: IgnoredMunicipalities municipalities: IgnoredMunicipalities
} }
`; `
+3 -3
View File
@@ -2,8 +2,8 @@ const DARK_MODE_KEY = 'dancefinder-dark-mode'
const LOCALE_KEY = 'dancefinder-locale' const LOCALE_KEY = 'dancefinder-locale'
const getDarkMode = () => localStorage.getItem(DARK_MODE_KEY) const getDarkMode = () => localStorage.getItem(DARK_MODE_KEY)
const setDarkMode = (mode) => localStorage.setItem(DARK_MODE_KEY, mode) const setDarkMode = mode => localStorage.setItem(DARK_MODE_KEY, mode)
const getLocale = () => localStorage.getItem(LOCALE_KEY) const getLocale = () => localStorage.getItem(LOCALE_KEY)
const setLocale = (locale) => localStorage.setItem(LOCALE_KEY, locale) const setLocale = locale => localStorage.setItem(LOCALE_KEY, locale)
export { getDarkMode, setDarkMode, getLocale, setLocale }; export { getDarkMode, setDarkMode, getLocale, setLocale }
+731 -201
View File
File diff suppressed because it is too large Load Diff