refactor: format
TS Lint / ESLint (push) Has been cancelled
TS Lint / Oxlint (push) Has been cancelled
TS Lint / TypeScript (push) Has been cancelled

This commit is contained in:
2026-07-14 11:47:05 +02:00
parent 566f8403ef
commit a9b2e31d81
17 changed files with 432 additions and 183 deletions
+24 -9
View File
@@ -1,12 +1,18 @@
<script setup lang="ts">
import type { Alert } from '@/types';
import { computed, ref, onBeforeMount } from 'vue';
import { CircleX, CircleAlert, CircleCheck, Info } from '@lucide/vue';
import type { Alert } from "@/types";
import { computed, ref, onBeforeMount } from "vue";
import { CircleX, CircleAlert, CircleCheck, Info } from "@lucide/vue";
const props = defineProps<{ alert: Alert }>();
const dismissed = ref<boolean>(false);
const refreshKey = ref<number>(1);
const visible = computed<boolean>(() => refreshKey.value > 0 && !dismissed.value && (new Date().getTime() - props.alert.created.getTime()) <= props.alert.seconds * 1000);
const visible = computed<boolean>(
() =>
refreshKey.value > 0 &&
!dismissed.value &&
new Date().getTime() - props.alert.created.getTime() <=
props.alert.seconds * 1000,
);
function onDismiss() {
dismissed.value = true;
@@ -20,11 +26,20 @@ onBeforeMount(() => {
</script>
<template>
<div v-if="visible" class="alert alert-info alert-soft cursor-pointer" :class="`alert-${alert.type}`" @click="onDismiss">
<CircleX v-if="alert.type === 'error'" /> <!-- alert-error -->
<CircleAlert v-if="alert.type === 'warning'" /> <!-- alert-warning -->
<CircleCheck v-if="alert.type === 'success'" /> <!-- alert-success -->
<Info v-if="alert.type === 'info'" /> <!-- alert-info -->
<div
v-if="visible"
class="alert alert-info alert-soft cursor-pointer"
:class="`alert-${alert.type}`"
@click="onDismiss"
>
<CircleX v-if="alert.type === 'error'" />
<!-- alert-error -->
<CircleAlert v-if="alert.type === 'warning'" />
<!-- alert-warning -->
<CircleCheck v-if="alert.type === 'success'" />
<!-- alert-success -->
<Info v-if="alert.type === 'info'" />
<!-- alert-info -->
<span>{{ alert.message }}</span>
</div>
</template>
+10 -4
View File
@@ -1,13 +1,19 @@
<script setup lang="ts">
import { useAlertStore } from '@/stores/alerts';
import { defineAsyncComponent } from 'vue';
const AlertItem = defineAsyncComponent(() => import("@/components/AlertItem.vue"));
import { useAlertStore } from "@/stores/alerts";
import { defineAsyncComponent } from "vue";
const AlertItem = defineAsyncComponent(
() => import("@/components/AlertItem.vue"),
);
const { alerts } = useAlertStore();
</script>
<template>
<div class="toast select-none">
<alert-item v-for="alert in alerts" :key="alert.created.getTime()" :alert="alert" />
<alert-item
v-for="alert in alerts"
:key="alert.created.getTime()"
:alert="alert"
/>
</div>
</template>
+90 -18
View File
@@ -4,10 +4,10 @@ import { getCron, parseCron, validCron } from "@/lib/cron";
import { CronType } from "@/enums";
import { DEFAULT_CRON } from "@/constants";
const cron = defineModel<string|null>({ required: true });
const cron = defineModel<string | null>({ required: true });
const rawCron = ref<string>(DEFAULT_CRON);
const valid = ref<boolean>(true);
const props = defineProps<{editMode: boolean}>();
const props = defineProps<{ editMode: boolean }>();
const cronType = ref<CronType>(CronType.ONE_TIME);
const cronValue = ref<number>(0);
@@ -24,7 +24,7 @@ function updateCron() {
}
function onChangeCronType() {
switch(cronType.value) {
switch (cronType.value) {
case CronType.EVERY_DAY:
cronValue.value = 0;
break;
@@ -63,25 +63,97 @@ watch(cron, () => {
<template>
<div class="flex gap-2">
<select v-model="cronType" class="select" @change="onChangeCronType">
<option :value="CronType.ONE_TIME">{{ $t('cron.type.one_time') }}</option>
<option :value="CronType.EVERY_DAY">{{ $t('cron.type.every_day') }}</option>
<option :value="CronType.EVERY_WEEK">{{ $t('cron.type.every_week') }}</option>
<option :value="CronType.EVERY_MONTH">{{ $t('cron.type.every_month') }}</option>
<option :value="CronType.EVERY_YEAR">{{ $t('cron.type.every_year') }}</option>
<option :value="CronType.SPECIFIC">{{ $t('cron.type.specific') }}</option>
<option :value="CronType.ONE_TIME">
{{ $t("cron.type.one_time") }}
</option>
<option :value="CronType.EVERY_DAY">
{{ $t("cron.type.every_day") }}
</option>
<option :value="CronType.EVERY_WEEK">
{{ $t("cron.type.every_week") }}
</option>
<option :value="CronType.EVERY_MONTH">
{{ $t("cron.type.every_month") }}
</option>
<option :value="CronType.EVERY_YEAR">
{{ $t("cron.type.every_year") }}
</option>
<option :value="CronType.SPECIFIC">
{{ $t("cron.type.specific") }}
</option>
</select>
<select v-if="cronType === CronType.EVERY_DAY" v-model="cronValue" class="select" @change="onChangeCronValue">
<option v-for="i in Array.from(Array(24).keys())" :key="`h${i}`" :value="i">{{ i.toFixed(0).padStart(2, '0') }}:00</option>
<select
v-if="cronType === CronType.EVERY_DAY"
v-model="cronValue"
class="select"
@change="onChangeCronValue"
>
<option
v-for="i in Array.from(Array(24).keys())"
:key="`h${i}`"
:value="i"
>
{{ i.toFixed(0).padStart(2, "0") }}:00
</option>
</select>
<select v-if="cronType === CronType.EVERY_WEEK" v-model="cronValue" class="select" @change="onChangeCronValue">
<option v-for="i in Array.from(Array(7).keys())" :key="`w${i}`" :value="i + 1">{{ $t(`cron.week.${i.toFixed(0)}`) }}</option>
<select
v-if="cronType === CronType.EVERY_WEEK"
v-model="cronValue"
class="select"
@change="onChangeCronValue"
>
<option
v-for="i in Array.from(Array(7).keys())"
:key="`w${i}`"
:value="i + 1"
>
{{ $t(`cron.week.${i.toFixed(0)}`) }}
</option>
</select>
<select v-if="cronType === CronType.EVERY_MONTH" v-model="cronValue" class="select" @change="onChangeCronValue">
<option v-for="i in Array.from(Array(31).keys())" :key="`d${i}`" :value="i + 1">{{i + 1}}{{ i % 10 == 0 ? $t('cron.month.st') : (i % 10 === 1 ? $t('cron.month.nd'): (i % 10 === 2 ? $t('cron.month.rd') : $t('cron.month.th'))) }}</option>
<select
v-if="cronType === CronType.EVERY_MONTH"
v-model="cronValue"
class="select"
@change="onChangeCronValue"
>
<option
v-for="i in Array.from(Array(31).keys())"
:key="`d${i}`"
:value="i + 1"
>
{{ i + 1
}}{{
i % 10 == 0
? $t("cron.month.st")
: i % 10 === 1
? $t("cron.month.nd")
: i % 10 === 2
? $t("cron.month.rd")
: $t("cron.month.th")
}}
</option>
</select>
<select v-if="cronType === CronType.EVERY_YEAR" v-model="cronValue" class="select" @change="onChangeCronValue">
<option v-for="i in Array.from(Array(12).keys())" :key="`m${i}`" :value="i + 1">{{ $t(`cron.year.${i.toFixed(0)}`) }}</option>
<select
v-if="cronType === CronType.EVERY_YEAR"
v-model="cronValue"
class="select"
@change="onChangeCronValue"
>
<option
v-for="i in Array.from(Array(12).keys())"
:key="`m${i}`"
:value="i + 1"
>
{{ $t(`cron.year.${i.toFixed(0)}`) }}
</option>
</select>
<input v-if="cronType === CronType.SPECIFIC" v-model="rawCron" type="text" class="input font-mono" :class="valid ? '' : 'input-error'" @input="onInputRawCron" />
<input
v-if="cronType === CronType.SPECIFIC"
v-model="rawCron"
type="text"
class="input font-mono"
:class="valid ? '' : 'input-error'"
@input="onInputRawCron"
/>
</div>
</template>
+5 -4
View File
@@ -1,15 +1,16 @@
<script setup lang="ts">
import { setCookie } from '@/lib/cookies';
import { useI18n } from 'vue-i18n';
import { setCookie } from "@/lib/cookies";
import { useI18n } from "vue-i18n";
const i18n = useI18n();
function onSetLang(lang: string) {
i18n.locale.value = lang;
setCookie('lang', lang);
setCookie("lang", lang);
}
</script>
<template>
<a href="#" @click.prevent="onSetLang('fr')">🇫🇷</a> / <a href="#" @click.prevent="onSetLang('en')">🇺🇸</a>
<a href="#" @click.prevent="onSetLang('fr')">🇫🇷</a> /
<a href="#" @click.prevent="onSetLang('en')">🇺🇸</a>
</template>
+9 -5
View File
@@ -1,19 +1,23 @@
<script setup lang="ts">
import { defineAsyncComponent } from "vue";
const LangInput = defineAsyncComponent(() => import("@/components/LangInput.vue"));
const LangInput = defineAsyncComponent(
() => import("@/components/LangInput.vue"),
);
</script>
<template>
<footer class="footer sm:footer-horizontal footer-center bg-base-300 text-base-content p-2">
<footer
class="footer sm:footer-horizontal footer-center bg-base-300 text-base-content p-2"
>
<aside>
<p>
<lang-input /> - 2026 -
<a
href="https://git.klemek.fr/klemek/tout-doux"
class="underline">
klemek
class="underline"
>
klemek
</a>
</p>
</aside>
+48 -21
View File
@@ -3,20 +3,22 @@ import { onBeforeMount, ref, watch, computed, defineAsyncComponent } from "vue";
import type { Task } from "@/types";
import { Copy, Trash, Save, X } from "@lucide/vue";
import { updateTask } from "@/api/tasks";
const CronInput = defineAsyncComponent(() => import("@/components/CronInput.vue"));
const CronInput = defineAsyncComponent(
() => import("@/components/CronInput.vue"),
);
import { taskCompleted, taskNextReset } from "@/lib/tasks";
import { relativeTime } from "@/lib/dates";
import { useAlertStore } from "@/stores/alerts";
import { useI18n } from "vue-i18n";
const emit = defineEmits<(e: 'clone' | 'delete', task: Task) => void>();
const emit = defineEmits<(e: "clone" | "delete", task: Task) => void>();
const task = defineModel<Task>({ required: true });
defineProps<{ showLastChecked: boolean; showNextReset: boolean }>();
const editMode = ref<boolean>(false);
const editName = ref<string>('');
const editCron = ref<string|null>(null);
const editName = ref<string>("");
const editCron = ref<string | null>(null);
const refreshKey = ref<number>(0);
const checked = computed<boolean>(() => taskCompleted(task.value));
@@ -31,13 +33,17 @@ function onClose() {
}
function onSave() {
updateTask(task.value.id, { name: editName.value, reset_cron: editCron.value })
updateTask(task.value.id, {
name: editName.value,
reset_cron: editCron.value,
})
.then((newTask) => {
task.value = newTask;
alertSuccess(i18n.t('alerts.task_updated'));
}).catch(() => {
alertError(i18n.t('alerts.task_update_error'))
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;
@@ -45,28 +51,36 @@ function onSave() {
function onCheck() {
if (!checked.value) {
updateTask(task.value.id, { check_date: (new Date()).toISOString(), previous_check_date: task.value.check_date?.toISOString() })
updateTask(task.value.id, {
check_date: new Date().toISOString(),
previous_check_date: task.value.check_date?.toISOString(),
})
.then((newTask) => {
task.value = newTask;
}).catch(() => {
alertError(i18n.t('alerts.task_update_error'))
})
.catch(() => {
alertError(i18n.t("alerts.task_update_error"));
});
} else {
updateTask(task.value.id, { check_date: null, previous_check_date: task.value.check_date?.toISOString() })
updateTask(task.value.id, {
check_date: null,
previous_check_date: task.value.check_date?.toISOString(),
})
.then((newTask) => {
task.value = newTask;
}).catch(() => {
alertError(i18n.t('alerts.task_update_error'))
})
.catch(() => {
alertError(i18n.t("alerts.task_update_error"));
});
}
}
function onClone() {
emit('clone', task.value);
emit("clone", task.value);
}
function onDelete() {
emit('delete', task.value);
emit("delete", task.value);
}
onBeforeMount(() => {
@@ -89,7 +103,13 @@ watch(task, () => {
<template>
<div class="list-row text-left">
<div class="content-center">
<input :id="refreshKey.toFixed(0)" type="checkbox" class="checkbox" :checked="checked" @click.prevent="onCheck" />
<input
:id="refreshKey.toFixed(0)"
type="checkbox"
class="checkbox"
:checked="checked"
@click.prevent="onCheck"
/>
</div>
<div
v-if="!editMode"
@@ -97,11 +117,18 @@ watch(task, () => {
@click.prevent="editMode = true"
>
<div>{{ task.name }}</div>
<div v-if="showLastChecked && !checked && task.check_date" class="font-light text-xs italic">
{{ $t('checked') }} {{ relativeTime(task.check_date, $i18n.locale) }}
<div
v-if="showLastChecked && !checked && task.check_date"
class="font-light text-xs italic"
>
{{ $t("checked") }}
{{ relativeTime(task.check_date, $i18n.locale) }}
</div>
<div v-if="showNextReset && checked && nextReset" class="font-light text-xs italic">
{{ $t('resets') }} {{ relativeTime(nextReset, $i18n.locale) }}
<div
v-if="showNextReset && checked && nextReset"
class="font-light text-xs italic"
>
{{ $t("resets") }} {{ relativeTime(nextReset, $i18n.locale) }}
</div>
</div>
<template v-else>
+112 -63
View File
@@ -3,7 +3,9 @@ import { ref, onBeforeMount, computed, defineAsyncComponent } from "vue";
import type { Task } from "@/types";
import { getTasks, createTask, deleteTask } from "@/api/tasks";
import { CirclePlus } from "@lucide/vue";
const TaskItem = defineAsyncComponent(() => import("@/components/TaskItem.vue"));
const TaskItem = defineAsyncComponent(
() => import("@/components/TaskItem.vue"),
);
import { taskCompleted, sortTasks } from "@/lib/tasks";
import { SortType } from "@/enums";
import { booleanCookieRef, enumCookieRef } from "@/lib/cookies";
@@ -14,7 +16,10 @@ const taskInput = ref<string>("");
const tasks = ref<Task[]>([]);
const list = ref<string>("test");
const sortType = enumCookieRef<SortType>("toutDouxSortType", SortType.CREATED_AT);
const sortType = enumCookieRef<SortType>(
"toutDouxSortType",
SortType.CREATED_AT,
);
const sortReverse = booleanCookieRef("toutDouxSortReverse", false);
const showLastChecked = booleanCookieRef("toutDouxShowLastChecked", false);
const showNextReset = booleanCookieRef("toutDouxShowNextReset", false);
@@ -34,13 +39,14 @@ function fetchTasks() {
tasks.value = data;
reSortTasks();
setTimeout(fetchTasks, 10000);
}).catch(() => {
if (tasks.value.length !== 0) {
alertWarning(i18n.t('alerts.task_refresh_error'));
} else {
alertError(i18n.t('alerts.task_fetch_error'));
}
})
.catch(() => {
if (tasks.value.length !== 0) {
alertWarning(i18n.t("alerts.task_refresh_error"));
} else {
alertError(i18n.t("alerts.task_fetch_error"));
}
});
}
function reSortTasks() {
@@ -56,10 +62,10 @@ function onNewTask() {
.then((data: Task) => {
tasks.value.push(data);
reSortTasks();
alertSuccess(i18n.t('alerts.task_created'));
alertSuccess(i18n.t("alerts.task_created"));
})
.catch(() => {
alertError(i18n.t('alerts.task_create_error'))
alertError(i18n.t("alerts.task_create_error"));
})
.finally(() => {
taskInput.value = "";
@@ -71,21 +77,24 @@ function onCloneTask(task: Task) {
createTask(list.value, {
name: task.name,
reset_cron: task.reset_cron,
}).then((data: Task) => {
tasks.value.push(data);
alertSuccess(i18n.t('alerts.task_cloned'));
}).catch(() => {
alertError(i18n.t('alerts.task_create_error'))
})
.then((data: Task) => {
tasks.value.push(data);
alertSuccess(i18n.t("alerts.task_cloned"));
})
.catch(() => {
alertError(i18n.t("alerts.task_create_error"));
});
}
function onDeleteTask(task: Task) {
deleteTask(task.id)
.then(() => {
alertSuccess(i18n.t('alerts.task_deleted'));
}).catch(() => {
alertError(i18n.t('alerts.task_delete_error'))
alertSuccess(i18n.t("alerts.task_deleted"));
})
.catch(() => {
alertError(i18n.t("alerts.task_delete_error"));
});
tasks.value.splice(tasks.value.indexOf(task), 1);
}
@@ -115,10 +124,13 @@ onBeforeMount(fetchTasks);
</li>
</template>
<li v-if="empty" class="list-row italic text-xl font-extralight">
{{ $t('empty_hint') }}
{{ $t("empty_hint") }}
</li>
<li v-if="allCompleted && separateCompleted" class="list-row italic text-xl font-extralight">
{{ $t('all_completed_hint') }}
<li
v-if="allCompleted && separateCompleted"
class="list-row italic text-xl font-extralight"
>
{{ $t("all_completed_hint") }}
</li>
<li class="list-row">
<div class="list-col-grow">
@@ -141,12 +153,18 @@ onBeforeMount(fetchTasks);
</div>
</li>
</ul>
<div v-if="separateCompleted && hasCompleted" class="collapse collapse-arrow">
<input id="completed-dropdown" type="checkbox" />
<div class="collapse-title mb-0">{{ $t('completed') }}</div>
<div class="collapse-content p-0">
<ul class="list">
<template v-for="(task, i) in tasks" :key="`${task.id}-completed`">
<div
v-if="separateCompleted && hasCompleted"
class="collapse collapse-arrow"
>
<input id="completed-dropdown" type="checkbox" />
<div class="collapse-title mb-0">{{ $t("completed") }}</div>
<div class="collapse-content p-0">
<ul class="list">
<template
v-for="(task, i) in tasks"
:key="`${task.id}-completed`"
>
<li v-if="tasks[i] && taskCompleted(task)">
<task-item
v-model="tasks[i]"
@@ -156,42 +174,73 @@ onBeforeMount(fetchTasks);
@delete="onDeleteTask"
/>
</li>
</template>
</ul>
</div>
</template>
</ul>
</div>
</div>
<div class="collapse collapse-arrow font-light text-sm">
<input id="options-dropdown" type="checkbox"/>
<div class="collapse-title">{{ $t('options.title') }}</div>
<div class="collapse-content text-sm">
<fieldset class="fieldset flex flex-col gap-2">
<label class="label">
Sort by
<select v-model="sortType" class="select" @change="onChangeSortType">
<option :value="SortType.CREATED_AT">{{ $t('options.sort.created_at') }}</option>
<option :value="SortType.UPDATED_AT">{{ $t('options.sort.updated_at') }}</option>
<option :value="SortType.CHECK_DATE">{{ $t('options.sort.check_date') }}</option>
<option :value="SortType.RESET_DATE">{{ $t('options.sort.reset_date') }}</option>
<option :value="SortType.NAME">{{ $t('options.sort.name') }}</option>
</select>
</label>
<label class="label">
<input v-model="sortReverse" type="checkbox" class="checkbox" @change="onChangeSortReverse" />
{{ $t('options.reverse_sort') }}
</label>
<label class="label">
<input v-model="showLastChecked" type="checkbox" class="checkbox" />
{{ $t('options.last_checked') }}
</label>
<label class="label">
<input v-model="showNextReset" type="checkbox" class="checkbox" />
{{ $t('options.next_reset') }}
</label>
<label class="label">
<input v-model="separateCompleted" type="checkbox" class="checkbox" />
{{ $t('options.separate_completed') }}
</label>
</fieldset>
</div>
<div class="collapse collapse-arrow font-light text-sm">
<input id="options-dropdown" type="checkbox" />
<div class="collapse-title">{{ $t("options.title") }}</div>
<div class="collapse-content text-sm">
<fieldset class="fieldset flex flex-col gap-2">
<label class="label">
Sort by
<select
v-model="sortType"
class="select"
@change="onChangeSortType"
>
<option :value="SortType.CREATED_AT">
{{ $t("options.sort.created_at") }}
</option>
<option :value="SortType.UPDATED_AT">
{{ $t("options.sort.updated_at") }}
</option>
<option :value="SortType.CHECK_DATE">
{{ $t("options.sort.check_date") }}
</option>
<option :value="SortType.RESET_DATE">
{{ $t("options.sort.reset_date") }}
</option>
<option :value="SortType.NAME">
{{ $t("options.sort.name") }}
</option>
</select>
</label>
<label class="label">
<input
v-model="sortReverse"
type="checkbox"
class="checkbox"
@change="onChangeSortReverse"
/>
{{ $t("options.reverse_sort") }}
</label>
<label class="label">
<input
v-model="showLastChecked"
type="checkbox"
class="checkbox"
/>
{{ $t("options.last_checked") }}
</label>
<label class="label">
<input
v-model="showNextReset"
type="checkbox"
class="checkbox"
/>
{{ $t("options.next_reset") }}
</label>
<label class="label">
<input
v-model="separateCompleted"
type="checkbox"
class="checkbox"
/>
{{ $t("options.separate_completed") }}
</label>
</fieldset>
</div>
</div>
</template>