fix: local data before sending to server
This commit is contained in:
@@ -14,7 +14,7 @@ import {
|
||||
const TaskItem = defineAsyncComponent(
|
||||
() => import("@/components/TaskItem.vue"),
|
||||
);
|
||||
import { taskCompleted, sortTasks } from "@/lib/tasks";
|
||||
import { taskCompleted, sortTasks, newTemporaryTask } from "@/lib/tasks";
|
||||
import { SortType } from "@/enums";
|
||||
import { booleanCookieRef, enumCookieRef } from "@/lib/cookies";
|
||||
import { useAlertStore } from "@/stores/alerts";
|
||||
@@ -88,13 +88,16 @@ function reSortTasks(update = false) {
|
||||
|
||||
function onNewTask() {
|
||||
if (taskInput.value.trim() && list.value && !loading.value) {
|
||||
createTask(list.value, {
|
||||
const data = {
|
||||
name: taskInput.value.trim(),
|
||||
reset_cron: null,
|
||||
})
|
||||
};
|
||||
const task = newTemporaryTask(data);
|
||||
tasks.value.push(task);
|
||||
reSortTasks(true);
|
||||
createTask(list.value, data)
|
||||
.then((data: Task) => {
|
||||
tasks.value.push(data);
|
||||
reSortTasks(true);
|
||||
task.id = data.id;
|
||||
alertSuccess(i18n.t("alerts.task_created"));
|
||||
})
|
||||
.catch(() => {
|
||||
@@ -112,12 +115,16 @@ function onUpdateTask() {
|
||||
|
||||
function onCloneTask(task: Task) {
|
||||
if (list.value) {
|
||||
createTask(list.value, {
|
||||
const data = {
|
||||
name: task.name,
|
||||
reset_cron: task.reset_cron,
|
||||
})
|
||||
};
|
||||
const newTask = newTemporaryTask(data);
|
||||
tasks.value.push(newTask);
|
||||
reSortTasks(true);
|
||||
createTask(list.value, data)
|
||||
.then((data: Task) => {
|
||||
tasks.value.push(data);
|
||||
task.id = data.id;
|
||||
reSortTasks(true);
|
||||
alertSuccess(i18n.t("alerts.task_cloned"));
|
||||
})
|
||||
@@ -128,16 +135,15 @@ function onCloneTask(task: Task) {
|
||||
}
|
||||
|
||||
function onDeleteTask(task: Task) {
|
||||
tasks.value.splice(tasks.value.indexOf(task), 1);
|
||||
reSortTasks(true);
|
||||
deleteTask(task.id)
|
||||
.then(() => {
|
||||
reSortTasks(true);
|
||||
alertSuccess(i18n.t("alerts.task_deleted"));
|
||||
})
|
||||
.catch(() => {
|
||||
alertError(i18n.t("alerts.task_delete_error"));
|
||||
});
|
||||
|
||||
tasks.value.splice(tasks.value.indexOf(task), 1);
|
||||
}
|
||||
|
||||
function onChangeSortType() {
|
||||
|
||||
Reference in New Issue
Block a user