Skip to content

Commit

Permalink
done with update
Browse files Browse the repository at this point in the history
  • Loading branch information
AmsaleG committed Aug 8, 2022
1 parent c39d28c commit 8a1f4d4
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
10 changes: 7 additions & 3 deletions starter-project-web-vue2/components/amsale/AmsaleBlogList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<v-spacer></v-spacer>
<v-col align="end">
<v-btn
v-if="$auth.loggedIn"
v-if="$auth.loggedIn && isAuthor(blog)"
class="ma-2"
outlined
small
Expand Down Expand Up @@ -76,11 +76,15 @@ export default {
dialog: false,
}
},
methods: {
...mapActions('amsale', ['fetchBlogs', 'deleteBlog']),
isAuthor(blog) {
return blog.authorUserId._id === this.$auth.user._id
},
},
computed: {
...mapState('amsale', ['blogs']),
},
computed: { ...mapState('amsale', ['blogs']) },
components: { AmsaleAddBlogVue },
created() {
this.fetchBlogs()
Expand Down
11 changes: 8 additions & 3 deletions starter-project-web-vue2/components/amsale/AmsaleEditBlog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<div class="mt-5 mb-5 mr-4">
<v-row align="end" justify="space-around">
<v-spacer></v-spacer>
<v-btn tile color="success" @click="show = !show">
<v-btn v-if="isAuthor" tile color="success" @click="show = !show">
<v-icon left> mdi-pencil </v-icon>
Edit
</v-btn>
Expand Down Expand Up @@ -55,6 +55,13 @@ export default {
show: false,
updatedBlog: {},
}),
computed: {
isAuthor() {
return this.$auth.loggedIn && this.blog.authorUserId
? this.blog.authorUserId._id === this.$auth.user._id
: 'loading'
},
},
created() {
this.updatedBlog.title = this.blog.title
Expand All @@ -63,9 +70,7 @@ export default {
methods: {
...mapActions('amsale', ['editBlog']),
onSave() {
console.log('from frontend', this.blog, this.$auth.user)
this.editBlog({ blog: this.updatedBlog, id: this.blog._id })
// this.$nuxt.refresh()
this.snackbar = true
window.location.reload()
this.show = false
Expand Down
2 changes: 0 additions & 2 deletions starter-project-web-vue2/store/amsale.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ const actions = {
commit('setBlogs', response.data)
},
async deleteBlog({ commit }, id) {
console.log('deleted id', id)
await this.$axios.delete(`articles/${id}`)
commit('deletedBlog', id)
window.location.reload()
Expand All @@ -17,7 +16,6 @@ const actions = {
commit('newBlog', response.data)
},
async editBlog({ commit }, { blog, id }) {
console.log(blog, id)
const response = await this.$axios.patch(`articles/${id}`, blog)
commit('editBlog', response.data)
},
Expand Down

0 comments on commit 8a1f4d4

Please sign in to comment.