fix: local data before sending to server
TS Lint / Oxlint (push) Successful in 58s
TS Lint / TypeScript (push) Successful in 1m17s
TS Lint / ESLint (push) Successful in 1m17s
Docker Build / build (push) Successful in 13m28s

This commit is contained in:
2026-07-16 15:54:34 +02:00
parent 41e94c8bcb
commit 603bd9f108
3 changed files with 88 additions and 48 deletions
+52 -36
View File
@@ -13,7 +13,7 @@ import { updateTask } from "@/api/tasks";
const CronInput = defineAsyncComponent( const CronInput = defineAsyncComponent(
() => import("@/components/CronInput.vue"), () => import("@/components/CronInput.vue"),
); );
import { taskCompleted, taskNextReset } from "@/lib/tasks"; import { isTemporary, taskCompleted, taskNextReset } from "@/lib/tasks";
import { relativeTime } from "@/lib/dates"; import { relativeTime } from "@/lib/dates";
import { useAlertStore } from "@/stores/alerts"; import { useAlertStore } from "@/stores/alerts";
import { useI18n } from "vue-i18n"; import { useI18n } from "vue-i18n";
@@ -38,9 +38,11 @@ const i18n = useI18n();
const { alertSuccess, alertError } = useAlertStore(); const { alertSuccess, alertError } = useAlertStore();
async function onOpen() { async function onOpen() {
editMode.value = true; if (!isTemporary(task.value)) {
await nextTick(); editMode.value = true;
editNameInput.value?.focus(); await nextTick();
editNameInput.value?.focus();
}
} }
function onClose() { function onClose() {
@@ -51,10 +53,14 @@ function onClose() {
function onSave() { function onSave() {
if (editName.value.trim()) { if (editName.value.trim()) {
updateTask(task.value.id, { const data = {
name: editName.value.trim(), name: editName.value.trim(),
reset_cron: editCron.value, reset_cron: editCron.value,
}) };
task.value.name = editName.value.trim();
task.value.reset_cron = editCron.value;
editMode.value = false;
updateTask(task.value.id, data)
.then((newTask) => { .then((newTask) => {
task.value = newTask; task.value = newTask;
emit("updated", newTask); emit("updated", newTask);
@@ -63,46 +69,55 @@ function onSave() {
.catch(() => { .catch(() => {
alertError(i18n.t("alerts.task_update_error")); alertError(i18n.t("alerts.task_update_error"));
}); });
task.value.name = editName.value;
task.value.reset_cron = editCron.value;
editMode.value = false;
} }
} }
function onCheck() { function onCheck() {
if (!checked.value) { if (!isTemporary(task.value)) {
updateTask(task.value.id, { if (!checked.value) {
check_date: new Date().toISOString(), const data = {
previous_check_date: task.value.check_date?.toISOString(), check_date: new Date().toISOString(),
}) previous_check_date: task.value.check_date?.toISOString(),
.then((newTask) => { };
task.value = newTask; task.value.previous_check_date = task.value.check_date;
emit("updated", newTask); task.value.check_date = new Date();
}) updateTask(task.value.id, data)
.catch(() => { .then((data) => {
alertError(i18n.t("alerts.task_update_error")); task.value = data;
}); emit("updated", data);
} else { })
updateTask(task.value.id, { .catch(() => {
check_date: null, alertError(i18n.t("alerts.task_update_error"));
previous_check_date: task.value.check_date?.toISOString(), });
}) } else {
.then((newTask) => { const data = {
task.value = newTask; check_date: null,
emit("updated", newTask); previous_check_date: task.value.check_date?.toISOString(),
}) };
.catch(() => { task.value.previous_check_date = task.value.check_date;
alertError(i18n.t("alerts.task_update_error")); task.value.check_date = null;
}); updateTask(task.value.id, data)
.then((data) => {
task.value = data;
emit("updated", data);
})
.catch(() => {
alertError(i18n.t("alerts.task_update_error"));
});
}
} }
} }
function onClone() { function onClone() {
emit("clone", task.value); if (!isTemporary(task.value)) {
emit("clone", task.value);
}
} }
function onDelete() { function onDelete() {
emit("delete", task.value); if (!isTemporary(task.value)) {
emit("delete", task.value);
}
} }
onBeforeMount(() => { onBeforeMount(() => {
@@ -112,6 +127,7 @@ onBeforeMount(() => {
refreshKey.value++; refreshKey.value++;
}, 60000); }, 60000);
}); });
watch(task, () => { watch(task, () => {
if (!editMode.value && task.value.name !== editName.value) { if (!editMode.value && task.value.name !== editName.value) {
editName.value = task.value.name; editName.value = task.value.name;
@@ -131,7 +147,7 @@ watch(task, () => {
type="checkbox" type="checkbox"
class="checkbox" class="checkbox"
:checked="checked" :checked="checked"
@click.prevent="onCheck" @click="onCheck"
/> />
</div> </div>
<div <div
+19 -1
View File
@@ -1,7 +1,9 @@
import { SortType } from "@/enums"; import { SortType } from "@/enums";
import type { RawTask, Task } from "@/types"; import type { RawTask, Task, TaskCreateData } from "@/types";
import { CronExpressionParser } from "cron-parser"; import { CronExpressionParser } from "cron-parser";
const TEMPORARY_ID = "tmp";
export function parseTask(task: RawTask): Task { export function parseTask(task: RawTask): Task {
return { return {
id: task.id, id: task.id,
@@ -16,6 +18,22 @@ export function parseTask(task: RawTask): Task {
}; };
} }
export function newTemporaryTask(data: TaskCreateData): Task {
return {
id: TEMPORARY_ID,
name: data.name,
reset_cron: data.reset_cron,
created_at: new Date(),
updated_at: new Date(),
check_date: null,
previous_check_date: null,
}
}
export function isTemporary(task: Task): boolean {
return task.id === TEMPORARY_ID;
}
export function taskNextReset(task: Task): Date | null { export function taskNextReset(task: Task): Date | null {
if (task.check_date === null || task.reset_cron === null) { if (task.check_date === null || task.reset_cron === null) {
return null; return null;
+17 -11
View File
@@ -14,7 +14,7 @@ import {
const TaskItem = defineAsyncComponent( const TaskItem = defineAsyncComponent(
() => import("@/components/TaskItem.vue"), () => import("@/components/TaskItem.vue"),
); );
import { taskCompleted, sortTasks } from "@/lib/tasks"; import { taskCompleted, sortTasks, newTemporaryTask } from "@/lib/tasks";
import { SortType } from "@/enums"; import { SortType } from "@/enums";
import { booleanCookieRef, enumCookieRef } from "@/lib/cookies"; import { booleanCookieRef, enumCookieRef } from "@/lib/cookies";
import { useAlertStore } from "@/stores/alerts"; import { useAlertStore } from "@/stores/alerts";
@@ -88,13 +88,16 @@ function reSortTasks(update = false) {
function onNewTask() { function onNewTask() {
if (taskInput.value.trim() && list.value && !loading.value) { if (taskInput.value.trim() && list.value && !loading.value) {
createTask(list.value, { const data = {
name: taskInput.value.trim(), name: taskInput.value.trim(),
reset_cron: null, reset_cron: null,
}) };
const task = newTemporaryTask(data);
tasks.value.push(task);
reSortTasks(true);
createTask(list.value, data)
.then((data: Task) => { .then((data: Task) => {
tasks.value.push(data); task.id = data.id;
reSortTasks(true);
alertSuccess(i18n.t("alerts.task_created")); alertSuccess(i18n.t("alerts.task_created"));
}) })
.catch(() => { .catch(() => {
@@ -112,12 +115,16 @@ function onUpdateTask() {
function onCloneTask(task: Task) { function onCloneTask(task: Task) {
if (list.value) { if (list.value) {
createTask(list.value, { const data = {
name: task.name, name: task.name,
reset_cron: task.reset_cron, reset_cron: task.reset_cron,
}) };
const newTask = newTemporaryTask(data);
tasks.value.push(newTask);
reSortTasks(true);
createTask(list.value, data)
.then((data: Task) => { .then((data: Task) => {
tasks.value.push(data); task.id = data.id;
reSortTasks(true); reSortTasks(true);
alertSuccess(i18n.t("alerts.task_cloned")); alertSuccess(i18n.t("alerts.task_cloned"));
}) })
@@ -128,16 +135,15 @@ function onCloneTask(task: Task) {
} }
function onDeleteTask(task: Task) { function onDeleteTask(task: Task) {
tasks.value.splice(tasks.value.indexOf(task), 1);
reSortTasks(true);
deleteTask(task.id) deleteTask(task.id)
.then(() => { .then(() => {
reSortTasks(true);
alertSuccess(i18n.t("alerts.task_deleted")); alertSuccess(i18n.t("alerts.task_deleted"));
}) })
.catch(() => { .catch(() => {
alertError(i18n.t("alerts.task_delete_error")); alertError(i18n.t("alerts.task_delete_error"));
}); });
tasks.value.splice(tasks.value.indexOf(task), 1);
} }
function onChangeSortType() { function onChangeSortType() {