From a4cf1946727ba38c678bc79b20aeee135de44287 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Kucharczyk?= Date: Wed, 9 Sep 2020 18:15:54 +0200 Subject: [PATCH] Implement actually adding notes to the db. --- src/components/NoteList.vue | 5 +---- src/services/NoteService.js | 3 +++ src/store/index.js | 8 +++++++- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/components/NoteList.vue b/src/components/NoteList.vue index c3f654b..4f54ecc 100644 --- a/src/components/NoteList.vue +++ b/src/components/NoteList.vue @@ -30,10 +30,7 @@ export default { }, methods: { addNote() { - this.$store.commit('ADD_NOTE', { - id: this.notes.length, - text: this.content - }) + this.$store.commit('ADD_NOTE', this.content) this.content = '' } }, diff --git a/src/services/NoteService.js b/src/services/NoteService.js index 94cd171..cfc81c8 100644 --- a/src/services/NoteService.js +++ b/src/services/NoteService.js @@ -12,5 +12,8 @@ const apiClient = axios.create({ export default { getNotes() { return apiClient.get('/notes') + }, + addNote(text) { + return apiClient.post('/notes', JSON.stringify({ text })) } } diff --git a/src/store/index.js b/src/store/index.js index 08476b3..7cb81ad 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -18,7 +18,13 @@ export default createStore({ }) }, ADD_NOTE(state, note) { - state.notes.push(note) + NoteService.addNote(note) + .then(() => { + this.commit('FETCH_NOTES') + }) + .catch(error => { + console.error(error) + }) } }, actions: {}