|
@@ -1,4 +1,19 @@
|
|
|
+function separateBlogs(blogs) {
|
|
|
+ const published = []
|
|
|
+ const drafts = []
|
|
|
+
|
|
|
+ blogs.forEach(blog => {
|
|
|
+ blog.status === 'active' ? drafts.push(blog) : published.push(blog)
|
|
|
+ })
|
|
|
+
|
|
|
+ return {published, drafts}
|
|
|
+}
|
|
|
+
|
|
|
export const state = () => ({
|
|
|
+ items: {
|
|
|
+ drafts: [],
|
|
|
+ published: []
|
|
|
+ },
|
|
|
item: {},
|
|
|
isSaving: false
|
|
|
})
|
|
@@ -29,6 +44,18 @@ export const actions = {
|
|
|
commit('setBlog', blog)
|
|
|
console.log('courses.js mutations done setBlog')
|
|
|
},
|
|
|
+ async fetchUserBlogs({commit, state}) {
|
|
|
+ const blogs = await this.$axios.$get('/api/v1/blogs/me')
|
|
|
+ debugger;
|
|
|
+ if(blogs.isAxiosError === true){
|
|
|
+ console.log(blog.data)
|
|
|
+ return Error('')
|
|
|
+ }
|
|
|
+ const { published, drafts } = separateBlogs(blogs)
|
|
|
+ commit('setBlogs', {resource: 'drafts', items: drafts})
|
|
|
+ commit('setBlogs', {resource: 'published', items: published})
|
|
|
+ return { published, drafts }
|
|
|
+ },
|
|
|
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)
|
|
@@ -48,6 +75,9 @@ export const mutations = {
|
|
|
setBlog(state, blog) {
|
|
|
state.item = blog
|
|
|
},
|
|
|
+ setBlogs(state, {resource, items}) {
|
|
|
+ state.items[resource] = items
|
|
|
+ },
|
|
|
setIsSaving(state, isSaving) {
|
|
|
state.isSaving = isSaving
|
|
|
}
|