From 1d59eba8b8055e7744f5b76f5e9a9f86cf3df328 Mon Sep 17 00:00:00 2001
From: Precipicee <23813728@student.uwa.edu.au>
Date: Sat, 10 Jan 2026 00:21:42 +0800
Subject: [PATCH 1/2] fixed empty time input
---
client/src/components/task_form.tsx | 5 ++-
client/src/components/task_item.tsx | 4 +-
client/src/components/time_input.tsx | 55 ++++++++++++++--------------
3 files changed, 35 insertions(+), 29 deletions(-)
diff --git a/client/src/components/task_form.tsx b/client/src/components/task_form.tsx
index 96b8171..e06834a 100644
--- a/client/src/components/task_form.tsx
+++ b/client/src/components/task_form.tsx
@@ -66,6 +66,9 @@ export function TaskForm({ userId, onTaskCreated }: TaskFormProps) {
const new_topics = topics
.filter((t) => t.type === "new")
.map((t) => ({ name: t.name, color_hex: t.color_hex }));
+
+ const validTimes = times.filter(t => t.start_time && t.end_time);
+
const response = await fetch("http://localhost:8000/api/planner/tasks/", {
method: "POST",
headers: {
@@ -77,7 +80,7 @@ export function TaskForm({ userId, onTaskCreated }: TaskFormProps) {
description: description,
completed: false,
user_id: userId,
- times: times,
+ times: validTimes,
existing_topic_ids: existing_topic_ids,
new_topics: new_topics,
}),
diff --git a/client/src/components/task_item.tsx b/client/src/components/task_item.tsx
index b2d0208..e4e645c 100644
--- a/client/src/components/task_item.tsx
+++ b/client/src/components/task_item.tsx
@@ -93,6 +93,8 @@ export function TaskItem({
color_hex: t.color_hex,
}));
+ const validTimes = draftTimes.filter(t => t.start_time && t.end_time);
+
const response = await fetch(
`http://localhost:8000/api/planner/tasks/${item.id}/`,
{
@@ -107,7 +109,7 @@ export function TaskItem({
completed: item.completed,
existing_topic_ids: existing_topic_ids,
new_topics: new_topics,
- times: draftTimes,
+ times: validTimes,
}),
},
);
diff --git a/client/src/components/time_input.tsx b/client/src/components/time_input.tsx
index 30eb937..7cb5020 100644
--- a/client/src/components/time_input.tsx
+++ b/client/src/components/time_input.tsx
@@ -22,17 +22,35 @@ const daysOfWeek = [
];
export function TimeInput({ times, setTimes }: TimeInputProps) {
+
+ const addTime = () => {
+ // Add a new empty draft time only if there isn't already an empty one
+ const hasEmpty = times.some(t => !t.start_time || !t.end_time);
+ if (!hasEmpty) {
+ setTimes([
+ ...times,
+ { id: 0, day: 1, start_time: "", end_time: "", repeating: false },
+ ]);
+ }
+ };
+
+ const updateTime = (index: number, field: keyof Time, value: any) => {
+ const newTimes = [...times];
+ newTimes[index] = { ...newTimes[index], [field]: value };
+ setTimes(newTimes);
+ };
+
+ const removeTime = (index: number) => {
+ setTimes(times.filter((_, i) => i !== index));
+ };
+
return (
{times.map((time, index) => (