Update..
This commit is contained in:
+17
-5
@@ -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
|
||||
},
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user