From 1144d704817e7f006e0147eec76034e20b2119b7 Mon Sep 17 00:00:00 2001 From: Jaakko Lappalainen Date: Wed, 8 Jun 2022 16:26:31 +0100 Subject: [PATCH] feat(Posts): create comments for posts --- frontend/src/components/Dashboard/Posts.vue | 4 ++-- frontend/src/store/actions/index.js | 12 ++++++++++-- frontend/src/store/index.js | 1 + frontend/src/store/mutations.js | 9 ++++++--- frontend/src/store/mutations.spec.js | 2 +- 5 files changed, 20 insertions(+), 8 deletions(-) diff --git a/frontend/src/components/Dashboard/Posts.vue b/frontend/src/components/Dashboard/Posts.vue index ac9de12..feb0dfc 100644 --- a/frontend/src/components/Dashboard/Posts.vue +++ b/frontend/src/components/Dashboard/Posts.vue @@ -33,7 +33,6 @@
post.id === parentId); + SET_PARENT_ID(state, data) { + state.parentId = data; + }, + SET_POSTS(state, results) { + if (state.parentId) { + const parent = state.posts.find((post) => post.id === state.parentId); state.posts = [parent, ...results]; } else { state.posts = results; diff --git a/frontend/src/store/mutations.spec.js b/frontend/src/store/mutations.spec.js index 1700963..1bec93b 100644 --- a/frontend/src/store/mutations.spec.js +++ b/frontend/src/store/mutations.spec.js @@ -26,7 +26,7 @@ describe('mutations', () => { // mock state const state = { posts: [] }; // apply mutation - SET_POSTS(state, { results: postsFixture }); + SET_POSTS(state, postsFixture); // assert result expect(state.posts).toEqual(postsFixture); });