Compare commits
4
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3a40b06354 | ||
|
|
117d3a2029 | ||
|
|
478091b0ba | ||
|
|
08b3b06089 |
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "tout-doux",
|
||||
"version": "1.0.2",
|
||||
"version": "1.0.4",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"engines": {
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
[project]
|
||||
name = "tout-doux"
|
||||
version = "1.0.2"
|
||||
version = "1.0.4"
|
||||
description = ""
|
||||
requires-python = ">=3.14"
|
||||
dependencies = [
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<script setup lang="ts">
|
||||
import { onBeforeMount, ref, watch, computed, defineAsyncComponent } from "vue";
|
||||
import { onBeforeMount, ref, watch, computed, defineAsyncComponent, nextTick } from "vue";
|
||||
import type { Task } from "@/types";
|
||||
import { CopyIcon, TrashIcon, SaveIcon, XIcon } from "@lucide/vue";
|
||||
import { updateTask } from "@/api/tasks";
|
||||
@@ -11,7 +11,8 @@ import { relativeTime } from "@/lib/dates";
|
||||
import { useAlertStore } from "@/stores/alerts";
|
||||
import { useI18n } from "vue-i18n";
|
||||
|
||||
const emit = defineEmits<(e: "clone" | "delete" | "updated", task: Task) => void>();
|
||||
const emit =
|
||||
defineEmits<(e: "clone" | "delete" | "updated", task: Task) => void>();
|
||||
|
||||
const task = defineModel<Task>({ required: true });
|
||||
defineProps<{ showLastChecked: boolean; showNextReset: boolean }>();
|
||||
@@ -20,6 +21,7 @@ const editMode = ref<boolean>(false);
|
||||
const editName = ref<string>("");
|
||||
const editCron = ref<string | null>(null);
|
||||
const refreshKey = ref<number>(0);
|
||||
const editNameInput = ref<HTMLInputElement | null>(null);
|
||||
|
||||
const checked = computed<boolean>(() => taskCompleted(task.value));
|
||||
const nextReset = computed<Date | null>(() => taskNextReset(task.value));
|
||||
@@ -28,26 +30,36 @@ const i18n = useI18n();
|
||||
|
||||
const { alertSuccess, alertError } = useAlertStore();
|
||||
|
||||
async function onOpen() {
|
||||
editMode.value = true;
|
||||
await nextTick();
|
||||
editNameInput.value?.focus();
|
||||
}
|
||||
|
||||
function onClose() {
|
||||
editName.value = task.value.name;
|
||||
editCron.value = task.value.reset_cron;
|
||||
editMode.value = false;
|
||||
}
|
||||
|
||||
function onSave() {
|
||||
updateTask(task.value.id, {
|
||||
name: editName.value,
|
||||
reset_cron: editCron.value,
|
||||
})
|
||||
.then((newTask) => {
|
||||
task.value = newTask;
|
||||
emit("updated", newTask);
|
||||
alertSuccess(i18n.t("alerts.task_updated"));
|
||||
if (editName.value.trim()) {
|
||||
updateTask(task.value.id, {
|
||||
name: editName.value.trim(),
|
||||
reset_cron: editCron.value,
|
||||
})
|
||||
.catch(() => {
|
||||
alertError(i18n.t("alerts.task_update_error"));
|
||||
});
|
||||
task.value.name = editName.value;
|
||||
task.value.reset_cron = editCron.value;
|
||||
editMode.value = false;
|
||||
.then((newTask) => {
|
||||
task.value = newTask;
|
||||
emit("updated", newTask);
|
||||
alertSuccess(i18n.t("alerts.task_updated"));
|
||||
})
|
||||
.catch(() => {
|
||||
alertError(i18n.t("alerts.task_update_error"));
|
||||
});
|
||||
task.value.name = editName.value;
|
||||
task.value.reset_cron = editCron.value;
|
||||
editMode.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
function onCheck() {
|
||||
@@ -105,7 +117,7 @@ watch(task, () => {
|
||||
|
||||
<template>
|
||||
<div class="list-row text-left">
|
||||
<template v-if="!editMode">
|
||||
<template v-if="!editMode">
|
||||
<div class="content-center">
|
||||
<input
|
||||
:id="refreshKey.toFixed(0)"
|
||||
@@ -117,7 +129,7 @@ watch(task, () => {
|
||||
</div>
|
||||
<div
|
||||
class="cursor-pointer text-lg select-none"
|
||||
@click.prevent="editMode = true"
|
||||
@click.prevent="onOpen"
|
||||
>
|
||||
<div>{{ task.name }}</div>
|
||||
<div
|
||||
@@ -131,7 +143,8 @@ watch(task, () => {
|
||||
v-if="showNextReset && checked && nextReset"
|
||||
class="font-light text-xs italic"
|
||||
>
|
||||
{{ $t("resets") }} {{ relativeTime(nextReset, $i18n.locale) }}
|
||||
{{ $t("resets") }}
|
||||
{{ relativeTime(nextReset, $i18n.locale) }}
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
@@ -141,7 +154,13 @@ watch(task, () => {
|
||||
<button class="btn btn-square me-1" @click="onClose">
|
||||
<x-icon />
|
||||
</button>
|
||||
<button class="btn btn-square me-1" @click="onSave">
|
||||
<button
|
||||
class="btn btn-square me-1"
|
||||
:class="
|
||||
editName.trim().length === 0 ? 'btn-disabled' : ''
|
||||
"
|
||||
@click="onSave"
|
||||
>
|
||||
<save-icon />
|
||||
</button>
|
||||
<button class="btn btn-square me-1" @click="onClone">
|
||||
@@ -151,7 +170,13 @@ watch(task, () => {
|
||||
<trash-icon />
|
||||
</button>
|
||||
</div>
|
||||
<input v-model="editName" type="text" class="input w-full" />
|
||||
<input
|
||||
ref="editNameInput"
|
||||
v-model="editName"
|
||||
type="text"
|
||||
class="input w-full"
|
||||
@keyup.enter="onSave"
|
||||
/>
|
||||
<cron-input v-model="editCron" :edit-mode="editMode" />
|
||||
</div>
|
||||
</template>
|
||||
|
||||
@@ -25,6 +25,7 @@ import { shareLink } from "@/lib/share";
|
||||
const route = useRoute();
|
||||
|
||||
const list = ref<string | null>(null);
|
||||
const loading = ref<boolean>(true);
|
||||
const taskInput = ref<string>("");
|
||||
const tasks = ref<Task[]>([]);
|
||||
|
||||
@@ -54,6 +55,7 @@ function fetchTasks() {
|
||||
.then((data: Task[]) => {
|
||||
tasks.value = data;
|
||||
reSortTasks();
|
||||
loading.value = false;
|
||||
setTimeout(fetchTasks, 10000);
|
||||
})
|
||||
.catch(() => {
|
||||
@@ -72,7 +74,7 @@ function reSortTasks() {
|
||||
}
|
||||
|
||||
function onNewTask() {
|
||||
if (taskInput.value.trim() && list.value) {
|
||||
if (taskInput.value.trim() && list.value && !loading.value) {
|
||||
createTask(list.value, {
|
||||
name: taskInput.value.trim(),
|
||||
reset_cron: null,
|
||||
@@ -179,7 +181,7 @@ onBeforeRouteUpdate((to) => {
|
||||
</li>
|
||||
</template>
|
||||
<li
|
||||
v-if="empty"
|
||||
v-if="!loading && empty"
|
||||
class="list-row italic text-xl font-extralight self-center"
|
||||
>
|
||||
<span
|
||||
@@ -188,7 +190,7 @@ onBeforeRouteUpdate((to) => {
|
||||
></span>
|
||||
</li>
|
||||
<li
|
||||
v-else-if="allCompleted && separateCompleted"
|
||||
v-else-if="!loading && allCompleted && separateCompleted"
|
||||
class="list-row italic text-xl font-extralight self-center"
|
||||
>
|
||||
<span
|
||||
@@ -209,7 +211,7 @@ onBeforeRouteUpdate((to) => {
|
||||
<div>
|
||||
<button
|
||||
class="btn btn-square"
|
||||
:disabled="taskInput.trim().length === 0"
|
||||
:disabled="loading || taskInput.trim().length === 0"
|
||||
@click="onNewTask"
|
||||
>
|
||||
<circle-plus-icon />
|
||||
|
||||
Reference in New Issue
Block a user