flatisfy/flatisfy/web/js_src/store/mutations.js
Phyks (Lucas Verney) 0e3d1576b2
Use stars to note flats
Instead of a binary "followed" / "not followed" status, use 5 stars to
allow users to give a note to a flat between 0 (not followed) and 5. Any
note different from zero add a "followed" status.

Closes issue #36.
2017-05-03 22:14:51 +02:00

57 lines
1.7 KiB
JavaScript

import Vue from 'vue'
import * as types from './mutations-types'
export const state = {
flats: [],
timeToPlaces: [],
loading: false
}
export const mutations = {
[types.REPLACE_FLATS] (state, { flats }) {
state.loading = false
state.flats = flats
},
[types.MERGE_FLATS] (state, { flats }) {
state.loading = false
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)
}
})
},
[types.UPDATE_FLAT_STATUS] (state, { flatId, newStatus }) {
state.loading = false
const index = state.flats.findIndex(flat => flat.id === flatId)
if (index > -1) {
Vue.set(state.flats[index], 'status', newStatus)
}
},
[types.UPDATE_FLAT_NOTES] (state, { flatId, newNotes }) {
state.loading = false
const index = state.flats.findIndex(flat => flat.id === flatId)
if (index > -1) {
Vue.set(state.flats[index], 'notes', newNotes)
}
},
[types.UPDATE_FLAT_NOTATION] (state, { flatId, newNotation }) {
state.loading = false
const index = state.flats.findIndex(flat => flat.id === flatId)
if (index > -1) {
Vue.set(state.flats[index], 'notation', newNotation)
}
},
[types.RECEIVE_TIME_TO_PLACES] (state, { timeToPlaces }) {
state.loading = false
state.timeToPlaces = timeToPlaces
},
[types.IS_LOADING] (state) {
state.loading = true
}
}