2017-04-13 23:24:31 +02:00
|
|
|
import Vue from 'vue'
|
|
|
|
|
|
|
|
import * as types from './mutations-types'
|
|
|
|
|
|
|
|
export const state = {
|
|
|
|
flats: [],
|
2017-05-02 18:35:34 +02:00
|
|
|
timeToPlaces: [],
|
2019-01-13 20:22:57 +01:00
|
|
|
metadata: [],
|
2017-05-12 16:27:31 +02:00
|
|
|
loading: 0
|
2017-04-13 23:24:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
export const mutations = {
|
|
|
|
[types.REPLACE_FLATS] (state, { flats }) {
|
|
|
|
state.flats = flats
|
2017-05-12 16:27:31 +02:00
|
|
|
state.loading -= 1
|
2017-04-13 23:24:31 +02:00
|
|
|
},
|
|
|
|
[types.MERGE_FLATS] (state, { flats }) {
|
|
|
|
flats.forEach(flat => {
|
|
|
|
const flatIndex = state.flats.findIndex(storedFlat => storedFlat.id === flat.id)
|
|
|
|
|
|
|
|
if (flatIndex > -1) {
|
|
|
|
Vue.set(state.flats, flatIndex, flat)
|
|
|
|
} else {
|
|
|
|
state.flats.push(flat)
|
|
|
|
}
|
|
|
|
})
|
2017-05-12 16:27:31 +02:00
|
|
|
state.loading = false
|
|
|
|
state.loading -= 1
|
2017-04-13 23:24:31 +02:00
|
|
|
},
|
|
|
|
[types.UPDATE_FLAT_STATUS] (state, { flatId, newStatus }) {
|
|
|
|
const index = state.flats.findIndex(flat => flat.id === flatId)
|
|
|
|
if (index > -1) {
|
|
|
|
Vue.set(state.flats[index], 'status', newStatus)
|
|
|
|
}
|
2017-05-12 16:27:31 +02:00
|
|
|
state.loading -= 1
|
2017-04-13 23:24:31 +02:00
|
|
|
},
|
2017-05-03 19:17:19 +02:00
|
|
|
[types.UPDATE_FLAT_NOTES] (state, { flatId, newNotes }) {
|
|
|
|
const index = state.flats.findIndex(flat => flat.id === flatId)
|
|
|
|
if (index > -1) {
|
|
|
|
Vue.set(state.flats[index], 'notes', newNotes)
|
|
|
|
}
|
2017-05-12 16:27:31 +02:00
|
|
|
state.loading -= 1
|
2017-05-03 19:17:19 +02:00
|
|
|
},
|
2017-05-03 22:10:24 +02:00
|
|
|
[types.UPDATE_FLAT_NOTATION] (state, { flatId, newNotation }) {
|
|
|
|
const index = state.flats.findIndex(flat => flat.id === flatId)
|
|
|
|
if (index > -1) {
|
|
|
|
Vue.set(state.flats[index], 'notation', newNotation)
|
|
|
|
}
|
2017-05-12 16:27:31 +02:00
|
|
|
state.loading -= 1
|
2017-05-03 22:10:24 +02:00
|
|
|
},
|
2017-11-09 17:33:39 +01:00
|
|
|
[types.UPDATE_FLAT_VISIT_DATE] (state, { flatId, newVisitDate }) {
|
|
|
|
const index = state.flats.findIndex(flat => flat.id === flatId)
|
|
|
|
if (index > -1) {
|
|
|
|
Vue.set(state.flats[index], 'visit-date', newVisitDate)
|
|
|
|
}
|
|
|
|
state.loading -= 1
|
|
|
|
},
|
2017-04-13 23:24:31 +02:00
|
|
|
[types.RECEIVE_TIME_TO_PLACES] (state, { timeToPlaces }) {
|
|
|
|
state.timeToPlaces = timeToPlaces
|
2017-05-12 16:27:31 +02:00
|
|
|
state.loading -= 1
|
2017-05-02 18:35:34 +02:00
|
|
|
},
|
2019-01-13 20:22:57 +01:00
|
|
|
[types.RECEIVE_METADATA] (state, { metadata }) {
|
|
|
|
state.metadata = metadata
|
|
|
|
state.loading -= 1
|
|
|
|
},
|
2017-05-02 18:35:34 +02:00
|
|
|
[types.IS_LOADING] (state) {
|
2017-05-12 16:27:31 +02:00
|
|
|
state.loading += 1
|
2017-04-13 23:24:31 +02:00
|
|
|
}
|
|
|
|
}
|