Browse Source

Adding post updates 'reply' bubbles

sbkwgh 8 năm trước cách đây
mục cha
commit
0d9aad9a09
1 tập tin đã thay đổi với 17 bổ sung0 xóa
  1. 17 0
      src/store/modules/thread.js

+ 17 - 0
src/store/modules/thread.js

@@ -36,6 +36,7 @@ const actions = {
 			.post('/api/v1/post', post)
 			.then(res => {
 				commit('addPost', res.data);
+				commit('addReplyBubble', res.data)
 				commit('setThreadEditorValue', '');
 				commit('setThreadEditorState', false);
 				commit({
@@ -56,6 +57,22 @@ const mutations = {
 	addPost (state, post) {
 		state.posts.push(post);
 	},
+	addReplyBubble (state, post) {
+		let repliedToPost = {}, index
+
+		if(post.replyId) {
+			state.posts.forEach((p, i) => {
+				if(p.id === post.replyId) {
+					index = i
+					repliedToPost = p
+				}
+			})
+
+			repliedToPost.Replies.push(post)
+
+			state.posts.splice(index, 1, repliedToPost)
+		}
+	},
 	setThreadEditorValue (state, value) {
 		state.editor.value = value
 	},