todo_widget: Fix bug where new todos sometimes replaced old todos.

Initialised `this.me` for the TaskData using a constructor to the
current user id.

The bug was caused due to `this.me` never being initialised, and hence
`idx` wasn't incremented on page reload, which resulted in duplicate
`data-key` attributes and hence new todos overwriting older todos with
the same `data-key`

Fixes: #20698
This commit is contained in:
N-Shar-ma 2022-01-22 14:00:05 +05:30 committed by Tim Abbott
parent e479acc809
commit 6d2de28bf0
1 changed files with 8 additions and 1 deletions

View File

@ -6,6 +6,7 @@ import render_widgets_todo_widget_tasks from "../templates/widgets/todo_widget_t
import * as blueslip from "./blueslip"; import * as blueslip from "./blueslip";
import {$t} from "./i18n"; import {$t} from "./i18n";
import {page_params} from "./page_params"; import {page_params} from "./page_params";
import * as people from "./people";
import * as util from "./util"; import * as util from "./util";
// Any single user should send add a finite number of tasks // Any single user should send add a finite number of tasks
@ -16,6 +17,10 @@ export class TaskData {
task_map = new Map(); task_map = new Map();
my_idx = 1; my_idx = 1;
constructor({current_user_id}) {
this.me = current_user_id;
}
get_widget_data() { get_widget_data() {
const all_tasks = Array.from(this.task_map.values()); const all_tasks = Array.from(this.task_map.values());
all_tasks.sort((a, b) => util.strcmp(a.task, b.task)); all_tasks.sort((a, b) => util.strcmp(a.task, b.task));
@ -156,7 +161,9 @@ export function activate(opts) {
const elem = opts.elem; const elem = opts.elem;
const callback = opts.callback; const callback = opts.callback;
const task_data = new TaskData(); const task_data = new TaskData({
current_user_id: people.my_current_user_id(),
});
function render() { function render() {
const html = render_widgets_todo_widget(); const html = render_widgets_todo_widget();