gancio-upstream/store/index.js

91 lines
2.6 KiB
JavaScript
Raw Normal View History

2022-11-24 17:29:48 +01:00
import dayjs from 'dayjs'
2019-04-03 00:25:12 +02:00
export const state = () => ({
2019-07-13 01:02:11 +02:00
settings: {
2019-10-20 14:22:55 +02:00
instance_timezone: 'Europe/Rome',
instance_name: '',
2019-07-13 01:02:11 +02:00
allow_registration: true,
allow_anon_event: true,
allow_multidate_event: true,
2019-07-13 01:02:11 +02:00
allow_recurrent_event: true,
recurrent_event_visible: false,
allow_geolocation: false,
geocoding_provider_type: '',
geocoding_provider: '',
geocoding_countrycodes: [],
tilelayer_provider: '',
tilelayer_provider_attribution: '',
enable_federation: false,
enable_resources: false,
2020-03-18 10:11:24 +01:00
hide_boosts: true,
enable_trusted_instances: true,
2021-11-09 12:47:26 +01:00
trusted_instances: [],
trusted_instances_label: '',
2021-11-09 12:47:26 +01:00
footerLinks: []
2019-07-13 01:02:11 +02:00
},
filter: {
query: '',
show_recurrent: null,
2023-01-12 11:14:34 +01:00
show_multidate: null,
},
2022-11-24 17:29:48 +01:00
announcements: [],
events: []
2019-04-03 00:25:12 +02:00
})
export const mutations = {
2019-09-11 19:12:24 +02:00
setSettings (state, settings) {
2019-06-06 23:54:32 +02:00
state.settings = settings
},
2019-09-11 19:12:24 +02:00
setSetting (state, setting) {
state.settings[setting.key] = setting.value
},
setAnnouncements (state, announcements) {
state.announcements = announcements
2022-11-24 17:29:48 +01:00
},
setEvents (state, events) {
2023-01-12 11:14:34 +01:00
state.events = Object.freeze(events)
},
setFilter (state, { type, value }) {
state.filter[type] = value
2019-04-03 00:25:12 +02:00
}
}
export const actions = {
2020-01-15 23:51:09 +01:00
// this method is called server side only for each request for nuxt
// we use it to get configuration from db, set locale, etc...
nuxtServerInit ({ commit }, { _req, res }) {
2023-01-12 14:40:14 +01:00
if (res.locals && res.locals.settings) {
commit('setSettings', res.locals.settings)
}
commit('setFilter', { type: 'show_recurrent',
value: res.locals.settings.allow_recurrent_event && res.locals.settings.recurrent_event_visible })
2022-02-26 21:27:40 +01:00
if (res.locals.status === 'READY') {
commit('setAnnouncements', res.locals.announcements)
}
2019-04-26 23:14:43 +02:00
},
async updateAnnouncements ({ commit }) {
const announcements = await this.$axios.$get('/announcements')
commit('setAnnouncements', announcements)
},
setAnnouncements ({ commit }, announcements) {
commit('setAnnouncements', announcements)
},
2019-09-11 19:12:24 +02:00
async setSetting ({ commit }, setting) {
await this.$axios.$post('/settings', setting)
commit('setSetting', setting)
2022-11-24 17:29:48 +01:00
},
setFilter ({ commit }, [type, value]) {
commit('setFilter', { type, value })
},
2022-11-25 09:47:57 +01:00
async getEvents ({ commit, state }, params = {}) {
2022-11-24 17:29:48 +01:00
const events = await this.$api.getEvents({
start: params.start || dayjs().startOf('month').unix(),
end: params.end || null,
show_recurrent: state.filter.show_recurrent,
show_multidate: state.filter.show_multidate
2022-11-24 17:29:48 +01:00
})
commit('setEvents', events)
2019-09-11 19:12:24 +02:00
}
2019-04-03 00:25:12 +02:00
}