diff --git a/static/js/todo_widget.js b/static/js/todo_widget.js index 697e7f3c40..1bbc8a068f 100644 --- a/static/js/todo_widget.js +++ b/static/js/todo_widget.js @@ -9,16 +9,7 @@ import * as util from "./util"; export class TaskData { task_map = new Map(); - - get_new_index() { - let idx = 0; - - for (const item of this.task_map.values()) { - idx = Math.max(idx, item.idx); - } - - return idx + 1; - } + my_idx = 1; get_widget_data() { const all_tasks = Array.from(this.task_map.values()); @@ -56,9 +47,10 @@ export class TaskData { handle = { new_task: { outbound: (task, desc) => { + this.my_idx += 1; const event = { type: "new_task", - key: this.get_new_index(), + key: this.my_idx, task, desc, completed: false, @@ -91,6 +83,11 @@ export class TaskData { if (!this.name_in_use(task)) { this.task_map.set(key, task_data); } + + // I may have added a task from another device. + if (sender_id === this.me && this.my_idx <= idx) { + this.my_idx = idx + 1; + } }, }, diff --git a/static/shared/js/poll_data.js b/static/shared/js/poll_data.js index 0e687d7e7b..baf8cfe8f3 100644 --- a/static/shared/js/poll_data.js +++ b/static/shared/js/poll_data.js @@ -108,7 +108,8 @@ export class PollData { votes, }); - if (this.my_idx <= idx) { + // I may have added a poll option from another device. + if (sender_id === this.me && this.my_idx <= idx) { this.my_idx = idx + 1; } },