generated from ludops/ludops-skeleton
fix: can create task to do now
Build and Deploy / build-and-push (push) Successful in 1m24s
Details
Build and Deploy / build-and-push (push) Successful in 1m24s
Details
This commit is contained in:
parent
844eb00270
commit
9f03e5bc45
|
|
@ -39,16 +39,22 @@ fastify.post<{ Body: { name: string; doesRepeat: boolean; repeatsEvery?: string;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Calculate lastCompletedOn based on toDoToday
|
// Calculate lastCompletedOn so the next due date lands correctly
|
||||||
let lastCompletedOn: Date | null = null;
|
let lastCompletedOn: Date | null = null;
|
||||||
if (!toDoToday && doesRepeat && repeatsEvery) {
|
if (doesRepeat && repeatsEvery) {
|
||||||
// Set it in the future so it doesn't appear as due today
|
|
||||||
const [amount, unit] = repeatsEvery.split('_');
|
const [amount, unit] = repeatsEvery.split('_');
|
||||||
const days = unit === 'DAYS' ? parseInt(amount) :
|
const days = unit === 'DAYS' ? parseInt(amount) :
|
||||||
unit === 'WEEKS' ? parseInt(amount) * 7 :
|
unit === 'WEEKS' ? parseInt(amount) * 7 :
|
||||||
unit === 'MONTHS' ? parseInt(amount) * 30 :
|
unit === 'MONTHS' ? parseInt(amount) * 30 :
|
||||||
parseInt(amount) * 365;
|
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({
|
const [newTask] = await db.insert(tasks).values({
|
||||||
|
|
|
||||||
|
|
@ -112,7 +112,7 @@ export default function CreateTaskForm({ onCreateTask }: CreateTaskFormProps) {
|
||||||
)}
|
)}
|
||||||
|
|
||||||
<div className="form-group">
|
<div className="form-group">
|
||||||
<label>To do today?</label>
|
<label>To do right now?</label>
|
||||||
<div className="radio-group">
|
<div className="radio-group">
|
||||||
<label>
|
<label>
|
||||||
<input
|
<input
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue