Commit e5b7fa6b authored by Tim Zallmann's avatar Tim Zallmann

This updates only the actual new discussion and not the full tree , which...

This updates only the actual new discussion and not the full tree , which leads to a very costly full rerender
parent 53760e8d
...@@ -59,7 +59,7 @@ export default { ...@@ -59,7 +59,7 @@ export default {
} }
}, },
methods: { methods: {
...mapActions(['cancelCommentForm', 'saveNote', 'fetchDiscussions']), ...mapActions(['cancelCommentForm', 'saveNote', 'refetchDiscussionById']),
handleCancelCommentForm() { handleCancelCommentForm() {
this.autosave.reset(); this.autosave.reset();
this.cancelCommentForm({ this.cancelCommentForm({
...@@ -78,10 +78,10 @@ export default { ...@@ -78,10 +78,10 @@ export default {
}); });
this.saveNote(postData) this.saveNote(postData)
.then(() => { .then(result => {
const endpoint = this.getNotesDataByProp('discussionsPath'); const endpoint = this.getNotesDataByProp('discussionsPath');
this.fetchDiscussions(endpoint) this.refetchDiscussionById({ path: endpoint, discussionId: result.discussion_id })
.then(() => { .then(() => {
this.handleCancelCommentForm(); this.handleCancelCommentForm();
}) })
......
...@@ -41,6 +41,15 @@ export const fetchDiscussions = ({ commit }, path) => ...@@ -41,6 +41,15 @@ export const fetchDiscussions = ({ commit }, path) =>
commit(types.SET_INITIAL_DISCUSSIONS, discussions); commit(types.SET_INITIAL_DISCUSSIONS, discussions);
}); });
export const refetchDiscussionById = ({ commit }, { path, discussionId }) =>
service
.fetchDiscussions(path)
.then(res => res.json())
.then(discussions => {
const selectedDiscussion = discussions.find(discussion => discussion.id === discussionId);
if (selectedDiscussion) commit(types.UPDATE_DISCUSSION, selectedDiscussion);
});
export const deleteNote = ({ commit }, note) => export const deleteNote = ({ commit }, note) =>
service.deleteNote(note.path).then(() => { service.deleteNote(note.path).then(() => {
commit(types.DELETE_NOTE, note); commit(types.DELETE_NOTE, note);
......
...@@ -114,7 +114,6 @@ export default { ...@@ -114,7 +114,6 @@ export default {
Object.assign(state, { discussions }); Object.assign(state, { discussions });
}, },
[types.SET_LAST_FETCHED_AT](state, fetchedAt) { [types.SET_LAST_FETCHED_AT](state, fetchedAt) {
Object.assign(state, { lastFetchedAt: fetchedAt }); Object.assign(state, { lastFetchedAt: fetchedAt });
}, },
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment