gancio-upstream/pages/index.vue

140 lines
4.7 KiB
Vue
Raw Normal View History

<template lang="pug">
v-container.px-2.px-sm-6.pt-0
//- Announcements
#announcements.mt-2.mt-sm-4(v-if='announcements.length')
Announcement(v-for='announcement in announcements' :key='`a_${announcement.id}`' :announcement='announcement')
//- Events
#events.mt-sm-4.mt-2
2022-11-24 17:30:01 +01:00
Event(:event='event' v-for='(event, idx) in visibleEvents' :lazy='idx>2' :key='event.id')
2019-04-03 00:25:12 +02:00
</template>
2019-05-30 12:04:14 +02:00
<script>
2022-11-24 17:30:01 +01:00
import { mapState, mapActions } from 'vuex'
import debounce from 'lodash/debounce'
import dayjs from 'dayjs'
import Event from '@/components/Event'
import Announcement from '@/components/Announcement'
2022-08-14 14:40:41 +02:00
import { mdiMagnify, mdiCloseCircle } from '@mdi/js'
2019-05-30 12:04:14 +02:00
export default {
name: 'Index',
2022-11-24 17:30:01 +01:00
components: { Event, Announcement },
2021-09-27 11:12:14 +02:00
middleware: 'setup',
2022-11-24 17:30:01 +01:00
async fetch () {
return this.getEvents()
},
2022-11-24 17:30:01 +01:00
activated() {
if (this.$fetchState.timestamp <= Date.now() - 60000) {
this.$fetch();
}
},
2022-08-14 14:40:41 +02:00
data ({ $store }) {
return {
2022-08-14 14:40:41 +02:00
mdiMagnify, mdiCloseCircle,
2021-04-26 23:18:50 +02:00
isCurrentMonth: true,
now: dayjs().unix(),
date: dayjs.tz().format('YYYY-MM-DD'),
2021-04-26 23:18:50 +02:00
start: dayjs().startOf('month').unix(),
end: null,
2022-11-24 17:30:01 +01:00
searching: false,
tmpEvents: [],
2022-08-14 14:40:41 +02:00
selectedDay: null,
show_recurrent: $store.state.settings.recurrent_event_visible,
}
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 + '/logo.png' }
2021-03-05 14:20:23 +01:00
],
link: [
2022-11-06 00:19:13 +01:00
{ rel: 'apple-touch-icon', href: this.settings.baseurl + '/logo.png' },
{ rel: 'alternate', type: 'application/rss+xml', title: this.settings.title, href: this.settings.baseurl + '/feed/rss' },
{ rel: 'alternate', type: 'text/calendar', title: this.settings.title, href: this.settings.baseurl + '/feed/ics' }
2021-03-05 14:20:23 +01:00
]
}
2021-01-11 00:17:56 +01:00
},
2021-04-26 23:18:50 +02:00
computed: {
2022-11-24 17:30:01 +01:00
...mapState(['settings', 'announcements', 'events']),
2021-04-26 23:18:50 +02:00
visibleEvents () {
2022-11-24 17:30:01 +01:00
if (this.searching) {
return this.tmpEvents
}
2021-04-26 23:18:50 +02:00
const now = dayjs().unix()
if (this.selectedDay) {
2022-08-07 21:49:59 +02:00
const min = dayjs.tz(this.selectedDay).startOf('day').unix()
const max = dayjs.tz(this.selectedDay).endOf('day').unix()
2022-09-14 12:01:08 +02:00
return this.events.filter(e => (e.start_datetime <= max && (e.end_datetime || e.start_datetime) >= min) && (this.show_recurrent || !e.parentId))
2021-04-26 23:18:50 +02:00
} else if (this.isCurrentMonth) {
2022-11-04 12:22:21 +01:00
return this.events.filter(e => ((e.end_datetime ? e.end_datetime > now : e.start_datetime + 3 * 60 * 60 > now) && (this.show_recurrent || !e.parentId)))
2021-04-26 23:18:50 +02:00
} else {
2022-08-14 14:40:41 +02:00
return this.events.filter(e => this.show_recurrent || !e.parentId)
2021-04-26 23:18:50 +02:00
}
2021-04-14 01:35:18 +02:00
}
},
2022-11-24 17:30:01 +01:00
created () {
this.$root.$on('dayclick', this.dayChange)
this.$root.$on('monthchange', this.monthChange)
this.$root.$on('search', debounce(this.search, 100))
},
destroyed () {
this.$root.$off('dayclick')
this.$root.$off('monthchange')
this.$root.$off('search')
},
methods: {
2022-11-24 17:30:01 +01:00
...mapActions(['getEvents']),
async search (query) {
if (query) {
this.tmpEvents = await this.$axios.$get(`/event/search?search=${query}`)
this.searching = true
} else {
this.tmpEvents = null
this.searching = false
}
2021-06-07 00:00:57 +02:00
},
2021-01-22 23:08:38 +01:00
updateEvents () {
2022-11-24 17:30:01 +01:00
return this.getEvents({
start: this.start,
end: this.end,
2021-04-26 23:18:50 +02:00
show_recurrent: true
})
},
2022-11-24 17:30:01 +01:00
async monthChange ({ year, month }) {
2021-04-26 23:18:50 +02:00
2021-03-05 14:20:23 +01:00
this.$nuxt.$loading.start()
2022-11-24 17:30:01 +01:00
this.$nextTick( async () => {
2021-04-26 23:18:50 +02:00
2022-11-24 17:30:01 +01:00
// unselect current selected day
this.selectedDay = null
// check if current month is selected
if (month - 1 === dayjs.tz().month() && year === dayjs.tz().year()) {
this.isCurrentMonth = true
this.start = dayjs().startOf('month').unix()
this.date = dayjs.tz().format('YYYY-MM-DD')
} else {
this.isCurrentMonth = false
this.date = ''
this.start = dayjs().year(year).month(month - 1).startOf('month').unix() // .startOf('week').unix()
}
this.end = dayjs().year(year).month(month).endOf('month').unix() // .endOf('week').unix()
await this.updateEvents()
this.$nuxt.$loading.finish()
})
},
dayChange (day) {
this.selectedDay = day ? dayjs.tz(day).format('YYYY-MM-DD') : null
}
2020-01-15 23:47:17 +01:00
}
2019-05-30 12:04:14 +02:00
}
2022-11-24 17:30:01 +01:00
</script>