From ab6058abe611672d4e10793a7a8b6bfa6b98e444 Mon Sep 17 00:00:00 2001 From: Amanuel Alemayehu Date: Wed, 3 Aug 2022 05:58:29 -0800 Subject: [PATCH 1/2] created basic ui --- .../components/amanz/AddBlog.vue | 96 +++++++++++++++++++ .../components/amanz/AmanzBlog.vue | 54 +++++++++++ starter-project-web-vue2/pages/amanz/_id.vue | 46 +++++++++ .../pages/amanz/index.vue | 61 ++++++++++++ 4 files changed, 257 insertions(+) create mode 100644 starter-project-web-vue2/components/amanz/AddBlog.vue create mode 100644 starter-project-web-vue2/components/amanz/AmanzBlog.vue create mode 100644 starter-project-web-vue2/pages/amanz/_id.vue create mode 100644 starter-project-web-vue2/pages/amanz/index.vue diff --git a/starter-project-web-vue2/components/amanz/AddBlog.vue b/starter-project-web-vue2/components/amanz/AddBlog.vue new file mode 100644 index 00000000..778cdffc --- /dev/null +++ b/starter-project-web-vue2/components/amanz/AddBlog.vue @@ -0,0 +1,96 @@ + + + diff --git a/starter-project-web-vue2/components/amanz/AmanzBlog.vue b/starter-project-web-vue2/components/amanz/AmanzBlog.vue new file mode 100644 index 00000000..85c26582 --- /dev/null +++ b/starter-project-web-vue2/components/amanz/AmanzBlog.vue @@ -0,0 +1,54 @@ + + + diff --git a/starter-project-web-vue2/pages/amanz/_id.vue b/starter-project-web-vue2/pages/amanz/_id.vue new file mode 100644 index 00000000..d1d9916d --- /dev/null +++ b/starter-project-web-vue2/pages/amanz/_id.vue @@ -0,0 +1,46 @@ + + + diff --git a/starter-project-web-vue2/pages/amanz/index.vue b/starter-project-web-vue2/pages/amanz/index.vue new file mode 100644 index 00000000..40ccb158 --- /dev/null +++ b/starter-project-web-vue2/pages/amanz/index.vue @@ -0,0 +1,61 @@ + + + From 0ea3264460495dc198e3a09c337a3270e5eaacbd Mon Sep 17 00:00:00 2001 From: Amanuel Alemayehu Date: Fri, 5 Aug 2022 03:57:34 -0800 Subject: [PATCH 2/2] ui with state and some fuctions completed --- .../components/amanz/AddBlog.vue | 39 ++++++++-- .../components/amanz/AmanzBlog.vue | 26 +++++-- .../components/amanz/EditBlog.vue | 75 +++++++++++++++++++ starter-project-web-vue2/pages/amanz/_id.vue | 71 ++++++++++-------- .../pages/amanz/index.vue | 57 ++++---------- starter-project-web-vue2/pages/index.vue | 11 ++- starter-project-web-vue2/store/amanz.js | 72 ++++++++++++++++++ 7 files changed, 257 insertions(+), 94 deletions(-) create mode 100644 starter-project-web-vue2/components/amanz/EditBlog.vue create mode 100644 starter-project-web-vue2/store/amanz.js diff --git a/starter-project-web-vue2/components/amanz/AddBlog.vue b/starter-project-web-vue2/components/amanz/AddBlog.vue index 778cdffc..24f28e13 100644 --- a/starter-project-web-vue2/components/amanz/AddBlog.vue +++ b/starter-project-web-vue2/components/amanz/AddBlog.vue @@ -38,10 +38,18 @@ > --> - + - + - * indicates required field*indicates required field - Close - - - Save + Cancel + Add @@ -88,9 +94,26 @@ diff --git a/starter-project-web-vue2/components/amanz/AmanzBlog.vue b/starter-project-web-vue2/components/amanz/AmanzBlog.vue index 85c26582..051020c2 100644 --- a/starter-project-web-vue2/components/amanz/AmanzBlog.vue +++ b/starter-project-web-vue2/components/amanz/AmanzBlog.vue @@ -13,7 +13,7 @@ :to="`/amanz/${blog._id} `" > - {{ blog.title }} {{ blog._id }} + {{ blog.title }} {{ blog.content @@ -22,12 +22,10 @@ - - mdi-pencil - + - + mdi-delete @@ -42,13 +40,31 @@ diff --git a/starter-project-web-vue2/components/amanz/EditBlog.vue b/starter-project-web-vue2/components/amanz/EditBlog.vue new file mode 100644 index 00000000..3a7663e9 --- /dev/null +++ b/starter-project-web-vue2/components/amanz/EditBlog.vue @@ -0,0 +1,75 @@ + + + diff --git a/starter-project-web-vue2/pages/amanz/_id.vue b/starter-project-web-vue2/pages/amanz/_id.vue index d1d9916d..fe9e14d7 100644 --- a/starter-project-web-vue2/pages/amanz/_id.vue +++ b/starter-project-web-vue2/pages/amanz/_id.vue @@ -1,43 +1,48 @@ diff --git a/starter-project-web-vue2/pages/index.vue b/starter-project-web-vue2/pages/index.vue index 95c1f831..b766fc44 100644 --- a/starter-project-web-vue2/pages/index.vue +++ b/starter-project-web-vue2/pages/index.vue @@ -41,7 +41,6 @@ export default { name: 'Amsale Gebrehana', description: 'A2SV G31', link: '/amsale', - }, { name: 'Ruth Getachew', @@ -49,10 +48,14 @@ export default { link: '/ruth', }, { - name: "Keiredin Aman", + name: 'Keiredin Aman', description: 'Summer Intern', - link: - '/keiredin', + link: '/keiredin', + }, + { + name: 'Amanuel Alemayehu', + description: 'Web Team Member', + link: '/amanz', }, ], } diff --git a/starter-project-web-vue2/store/amanz.js b/starter-project-web-vue2/store/amanz.js new file mode 100644 index 00000000..73f42ac7 --- /dev/null +++ b/starter-project-web-vue2/store/amanz.js @@ -0,0 +1,72 @@ +// eslint-disable-next-line no-unused-vars +import axios from 'axios' + +const state = { + blogs: [], + blog: {}, +} + +const getters = { + allBlogs: (state) => state.blogs, +} + +const actions = { + // eslint-disable-next-line no-unused-vars + async fetchBlogs({ commit }) { + const response = await axios.get( + 'https://blog-app-backend.onrender.com/api/articles/all' + ) + commit('setBlogs', response.data) + }, + + async fetchBlogsById({ commit }, id) { + const response = await axios.get( + `https://blog-app-backend.onrender.com/api/articles/${id}` + ) + commit('setBlog', response.data) + }, + + async addBlog({ commit }, newBlog) { + const response = await this.$axios.post( + 'https://blog-app-backend.onrender.com/api/articles', + newBlog + ) + commit('newBlog', response.data) + }, + + async deleteBlog({ commit }, id) { + await this.$axios.delete( + `https://blog-app-backend.onrender.com/api/articles/${id}` + ) + + commit('removeBlog', id) + }, + + async updateBlog({ commit }, updated) { + const response = await this.$axios.put( + `https://blog-app-backend.onrender.com/api/articles/${updated.id}`, + updated + ) + commit('updateBlog', response.data) + }, +} + +const mutations = { + setBlogs: (state, blogs) => (state.blogs = blogs), + newBlog: (state, blog) => state.blogs.unshift(blog), + setBlog: (state, blog) => (state.blog = blog), + // newBlog: (state, blog) => state.blogs.unshift(blog), + removeBlog: (state, id) => + (state.blogs = state.blogs.filter((blogg) => blogg._id !== id)), + // updateBlog: (state, blog) => { + // const index = state.blogs.findIndex((blogg) => blogg._id === blog._id) + + // } +} + +export default { + state, + getters, + actions, + mutations, +}