Skip to content

Commit 6b6c4ba

Browse files
committed
Merge remote-tracking branch 'origin/issue-7-Allow_CRUD_Operations_on_Tasks' into timetable-fixes
2 parents 1e10150 + 169c222 commit 6b6c4ba

3 files changed

Lines changed: 32 additions & 7 deletions

File tree

client/src/components/task_form.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,13 @@ export function TaskForm({ userId, onTaskCreated }: TaskFormProps) {
5151

5252
const handleSubmit = async (e: React.FormEvent) => {
5353
e.preventDefault();
54+
55+
const token = localStorage.getItem("access");
56+
if (!token) {
57+
console.error("No access token");
58+
return;
59+
}
60+
5461
try {
5562
const existing_topic_ids = topics
5663
.filter((t) => t.type === "existing")
@@ -63,6 +70,7 @@ export function TaskForm({ userId, onTaskCreated }: TaskFormProps) {
6370
method: "POST",
6471
headers: {
6572
"Content-Type": "application/json",
73+
Authorization: `Bearer ${token}`,
6674
},
6775
body: JSON.stringify({
6876
name: taskName,

client/src/components/task_item.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@ export function TaskItem({
8282

8383
async function saveEdit() {
8484
setSaving(true);
85+
86+
const token = localStorage.getItem("access");
87+
8588
try {
8689
const existing_topic_ids = draftTopics
8790
.filter((t) => t.type === "existing")
@@ -98,7 +101,10 @@ export function TaskItem({
98101
`http://localhost:8000/api/planner/tasks/${item.id}/`,
99102
{
100103
method: "PUT",
101-
headers: { "Content-Type": "application/json" },
104+
headers: {
105+
"Content-Type": "application/json",
106+
Authorization: `Bearer ${token}`,
107+
},
102108
body: JSON.stringify({
103109
name: draftName,
104110
description: draftDescription,

client/src/pages/tasks.tsx

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ export default function TasksPage() {
4949
router.push("/login"); //redirect to login if unauthorised
5050
return;
5151
}
52-
const auth = await fetch( "http://localhost:8000/api/planner/protected/",
52+
const auth = await fetch(
53+
"http://localhost:8000/api/planner/protected/",
5354
{
5455
headers: {
5556
Authorization: `Bearer ${token}`,
@@ -102,13 +103,16 @@ export default function TasksPage() {
102103
const task = items.find((t) => t.id === id);
103104
if (!task) return;
104105

106+
const token = localStorage.getItem("access");
107+
105108
try {
106109
const response = await fetch(
107110
`http://localhost:8000/api/planner/tasks/${id}/toggle_complete/`,
108111
{
109112
method: "PATCH",
110113
headers: {
111114
"Content-Type": "application/json",
115+
Authorization: `Bearer ${token}`,
112116
},
113117
body: JSON.stringify({ completed: !task.completed }),
114118
},
@@ -135,10 +139,17 @@ export default function TasksPage() {
135139
async function handleTaskDeleted(id: number) {
136140
if (!window.confirm("Delete this task?")) return;
137141

142+
const token = localStorage.getItem("access");
143+
138144
try {
139145
const response = await fetch(
140146
`http://localhost:8000/api/planner/tasks/${id}/`,
141-
{ method: "DELETE" },
147+
{
148+
method: "DELETE",
149+
headers: {
150+
Authorization: `Bearer ${token}`,
151+
},
152+
},
142153
);
143154

144155
if (!response.ok) {
@@ -152,7 +163,7 @@ export default function TasksPage() {
152163
}
153164

154165
return (
155-
<div className="content-container min-w-screen min-h-screen relative flex flex-row items-center justify-center bg-slate-500">
166+
<div className="content-container min-w-screen relative flex min-h-screen flex-row items-center justify-center bg-slate-500">
156167
<div className="task-list-container h-full w-full">
157168
<div className="task-list-content flex h-full w-full flex-col items-center justify-center rounded-lg p-3 text-slate-200">
158169
<div className="task-list-top mb-3 hidden h-[10%] w-full rounded-t-lg">
@@ -163,10 +174,10 @@ export default function TasksPage() {
163174
<div className="task-list-bottom flex w-full flex-row justify-center gap-6">
164175
<div
165176
className="task-list-wrapper flex w-fit flex-row justify-center"
166-
style={{
167-
scrollbarWidth: "thin",
177+
style={{
178+
scrollbarWidth: "thin",
168179
scrollbarColor: "grey white",
169-
display: !(showAddTask && items.length === 0) ? "flex" : "none"
180+
display: !(showAddTask && items.length === 0) ? "flex" : "none",
170181
}}
171182
>
172183
<TaskList

0 commit comments

Comments
 (0)