From 70a5d89d3fb41658e1944c0792387b981b40d6c1 Mon Sep 17 00:00:00 2001 From: TobbleCobble Date: Sat, 10 Jan 2026 06:26:53 +0000 Subject: [PATCH] use env variable for api calls --- client/src/components/task_form.tsx | 35 ++++++++++++++++------------- client/src/components/task_item.tsx | 4 ++-- client/src/pages/focus.tsx | 4 ++-- client/src/pages/login.tsx | 25 ++++++++++++--------- client/src/pages/register.tsx | 21 +++++++++-------- client/src/pages/schedule.tsx | 4 ++-- client/src/pages/tasks.tsx | 11 ++++----- docker-compose.prod.yml | 4 ++-- 8 files changed, 59 insertions(+), 49 deletions(-) diff --git a/client/src/components/task_form.tsx b/client/src/components/task_form.tsx index 7c6b567..54fd548 100644 --- a/client/src/components/task_form.tsx +++ b/client/src/components/task_form.tsx @@ -43,7 +43,7 @@ export function TaskForm({ userId, onTaskCreated }: TaskFormProps) { const [availableTopics, setAvailableTopics] = useState([]); useEffect(() => { - fetch("http://localhost:8000/api/planner/topic/") + fetch(process.env.NEXT_PUBLIC_BACKEND_URL + "planner/topic/") .then((res) => res.json()) .then((data) => setAvailableTopics(data)) .catch((err) => console.error("Failed to load topics:", err)); @@ -66,22 +66,25 @@ 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 response = await fetch("http://localhost:8000/api/planner/tasks/", { - method: "POST", - headers: { - "Content-Type": "application/json", - Authorization: `Bearer ${token}`, + const response = await fetch( + process.env.NEXT_PUBLIC_BACKEND_URL + "planner/tasks/", + { + method: "POST", + headers: { + "Content-Type": "application/json", + Authorization: `Bearer ${token}`, + }, + body: JSON.stringify({ + name: taskName, + description: description, + completed: false, + user_id: userId, + times: times, + existing_topic_ids: existing_topic_ids, + new_topics: new_topics, + }), }, - body: JSON.stringify({ - name: taskName, - description: description, - completed: false, - user_id: userId, - times: times, - existing_topic_ids: existing_topic_ids, - new_topics: new_topics, - }), - }); + ); if (!response.ok) { throw new Error("Failed to create task"); diff --git a/client/src/components/task_item.tsx b/client/src/components/task_item.tsx index aff4740..34e9760 100644 --- a/client/src/components/task_item.tsx +++ b/client/src/components/task_item.tsx @@ -98,7 +98,7 @@ export function TaskItem({ })); const response = await fetch( - `http://localhost:8000/api/planner/tasks/${item.id}/`, + process.env.NEXT_PUBLIC_BACKEND_URL + `planner/tasks/${item.id}/`, { method: "PUT", headers: { @@ -234,7 +234,7 @@ export function TaskItem({
{isEditing ? ( -
+