gancio/pages/index.vue

150 lines
4.4 KiB
Vue
Raw Normal View History

<template lang="pug">
v-container#home(fluid)
//- Announcements
Announcement(v-for='announcement in announcements' :key='`a_${announcement.id}`' :announcement='announcement')
2020-12-04 17:28:54 +01:00
//- Calendar and search bar
v-row#calbarmb-2
.col-xl-5.col-lg-5.col-md-6.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')
.col
2020-12-04 17:28:54 +01:00
Search(:filters='filters' @update='updateFilters')
v-chip(v-if='selectedDay' close @click:close='dayChange(selectedDay)') {{selectedDay}}
2020-12-04 17:28:54 +01:00
//- Events
#events
Event(v-for='event in events'
:key='event.id' :event='event'
@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 },
async asyncData ({ params, $api }) {
const events = await $api.getEvents({
start: dayjs().unix()
})
return { events }
},
data () {
return {
date: dayjs().format('YYYY-MM-DD'),
events: [],
start: dayjs().unix(),
end: null,
filters: { tags: [], places: [] },
selectedDay: null
}
2019-06-06 23:54:32 +02:00
},
computed: {
...mapState(['settings', 'announcements']),
},
methods: {
...mapActions(['setFilters']),
async updateEvents () {
this.events = await this.$api.getEvents({
start: this.start,
end: this.end,
places: this.filters.places,
tags: this.filters.tags
})
this.setFilters(this.filters)
},
placeClick (place_id) {
if (this.filters.places.includes(place_id)) {
this.filters.places = this.filters.places.filter(p_id => p_id !== place_id)
} else {
this.filters.places.push(place_id)
}
this.updateEvents()
},
tagClick (tag) {
if (this.filters.tags.includes(tag)) {
this.filters.tags = this.filters.tags.filter(t => t !== tag)
} else {
this.filters.tags.push(tag)
}
this.updateEvents()
},
updateFilters (filters) {
this.filters = filters
this.updateEvents()
},
2020-12-04 17:28:54 +01:00
monthChange ({ year, month }) {
this.selectedDay = null
// check if current month is selected
if (month - 1 === dayjs().month()) {
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()
}
// this.end = dayjs().year(year).month(month - 1).endOf('month').unix() // .endOf('week').unix()
this.end = null
this.updateEvents()
},
dayChange (day) {
if (this.selectedDay === day) {
this.selectedDay = null
this.date = dayjs().format('YYYY-MM-DD')
this.start = dayjs().unix() // .startOf('week').unix()
this.end = null
this.updateEvents()
return
}
this.start = dayjs(day).unix()
this.end = dayjs(day).endOf('day').unix()
this.date = dayjs(day).format('YYYY-MM-DD')
this.selectedDay = day
this.updateEvents()
}
},
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' }
]
}
2020-01-15 23:47:17 +01:00
}
2019-05-30 12:04:14 +02:00
}
</script>
<style lang='less'>
#home {
max-width: 1400px;
}
#events {
margin: 0 auto;
display: flex;
flex-wrap: wrap;
justify-content: center;
}
</style>