export const state = () => ({ notes: [], }) export const mutations = { set(state, notes) { state.notes = notes }, add(state, note) { state.notes.unshift(note) }, delete(state, uuid) { state.notes = state.notes.filter((e) => e.uuid !== uuid) }, // used when logging out clear(state) { state.notes = [] }, } export const actions = { async load({ commit }) { await new Promise((resolve) => setTimeout(resolve, 600)) this.$axios.get('/notes').then(({ data }) => commit('set', data)) }, // FIXME: make the api send the new date back create({ commit }, note) { this.$axios.post('/notes', note).then(({ data }) => commit('add', { updatedAt: new Date().toISOString(), uuid: data.uuid, ...note, }) ) }, delete({ commit }, note) { const result = this.$axios.delete(`/notes/${note.uuid}`) commit('delete', note.uuid) result.catch(() => commit('add', note)) }, } export const getters = {}