@@ -107,6 +107,10 @@ export default {
* @param task the task to save; this is an object as received from the broker.
*/
saveTask(task) {
+ if (!task.title) {
+ /* don't save empty tasks */
+ return;
+ }
console.info(`Saving task '${task.title}' with id ${task.id}`);
let request = "";
if (task.id !== NEW_TASK_ID) {
@@ -114,8 +118,8 @@ export default {
request = `mutation {
updateTask(
id: "${task.id}",
- title: "${task.title}",
- description: "${task.description}",
+ title: "${task.title.replaceAll('"', '\\"')}",
+ description: "${task.description.replaceAll('"', '\\"')}",
completed: ${task.completed ? "true" : "false"},
list: {
id: "${task.list.id}"
@@ -128,8 +132,8 @@ export default {
/* create new task */
request = `mutation {
createTask(
- title: "${task.title}",
- description: "${task.description}",
+ title: "${task.title.replaceAll('"', '\\"')}",
+ description: "${task.description.replaceAll('"', '\\"')}",
completed: ${task.completed ? "true" : "false"},
list: {
id: "${task.list.id}"
@@ -148,7 +152,7 @@ export default {
request
).then(data => {
/* Save the task's id in case it was just created */
- if (!task.id) {
+ if (task.id === NEW_TASK_ID) {
task.id = data.createTask.id;
}
}).catch(e => {
@@ -196,15 +200,18 @@ export default {
return;
}
- store.tasks.push({
- id: NEW_TASK_ID,
- completed: false,
- title: "Enter task here",
- description: "",
- list: {
- id: this.currentList,
- }
- });
+ /* Do not add another empty/new task */
+ if (!store.tasks.find((item) => item.id === NEW_TASK_ID)) {
+ store.tasks.push({
+ id: NEW_TASK_ID,
+ completed: false,
+ title: "",
+ description: "",
+ list: {
+ id: this.currentList,
+ }
+ });
+ }
/* wait a moment, then scroll list to the bottom */
setTimeout(function() {