gancio-upstream/store/index.js

72 lines
1.9 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 = () => ({
user_locale: {},
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_recurrent_event: true,
recurrent_event_visible: false,
allow_geolocation: false,
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: [],
footerLinks: []
2019-07-13 01:02:11 +02:00
},
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
},
2021-11-09 12:47:26 +01:00
setUserlocale (state, messages) {
state.user_locale = messages
},
setAnnouncements (state, announcements) {
state.announcements = announcements
2022-11-24 17:29:48 +01:00
},
setEvents (state, events) {
state.events = events
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 }) {
2022-02-26 21:27:40 +01:00
commit('setSettings', res.locals.settings)
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
},
async getEvents ({ commit }, params = {}) {
const events = await this.$api.getEvents({
start: params.start || dayjs().startOf('month').unix(),
end: params.end || null,
show_recurrent: params.show_recurrent
})
commit('setEvents', events)
return events
2019-09-11 19:12:24 +02:00
}
2019-04-03 00:25:12 +02:00
}