This commit is contained in:
2020-06-25 15:41:03 +02:00
parent 071ce40ac6
commit 67915246ba
7 changed files with 60 additions and 34 deletions
+17 -5
View File
@@ -1,8 +1,12 @@
export const state = () => ({
notes: [],
isInitialized: false,
})
export const mutations = {
setInitialized(state) {
state.isInitialized = true
},
set(state, notes) {
state.notes = notes
},
@@ -15,21 +19,25 @@ export const mutations = {
// used when logging out
clear(state) {
state.notes = []
state.initialized = false
},
}
export const actions = {
async load({ commit }) {
await new Promise((resolve) => setTimeout(resolve, 600))
this.$axios.get('/notes').then(({ data }) => commit('set', data))
this.$axios.get('/notes').then(({ data }) => {
commit('set', data)
commit('setInitialized')
})
},
// 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,
title: data.title,
updatedAt: data.updatedAt,
tags: data.tags,
})
)
},
@@ -40,4 +48,8 @@ export const actions = {
},
}
export const getters = {}
export const getters = {
isEmpty(state) {
return state.isInitialized && state.notes.length === 0
},
}