gancio-upstream/pages/index.vue

157 lines
5.2 KiB
Vue
Raw Normal View History

<template lang="pug">
v-container#home(fluid)
//- Announcements
2021-03-05 14:20:23 +01:00
#announcements.mr-1
Announcement(v-for='announcement in announcements' :key='`a_${announcement.id}`' :announcement='announcement')
2020-12-04 17:28:54 +01:00
//- Calendar and search bar
2021-02-09 12:15:22 +01:00
v-row
2021-01-11 00:17:56 +01:00
.col-xl-5.col-lg-5.col-md-7.col-sm-12.col-xs-12
2020-12-04 17:28:54 +01:00
//- this is needed as v-calendar does not support SSR
//- https://github.com/nathanreyes/v-calendar/issues/336
client-only
Calendar(@dayclick='dayChange' @monthchange='monthChange' :events='events')
2021-02-09 12:15:22 +01:00
.col.pt-0.pt-md-2
2020-12-04 17:28:54 +01:00
Search(:filters='filters' @update='updateFilters')
2021-01-11 00:17:56 +01:00
v-chip(v-if='selectedDay' close @click:close='dayChange({ date: selectedDay})') {{selectedDay}}
2020-12-04 17:28:54 +01:00
//- Events
2021-01-22 21:16:22 +01:00
#events.mt-1
//- div.event(v-for='(event, idx) in events' :key='event.id' v-intersect="(entries, observer, isIntersecting) => intersecting[event.id] = isIntersecting")
Event(:event='event' v-for='(event, idx) in events' :key='event.id' @tagclick='tagClick' @placeclick='placeClick')
2019-04-03 00:25:12 +02:00
</template>
2019-05-30 12:04:14 +02:00
<script>
import { mapState, mapActions } from 'vuex'
import dayjs from 'dayjs'
import Event from '@/components/Event'
import Announcement from '@/components/Announcement'
import Search from '@/components/Search'
2020-12-04 17:28:54 +01:00
import Calendar from '@/components/Calendar'
2019-05-30 12:04:14 +02:00
export default {
name: 'Index',
2020-12-04 17:28:54 +01:00
components: { Event, Search, Announcement, Calendar },
2021-01-11 00:17:56 +01:00
async asyncData ({ params, $api, store }) {
const events = await $api.getEvents({
2021-01-11 00:17:56 +01:00
start: dayjs().unix(),
end: null,
2021-03-10 15:26:09 +01:00
...store.state.filters
})
2021-01-25 01:17:25 +01:00
return { events, first: true }
},
2021-01-11 00:17:56 +01:00
data ({ $store }) {
return {
2021-01-25 01:17:25 +01:00
first: true,
date: dayjs().format('YYYY-MM-DD'),
events: [],
start: dayjs().unix(),
end: null,
2021-01-25 01:17:25 +01:00
selectedDay: null
2021-01-22 21:16:22 +01:00
// intersecting: {}
}
2019-06-06 23:54:32 +02:00
},
2021-03-05 14:20:23 +01:00
head () {
return {
title: this.settings.title,
meta: [
// hid is used as unique identifier. Do not use `vmid` for it as it will not work
{ hid: 'description', name: 'description', content: this.settings.description },
{ hid: 'og-description', name: 'og:description', content: this.settings.description },
{ hid: 'og-title', property: 'og:title', content: this.settings.title },
{ hid: 'og-url', property: 'og:url', content: this.settings.baseurl },
{ property: 'og:image', content: this.settings.baseurl + '/favicon.ico' }
],
link: [
{ rel: 'alternate', type: 'application/rss+xml', title: this.settings.title, href: this.settings.baseurl + '/feed/rss' }
]
}
2021-01-11 00:17:56 +01:00
},
2021-03-10 15:26:09 +01:00
computed: mapState(['settings', 'announcements', 'filters']),
2021-04-14 01:35:18 +02:00
mounted () {
const tags = document.location.hash.split('#').map(tag => decodeURIComponent(tag))
if (tags) {
this.setFilters({ ...this.filters, tags })
this.updateEvents()
}
},
methods: {
2021-01-22 21:16:22 +01:00
// onIntersect (isIntersecting, eventId) {
// this.intersecting[eventId] = isIntersecting
// },
...mapActions(['setFilters']),
2021-01-22 23:08:38 +01:00
updateEvents () {
return this.$api.getEvents({
start: this.start,
end: this.end,
2021-03-10 15:26:09 +01:00
...this.filters
2021-01-22 23:08:38 +01:00
}).then(events => {
this.events = events
2021-03-05 14:20:23 +01:00
this.$nuxt.$loading.finish()
})
},
placeClick (place_id) {
if (this.filters.places.includes(place_id)) {
2021-03-10 15:26:09 +01:00
this.setFilters({ ...this.filters, places: this.filters.places.filter(p_id => p_id !== place_id) })
} else {
2021-03-10 15:26:09 +01:00
this.setFilters({ ...this.filters, places: [].concat(this.filters.places, place_id) })
}
this.updateEvents()
},
tagClick (tag) {
2021-04-14 01:35:18 +02:00
this.$nuxt.$loading.start()
this.$router.push(`#${tag}`)
if (this.filters.tags.includes(tag)) {
2021-03-10 15:26:09 +01:00
this.setFilters({ ...this.filters, tags: this.filters.tags.filter(t => t !== tag) })
} else {
2021-03-10 15:26:09 +01:00
this.setFilters({ ...this.filters, tags: [].concat(this.filters.tags, tag) })
}
this.updateEvents()
},
2020-12-04 17:28:54 +01:00
monthChange ({ year, month }) {
2021-01-25 01:17:25 +01:00
if (this.first) {
this.first = false
return
}
2021-03-05 14:20:23 +01:00
this.$nuxt.$loading.start()
this.selectedDay = null
// check if current month is selected
2021-01-22 23:08:38 +01:00
if (month - 1 === dayjs().month() && year === dayjs().year()) {
this.start = dayjs().unix()
this.date = dayjs().format('YYYY-MM-DD')
} else {
this.date = ''
this.start = dayjs().year(year).month(month - 1).startOf('month').unix() // .startOf('week').unix()
}
2021-03-08 14:38:47 +01:00
// TODO: check if calendar view is double
this.end = dayjs().year(year).month(month).endOf('month').unix() // .endOf('week').unix()
this.updateEvents()
},
2021-03-10 15:26:09 +01:00
updateFilters (filters) {
2021-04-14 01:35:18 +02:00
this.$nuxt.$loading.start()
2021-03-10 15:26:09 +01:00
this.setFilters(filters)
this.updateEvents()
},
dayChange (day) {
2021-04-14 01:35:18 +02:00
this.$nuxt.$loading.start()
2021-01-11 00:17:56 +01:00
const date = dayjs(day.date).format('YYYY-MM-DD')
if (this.selectedDay === date) {
this.selectedDay = null
2021-04-14 01:35:18 +02:00
this.start = dayjs(day.date).startOf('month').unix() // .startOf('week').unix()
this.end = dayjs(day.date).endOf('month').unix()
this.updateEvents()
return
}
2021-01-11 00:17:56 +01:00
this.start = dayjs(date).startOf('day').unix()
2021-03-07 21:32:44 +01:00
this.end = dayjs(date).endOf('day').unix()
2021-01-11 00:17:56 +01:00
this.selectedDay = date
this.updateEvents()
}
2020-01-15 23:47:17 +01:00
}
2019-05-30 12:04:14 +02:00
}
</script>