|
@@ -1,3 +1,5 @@
|
|
|
+import Vue from 'vue'
|
|
|
+
|
|
|
function separateBlogs(blogs) {
|
|
|
const published = []
|
|
|
const drafts = []
|
|
@@ -66,15 +68,24 @@ export const actions = {
|
|
|
commit('deleteBlog', {resource, index})
|
|
|
return true
|
|
|
},
|
|
|
- updatePublishedBlog(blog) {
|
|
|
- alert('FEATURING BLOG')
|
|
|
+
|
|
|
+ async updatePublishedBlog({commit, state}, {id, data}) {
|
|
|
+ const blog = await this.$axios.$patch(`/api/v1/blogs/${id}`, data)
|
|
|
+ if(blog.isAxiosError === true){
|
|
|
+ console.log(blog.data)
|
|
|
+ return Error('')
|
|
|
+ }
|
|
|
+ const index = state.items['published'].findIndex(b => b._id === id)
|
|
|
+ commit('setPublishedBlog', {index, blog})
|
|
|
+ return blog
|
|
|
},
|
|
|
+
|
|
|
async updateBlog({commit, state}, {data, id}) {
|
|
|
console.log('instructor/blog.js actions updateBlog call axios.$patch-> Id, data')
|
|
|
const blog = await this.$axios.$patch(`/api/v1/blogs/${id}`, data)
|
|
|
if(blog.isAxiosError === true){
|
|
|
console.log(blog.data)
|
|
|
- return Error('')
|
|
|
+ return blog
|
|
|
}
|
|
|
console.log('instructor/blog.js actions updateBlog done axios.$patch-> Id, data')
|
|
|
console.log('courses.js mutations call setBlog')
|
|
@@ -88,6 +99,12 @@ export const mutations = {
|
|
|
setBlog(state, blog) {
|
|
|
state.item = blog
|
|
|
},
|
|
|
+ setPublishedBlog(state, {index, blog}) {
|
|
|
+ // Vue는 배열에 대해 다음과 같은 변경 사항을 감지할 수 없습니다.
|
|
|
+ // 인덱스로 배열에 있는 항목을 직접 설정하는 경우, 예: vm.items[indexOfItem] = newValue
|
|
|
+ // 배열 길이를 수정하는 경우, 예: vm.items.length = newLength
|
|
|
+ Vue.set(state.items.published, index, blog)
|
|
|
+ },
|
|
|
setBlogs(state, {resource, items}) {
|
|
|
state.items[resource] = items
|
|
|
},
|