start refactoring

This commit is contained in:
Julie Lenaerts 2022-05-06 17:38:08 +02:00
parent 5a1a33b6a4
commit cebdfdaa30
2 changed files with 24 additions and 8 deletions

View File

@ -203,7 +203,6 @@ export default {
}, },
methods: { methods: {
init() { init() {
console.log('init')
this.fetchData(); this.fetchData();
}, },
openModal() { openModal() {
@ -282,7 +281,7 @@ export default {
if (this.showMyCalendar) { if (this.showMyCalendar) {
this.calendarOptions.eventSources.push(this.calendarEvents.userCalendar); this.calendarOptions.eventSources.push(this.calendarEvents.userCalendar);
} }
// console.log(this.calendarOptions.eventSources); console.log('eventSources', this.calendarOptions.eventSources);
}, },
toggleMyCalendar(value) { toggleMyCalendar(value) {
this.showMyCalendar = value; this.showMyCalendar = value;
@ -450,7 +449,7 @@ export default {
color: "#3788d8" color: "#3788d8"
}; };
// console.log(copiedEvents); // console.log(copiedEvents);
// Add to the calendar // Add to the calendar
let newEvents = this.calendarEvents.new.events; let newEvents = this.calendarEvents.new.events;
newEvents.push(...copiedEvents.events); newEvents.push(...copiedEvents.events);
@ -459,7 +458,7 @@ export default {
color: "#3788d8" color: "#3788d8"
}; };
this.updateEventsSource(); this.updateEventsSource();
// Set the last new date // Set the last new date
this.lastNewDate = new Date(copiedEvents.events[copiedEvents.events.length - 1].start); this.lastNewDate = new Date(copiedEvents.events[copiedEvents.events.length - 1].start);

View File

@ -1,17 +1,21 @@
import 'es6-promise/auto'; import 'es6-promise/auto';
import { createStore } from 'vuex'; import { createStore } from 'vuex';
import { postCalendarRange, patchCalendarRange, deleteCalendarRange } from '../_api/api'; import { deleteCalendarRange, fetchCalendar, fetchCalendarRangesByUser, patchCalendarRange, postCalendarRange } from '../_api/api';
const debug = process.env.NODE_ENV !== 'production'; const debug = process.env.NODE_ENV !== 'production';
const store = createStore({ const store = createStore({
strict: debug, strict: debug,
state: { state: {
newCalendarRanges: [], newCalendarRanges: [],
updateCalendarRanges: [], updateCalendarRanges: [],
deleteCalendarRanges: [] deleteCalendarRanges: [],
userRanges: [],
}, },
mutations: { mutations: {
setUserRanges(state, payload) {
state.userRanges = payload
},
updateRange(state, payload) { updateRange(state, payload) {
state.updateCalendarRanges.push({ state.updateCalendarRanges.push({
id: payload.event.extendedProps.calendarRangeId, id: payload.event.extendedProps.calendarRangeId,
@ -53,8 +57,19 @@ const store = createStore({
) )
state.deleteCalendarRanges = filteredCollection; state.deleteCalendarRanges = filteredCollection;
}, },
addUserRange(state, payload) {
state.userRanges.push(payload);
}
}, },
actions: { actions: {
setUserRanges({ commit }) {
console.log('userId', window.userId);
fetchCalendarRangesByUser(window.userId)
.then((ranges) => {
console.log('ranges', ranges.results);
commit('setUserRanges', ranges.results);
})
},
createRange({ commit }, payload) { createRange({ commit }, payload) {
// console.log('### action createRange', payload); // console.log('### action createRange', payload);
commit('addRange', payload); commit('addRange', payload);
@ -85,5 +100,7 @@ const store = createStore({
} }
}); });
store.dispatch('setUserRanges');
export default store; export default store;