Commit 53ce3876 authored by Alexander Turinske's avatar Alexander Turinske

Fix reactivity in vulnerability footer

- create getter/setter for computed discussion propert
- update using that
parent a3dcc968
...@@ -37,17 +37,22 @@ export default { ...@@ -37,17 +37,22 @@ export default {
}, },
data: () => ({ data: () => ({
discussions: [], discussionsDictionary: {},
poll: null, poll: null,
lastFetchedAt: null, lastFetchedAt: null,
}), }),
computed: { computed: {
discussionDictionary() { discussions: {
return this.discussions.reduce((acc, discussion) => { get() {
acc[discussion.id] = discussion; return Object.values(this.discussionsDictionary);
return acc; },
}, {}); set(newDiscussions) {
this.discussionsDictionary = newDiscussions.reduce((acc, discussion) => {
acc[discussion.id] = discussion;
return acc;
}, {});
},
}, },
noteDictionary() { noteDictionary() {
return this.discussions return this.discussions
...@@ -83,7 +88,11 @@ export default { ...@@ -83,7 +88,11 @@ export default {
axios axios
.get(this.discussionsUrl) .get(this.discussionsUrl)
.then(({ data, headers: { date } }) => { .then(({ data, headers: { date } }) => {
this.discussions = data; this.discussionsDictionary = data.reduce((acc, discussion) => {
acc[discussion.id] = discussion;
return acc;
}, {});
this.lastFetchedAt = this.dateToSeconds(date); this.lastFetchedAt = this.dateToSeconds(date);
if (!this.poll) this.createNotesPoll(); if (!this.poll) this.createNotesPoll();
...@@ -127,19 +136,26 @@ export default { ...@@ -127,19 +136,26 @@ export default {
notes.forEach(note => { notes.forEach(note => {
// If the note exists, update it. // If the note exists, update it.
if (this.noteDictionary[note.id]) { if (this.noteDictionary[note.id]) {
Object.assign(this.noteDictionary[note.id], note); const updatedDiscussion = this.discussionsDictionary[note.discussion_id];
const index = updatedDiscussion.notes.findIndex(curr => curr.id === note.id);
updatedDiscussion.notes.splice(index, 1, note);
this.$set(this.discussionsDictionary, note.discussion_id, updatedDiscussion);
} }
// If the note doesn't exist, but the discussion does, add the note to the discussion. // If the note doesn't exist, but the discussion does, add the note to the discussion.
else if (this.discussionDictionary[note.discussion_id]) { else if (this.discussionsDictionary[note.discussion_id]) {
this.discussionDictionary[note.discussion_id].notes.push(note); const updatedDiscussion = this.discussionsDictionary[note.discussion_id];
updatedDiscussion.notes.push(note);
this.$set(this.discussionsDictionary, note.discussion_id, updatedDiscussion);
} }
// If the discussion doesn't exist, create it. // If the discussion doesn't exist, create it.
else { else {
this.discussions.push({ const newDiscussions = [...this.discussions];
newDiscussions.push({
id: note.discussion_id, id: note.discussion_id,
reply_id: note.discussion_id, reply_id: note.discussion_id,
notes: [note], notes: [note],
}); });
this.discussions = newDiscussions;
} }
}); });
}, },
......
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