Skip to content

Commit bd3f1fa

Browse files
committed
timetable page does correct fetch, and pages now have correct height to account for navbar
1 parent 6f39058 commit bd3f1fa

4 files changed

Lines changed: 35 additions & 9 deletions

File tree

client/src/components/timetable.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ function Timetable({ timetable_tasks_props }: TimetableProps) {
374374
>
375375
<div
376376
id="timetable-content"
377-
className="h-full w-full overflow-auto overscroll-none"
377+
className="h-full w-full overflow-auto overscroll-none scrollbar"
378378
onScroll={resizeAndPositionTimetableElements}
379379
>
380380
<div

client/src/pages/focus.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ const CountdownTimer = () => {
152152
}
153153

154154
return (
155-
<div className="h-screen bg-slate-800 p-8 font-inter">
155+
<div className="h-[calc(100vh-64px)] bg-slate-800 p-8 font-inter">
156156
<div className="flex flex-col items-center justify-start rounded-xl bg-slate-700 p-8 font-mono text-white shadow-inner shadow-slate-900">
157157
<p className="p-4 font-inter text-4xl font-semibold">focus</p>
158158
<div className="flex flex-row justify-center">

client/src/pages/schedule.tsx

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import Timetable, {
55
resizeAndPositionTimetableElements,
66
} from "@/components/timetable";
77
import { TimetableTaskProps } from "@/components/timetable_task";
8+
import { useRouter } from "next/router";
89

910
/*
1011
Database representation of Time.
@@ -59,6 +60,8 @@ Page containing a Timetable to visually represent the times that tasks have been
5960
assigned.
6061
*/
6162
function Schedule() {
63+
64+
const router = useRouter();
6265
const [timetableTasksProps, setTimetableTasksProps] = useState<
6366
TimetableTaskProps[]
6467
>([]);
@@ -82,13 +85,35 @@ function Schedule() {
8285
to be displayed. Sets the timetableTasksProps State variable once finished.
8386
*/
8487
async function fetchTasks() {
85-
const API_URL = "http://localhost:8000/api/planner/tasks/";
88+
8689
try {
87-
const response = await fetch(API_URL);
88-
if (!response.ok) {
89-
throw new Error(`Response status: ${response.status}`);
90+
const token = localStorage.getItem("access");
91+
if (!token) {
92+
router.push("/login"); //redirect to login if unauthorised
93+
return;
94+
}
95+
const auth = await fetch(
96+
"http://localhost:8000/api/planner/protected/",
97+
{
98+
headers: {
99+
Authorization: `Bearer ${token}`,
100+
},
101+
},
102+
);
103+
if (!auth.ok) {
104+
router.push("/login"); //redirect to login if unauthorised
105+
return;
90106
}
91-
const data = await response.json();
107+
const tasksFetch = await fetch(
108+
`http://localhost:8000/api/planner/tasks/`,
109+
{
110+
headers: {
111+
Authorization: `Bearer ${token}`,
112+
},
113+
},
114+
);
115+
116+
const data = await tasksFetch.json();
92117
let timetable_task_props =
93118
await formatTaskDataToTimetableTaskProps(data);
94119
timetable_task_props =
@@ -269,12 +294,12 @@ function Schedule() {
269294
return () => {
270295
removeEventListeners();
271296
};
272-
}, []);
297+
}, [router]);
273298
/* This should be dependent on timetableTasksProps however doing so causes it
274299
to run in an infinite loop. */
275300

276301
return (
277-
<div className="content-container min-w-screen min-h-screen flex w-full flex-row bg-slate-950">
302+
<div className="content-container min-w-screen h-[calc(100vh-64px)] flex w-full flex-row bg-slate-950">
278303
<div className="timetable-container max-h-[90vh] w-full p-3">
279304
<Timetable timetable_tasks_props={timetableTasksProps} />
280305
</div>

client/src/styles/globals.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,5 +92,6 @@
9292
@layer base {
9393
body {
9494
@apply bg-background text-foreground;
95+
@apply font-inter;
9596
}
9697
}

0 commit comments

Comments
 (0)