add multiple tasks in the same command

This commit is contained in:
liyunze 2023-08-07 22:19:08 +08:00
parent 1eb7611d5c
commit b5b2d9d7e2
3 changed files with 16 additions and 4 deletions

View file

@ -175,7 +175,7 @@ const configs = (function () {
];
// Responses
const taskAdded = 'The task "{message}" has been added, {user}!';
const taskAdded = 'The task(s) "{task}" has been added, {user}!';
const noTaskAdded =
"Looks like you already hit the limit of incomplete tasks, {user}";
const noTaskContent = "Try using !task the-task-you-are-working-on {user}";

View file

@ -41,7 +41,8 @@ ComfyJS.onCommand = (user, command, message, flags, extra) => {
} else if (addStatus === 2) {
// task has no content
respond(responses.noTaskContent, params);
} else if (addStatus === 3) {
} else {
params.task = addStatus;
// task added
respond(responses.taskAdded, params);
}

View file

@ -152,7 +152,7 @@ function setupDB() {
// 0: limit has reached
// 1: duplicate task
// 2: invalid input
// 3: success
// string (single or multiple tasks): success
function addTask(username, userColor, task) {
const tasks = JSON.parse(localStorage.tasks);
if (!tasks[username]) {
@ -183,11 +183,22 @@ function addTask(username, userColor, task) {
return 2;
}
// if task has commas
if (task.includes(",")) {
let tasksToAdd = task.split(",").map((t) => t.trim());
for (const t of tasksToAdd) {
tasks[username].todos.push({ text: t, done: false });
}
localStorage.setItem(`tasks`, JSON.stringify(tasks));
renderTaskListToDOM();
return tasksToAdd.join('", "');
}
tasks[username].todos.push({ text: task, done: false });
localStorage.setItem(`tasks`, JSON.stringify(tasks));
renderTaskListToDOM();
return 3;
return task;
}
// 0: user has no tasks