Commit f22f75b7 authored by Fatih Acet's avatar Fatih Acet

Fix rendering double note issue.

parent 92173ac5
...@@ -97,6 +97,8 @@ ...@@ -97,6 +97,8 @@
methods: { methods: {
...mapActions([ ...mapActions([
'saveNote', 'saveNote',
'stopPolling',
'restartPolling',
'removePlaceholderNotes', 'removePlaceholderNotes',
]), ]),
setIsSubmitButtonDisabled(note, isSubmitting) { setIsSubmitButtonDisabled(note, isSubmitting) {
...@@ -126,10 +128,13 @@ ...@@ -126,10 +128,13 @@
this.isSubmitting = true; this.isSubmitting = true;
this.note = ''; // Empty textarea while being requested. Repopulate in catch this.note = ''; // Empty textarea while being requested. Repopulate in catch
this.resizeTextarea(); this.resizeTextarea();
this.stopPolling();
this.saveNote(noteData) this.saveNote(noteData)
.then((res) => { .then((res) => {
this.isSubmitting = false; this.isSubmitting = false;
this.restartPolling();
if (res.errors) { if (res.errors) {
if (res.errors.commands_only) { if (res.errors.commands_only) {
this.discard(); this.discard();
......
...@@ -187,6 +187,14 @@ export const poll = ({ commit, state, getters }) => { ...@@ -187,6 +187,14 @@ export const poll = ({ commit, state, getters }) => {
}); });
}; };
export const stopPolling = () => {
eTagPoll.stop();
};
export const restartPolling = () => {
eTagPoll.restart();
};
export const fetchData = ({ commit, state, getters }) => { export const fetchData = ({ commit, state, getters }) => {
const requestData = { endpoint: state.notesData.notesPath, lastFetchedAt: state.lastFetchedAt }; const requestData = { endpoint: state.notesData.notesPath, lastFetchedAt: state.lastFetchedAt };
......
...@@ -5,15 +5,19 @@ import * as constants from '../constants'; ...@@ -5,15 +5,19 @@ import * as constants from '../constants';
export default { export default {
[types.ADD_NEW_NOTE](state, note) { [types.ADD_NEW_NOTE](state, note) {
const { discussion_id, type } = note; const { discussion_id, type } = note;
const noteData = { const [exists] = state.notes.filter(n => n.id === note.discussion_id);
expanded: true,
id: discussion_id, if (!exists) {
individual_note: !(type === constants.DISCUSSION_NOTE), const noteData = {
notes: [note], expanded: true,
reply_id: discussion_id, id: discussion_id,
}; individual_note: !(type === constants.DISCUSSION_NOTE),
notes: [note],
state.notes.push(noteData); reply_id: discussion_id,
};
state.notes.push(noteData);
}
}, },
[types.ADD_NEW_REPLY_TO_DISCUSSION](state, note) { [types.ADD_NEW_REPLY_TO_DISCUSSION](state, note) {
......
import * as actions from '~/notes/stores/actions'; import * as actions from '~/notes/stores/actions';
import testAction from './helpers'; import testAction from './helpers';
import { discussionMock, notesDataMock, userDataMock, issueDataMock, individualNote } from '../mock_data'; import { discussionMock, notesDataMock, userDataMock, issueDataMock, individualNote } from '../mock_data';
......
...@@ -3,19 +3,31 @@ import { note, discussionMock, notesDataMock, userDataMock, issueDataMock, indiv ...@@ -3,19 +3,31 @@ import { note, discussionMock, notesDataMock, userDataMock, issueDataMock, indiv
describe('Mutation Notes Store', () => { describe('Mutation Notes Store', () => {
describe('ADD_NEW_NOTE', () => { describe('ADD_NEW_NOTE', () => {
it('should add a new note to an array of notes', () => { let state;
const state = { notes: [] }; let noteData;
beforeEach(() => {
state = { notes: [] };
noteData = {
expanded: true,
id: note.discussion_id,
individual_note: true,
notes: [note],
reply_id: note.discussion_id,
};
mutations.ADD_NEW_NOTE(state, note); mutations.ADD_NEW_NOTE(state, note);
});
it('should add a new note to an array of notes', () => {
expect(state).toEqual({ expect(state).toEqual({
notes: [{ notes: [noteData],
expanded: true,
id: note.discussion_id,
individual_note: true,
notes: [note],
reply_id: note.discussion_id,
}],
}); });
expect(state.notes.length).toBe(1);
});
it('should not add the same note to the notes array', () => {
mutations.ADD_NEW_NOTE(state, note);
expect(state.notes.length).toBe(1);
}); });
}); });
......
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