fix: can create task to do now
Build and Deploy / build-and-push (push) Successful in 1m24s Details

This commit is contained in:
Ludo 2026-05-04 16:18:30 +02:00
parent 844eb00270
commit 9f03e5bc45
2 changed files with 14 additions and 8 deletions

View File

@ -39,16 +39,22 @@ fastify.post<{ Body: { name: string; doesRepeat: boolean; repeatsEvery?: string;
return;
}
// Calculate lastCompletedOn based on toDoToday
// Calculate lastCompletedOn so the next due date lands correctly
let lastCompletedOn: Date | null = null;
if (!toDoToday && doesRepeat && repeatsEvery) {
// Set it in the future so it doesn't appear as due today
if (doesRepeat && repeatsEvery) {
const [amount, unit] = repeatsEvery.split('_');
const days = unit === 'DAYS' ? parseInt(amount) :
unit === 'WEEKS' ? parseInt(amount) * 7 :
unit === 'MONTHS' ? parseInt(amount) * 30 :
parseInt(amount) * 365;
lastCompletedOn = new Date(Date.now() - days * 24 * 60 * 60 * 1000 + 24 * 60 * 60 * 1000);
const msInterval = days * 24 * 60 * 60 * 1000;
if (toDoToday) {
// next due = today: set lastCompletedOn = now - interval
lastCompletedOn = new Date(Date.now() - msInterval);
} else {
// next due = tomorrow: set lastCompletedOn = now - interval + 1 day
lastCompletedOn = new Date(Date.now() - msInterval + 24 * 60 * 60 * 1000);
}
}
const [newTask] = await db.insert(tasks).values({

View File

@ -112,7 +112,7 @@ export default function CreateTaskForm({ onCreateTask }: CreateTaskFormProps) {
)}
<div className="form-group">
<label>To do today?</label>
<label>To do right now?</label>
<div className="radio-group">
<label>
<input