From 8741a27ad1ee994de9f688b746addc2924021898 Mon Sep 17 00:00:00 2001 From: Samir Khairati Date: Tue, 16 Jul 2024 23:02:22 +0530 Subject: [PATCH 01/15] fix: announcements.sort is not a function error when announcements is being returned as an error --- frontend/src/components/announcements.tsx | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/frontend/src/components/announcements.tsx b/frontend/src/components/announcements.tsx index 68558b65..73b63e89 100644 --- a/frontend/src/components/announcements.tsx +++ b/frontend/src/components/announcements.tsx @@ -11,7 +11,7 @@ import axios from "axios"; import { DialogTrigger } from "@radix-ui/react-dialog"; import { Megaphone } from "lucide-react"; import type { z } from "zod"; -import type { announcementType } from "../../../lib/src"; +import { announcementType } from "../../../lib/src"; import { Button } from "./ui/button"; const fetchAnnouncements = async (): Promise< @@ -42,13 +42,12 @@ function Announcements() {
- {announcements?.length ? ( - announcements - .sort( - (a, b) => - new Date(a.createdAt as string).getTime() - - new Date(b.createdAt as string).getTime(), - ) + {Array.isArray(announcements) && announcements?.length ? ( + announcements?.sort( + (a, b) => + new Date(a.createdAt as string).getTime() - + new Date(b.createdAt as string).getTime(), + ) .map((announcement) => (

From 326bfd7f7306d54ec3fd131f35ae9c95cbfc4598 Mon Sep 17 00:00:00 2001 From: Samir Khairati Date: Tue, 16 Jul 2024 23:02:53 +0530 Subject: [PATCH 02/15] feat: disable edit and copy buttons for viewing archived timetables --- frontend/src/ViewTimetable.tsx | 130 +++++++++++++++++---------------- 1 file changed, 67 insertions(+), 63 deletions(-) diff --git a/frontend/src/ViewTimetable.tsx b/frontend/src/ViewTimetable.tsx index 15e36ed4..416a0542 100644 --- a/frontend/src/ViewTimetable.tsx +++ b/frontend/src/ViewTimetable.tsx @@ -602,6 +602,8 @@ function ViewTimetable() { let cdcs: string[]; const coursesList = []; + console.log(timetableQueryResult.data); + if ( timetableQueryResult.data === undefined || courseQueryResult.data === undefined @@ -612,8 +614,8 @@ function ViewTimetable() { timetableQueryResult.data.degrees.length === 1 ? timetableQueryResult.data.degrees[0] : timetableQueryResult.data.degrees - .sort((a, b) => (b as any) - (a as any)) - .join("") + .sort((a, b) => (b as any) - (a as any)) + .join("") ) as keyof typeof CDCList; const cdcListKey = `${timetableQueryResult.data.year}-${timetableQueryResult.data.semester}` as keyof (typeof CDCList)[typeof degree]; @@ -909,30 +911,32 @@ function ViewTimetable() { )} {userQueryResult.data.id === timetableQueryResult.data.authorId && ( - - - - - -

Edit Timetable

-
-
- )} + + + + + +

Edit Timetable

+
+
+ )} - - - -

Delete Timetable

-
-
- - - - Are you sure? - - - All your progress on this timetable will be lost, and - unrecoverable. - - - - Cancel - - - - - - - )} + + + + + + + + +

Delete Timetable

+
+
+ + + + Are you sure? + + + All your progress on this timetable will be lost, and + unrecoverable. + + + + Cancel + + + + + +
+ )}

{/* the bg-background here is necessary so the generated image has the background in it */} From 446f669a5bb56784d5e173216e9708aed3cb805a Mon Sep 17 00:00:00 2001 From: Samir Khairati Date: Tue, 16 Jul 2024 23:04:58 +0530 Subject: [PATCH 03/15] feat: disable copying while editing archived timetables --- frontend/src/EditTimetable.tsx | 115 ++++++++++++++++----------------- 1 file changed, 57 insertions(+), 58 deletions(-) diff --git a/frontend/src/EditTimetable.tsx b/frontend/src/EditTimetable.tsx index e23762a7..f93cac94 100644 --- a/frontend/src/EditTimetable.tsx +++ b/frontend/src/EditTimetable.tsx @@ -475,8 +475,8 @@ function EditTimetable() { timetableQueryResult.data.degrees.length === 1 ? timetableQueryResult.data.degrees[0] : timetableQueryResult.data.degrees - .sort((a, b) => (b as any) - (a as any)) - .join("") + .sort((a, b) => (b as any) - (a as any)) + .join("") ) as keyof typeof CDCList; const cdcListKey = `${timetableQueryResult.data.year}-${timetableQueryResult.data.semester}` as keyof (typeof CDCList)[typeof degree]; @@ -550,19 +550,19 @@ function EditTimetable() { if (cdcs[i].id === null) { const option = cdcs[i] as | { - id: null; - type: "warning"; - warning: string; - } + id: null; + type: "warning"; + warning: string; + } | { - id: null; - type: "optional"; - options: { - id: string; - code: string; - name: string; - }[]; - }; + id: null; + type: "optional"; + options: { + id: string; + code: string; + name: string; + }[]; + }; if ( option.type === "optional" && !option.options.some((e) => @@ -907,6 +907,7 @@ function EditTimetable() { - - - -

Delete Timetable

-
-
- - - - Are you sure? - - - All your progress on this timetable will be lost, and - unrecoverable. - - - - Cancel - - - - - - - )} + + + + + + + + +

Delete Timetable

+
+
+ + + + Are you sure? + + + All your progress on this timetable will be lost, and + unrecoverable. + + + + Cancel + + + + + +
+ )} {timetable.warnings.length !== 0 && ( @@ -990,10 +991,8 @@ function EditTimetable() {
))} {timetable.warnings.length > 2 && - ` and ${ - timetable.warnings.length - 2 - } other warning${ - timetable.warnings.length > 3 ? "s" : "" + ` and ${timetable.warnings.length - 2 + } other warning${timetable.warnings.length > 3 ? "s" : "" }`} From a0eff40f6a11a0dca4ed50c7a81d8241d14358b0 Mon Sep 17 00:00:00 2001 From: Samir Khairati Date: Tue, 16 Jul 2024 23:29:30 +0530 Subject: [PATCH 04/15] fix: remove zod field type minimum 4 characters validation for consistency in error messages --- lib/src/zodFieldTypes.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/src/zodFieldTypes.ts b/lib/src/zodFieldTypes.ts index 116114ba..a8596d60 100644 --- a/lib/src/zodFieldTypes.ts +++ b/lib/src/zodFieldTypes.ts @@ -38,9 +38,9 @@ export const namedTimetableIDType = (name?: string) => invalid_type_error: addNameToString("timetable id not a string", name), required_error: addNameToString("timetable id is required", name), }) - .min(4, { - message: addNameToString("timetable id is an invalid id", name), - }); +// .min(4, { +// message: addNameToString("timetable id is an invalid id", name), +// }); export const timetableIDType = namedTimetableIDType(); From 5baf8763fbc1c5ff76485b3a2d7858a101019a8a Mon Sep 17 00:00:00 2001 From: Samir Khairati Date: Tue, 16 Jul 2024 23:46:39 +0530 Subject: [PATCH 05/15] feat: better NotFound page --- frontend/src/NotFound.tsx | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/frontend/src/NotFound.tsx b/frontend/src/NotFound.tsx index 8d8675ae..fde3b0e7 100644 --- a/frontend/src/NotFound.tsx +++ b/frontend/src/NotFound.tsx @@ -1,11 +1,31 @@ -import { Route } from "@tanstack/react-router"; -import { rootRoute } from "./main"; +import { Route } from '@tanstack/react-router'; +import { rootRoute, router } from "./main"; const notFoundRoute = new Route({ getParentRoute: () => rootRoute, path: "404", component: () => { - return 404: Not Found; + return <> +
+

404

+
+ Page Not Found +
+
+
+ + + router.navigate({ to: "/" })} className="cursor-pointer relative block px-8 py-3 bg-[#1A2238] border border-current"> + GO HOME + +
+
+
+ }, }); From edc87a08352088cdac9d6f6d356b707d40b0bb75 Mon Sep 17 00:00:00 2001 From: Samir Khairati Date: Wed, 17 Jul 2024 00:19:56 +0530 Subject: [PATCH 06/15] fix: color changes in NotFound.tsx --- frontend/src/NotFound.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/src/NotFound.tsx b/frontend/src/NotFound.tsx index fde3b0e7..55f13dc4 100644 --- a/frontend/src/NotFound.tsx +++ b/frontend/src/NotFound.tsx @@ -6,7 +6,7 @@ const notFoundRoute = new Route({ path: "404", component: () => { return <> -
+

404

Page Not Found From 29b511d7663c0e3d50aecf8d4a90f2bf7718a20f Mon Sep 17 00:00:00 2001 From: Samir Khairati Date: Wed, 17 Jul 2024 00:20:16 +0530 Subject: [PATCH 07/15] feat: navigate to NotFound page on 404 error --- frontend/src/EditTimetable.tsx | 1 + frontend/src/ViewTimetable.tsx | 1 + 2 files changed, 2 insertions(+) diff --git a/frontend/src/EditTimetable.tsx b/frontend/src/EditTimetable.tsx index f93cac94..4bba943d 100644 --- a/frontend/src/EditTimetable.tsx +++ b/frontend/src/EditTimetable.tsx @@ -173,6 +173,7 @@ const editTimetableRoute = new Route({ ), }); + router.navigate({ to: "/404" }); break; case 500: toast({ diff --git a/frontend/src/ViewTimetable.tsx b/frontend/src/ViewTimetable.tsx index 416a0542..15225b25 100644 --- a/frontend/src/ViewTimetable.tsx +++ b/frontend/src/ViewTimetable.tsx @@ -157,6 +157,7 @@ const viewTimetableRoute = new Route({ if (error.response) { switch (error.response.status) { case 404: + router.navigate({ to: "/404" }); toast({ title: "Error", description: From b390f748ba24e6af215e31f56c51840d31f8d8ae Mon Sep 17 00:00:00 2001 From: skoriop Date: Wed, 17 Jul 2024 13:41:53 +0530 Subject: [PATCH 08/15] feat: extract NotFound into component --- frontend/src/NotFound.tsx | 27 +++------------------------ frontend/src/components/NotFound.tsx | 24 ++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 24 deletions(-) create mode 100644 frontend/src/components/NotFound.tsx diff --git a/frontend/src/NotFound.tsx b/frontend/src/NotFound.tsx index 55f13dc4..98ffd0e9 100644 --- a/frontend/src/NotFound.tsx +++ b/frontend/src/NotFound.tsx @@ -1,32 +1,11 @@ import { Route } from '@tanstack/react-router'; -import { rootRoute, router } from "./main"; +import { rootRoute } from "./main"; +import NotFound from './components/NotFound'; const notFoundRoute = new Route({ getParentRoute: () => rootRoute, path: "404", - component: () => { - return <> -
-

404

-
- Page Not Found -
-
-
- - - router.navigate({ to: "/" })} className="cursor-pointer relative block px-8 py-3 bg-[#1A2238] border border-current"> - GO HOME - -
-
-
- - }, + component: () => }); export default notFoundRoute; diff --git a/frontend/src/components/NotFound.tsx b/frontend/src/components/NotFound.tsx new file mode 100644 index 00000000..207e1d9f --- /dev/null +++ b/frontend/src/components/NotFound.tsx @@ -0,0 +1,24 @@ +import { router } from "../main"; + +const NotFound = () => +
+

404

+
+ Page Not Found +
+
+
+ + + router.navigate({ to: "/" })} className="cursor-pointer relative block px-8 py-3 bg-[#1A2238] border border-current"> + GO HOME + +
+
+
+ +export default NotFound; \ No newline at end of file From 4792985e23c9fc46d94df03f082b7f05d0f83c5e Mon Sep 17 00:00:00 2001 From: skoriop Date: Wed, 17 Jul 2024 13:45:08 +0530 Subject: [PATCH 09/15] feat: use NotFound component instead of route --- frontend/src/NotFound.tsx | 11 ----------- frontend/src/main.tsx | 4 ++-- 2 files changed, 2 insertions(+), 13 deletions(-) delete mode 100644 frontend/src/NotFound.tsx diff --git a/frontend/src/NotFound.tsx b/frontend/src/NotFound.tsx deleted file mode 100644 index 98ffd0e9..00000000 --- a/frontend/src/NotFound.tsx +++ /dev/null @@ -1,11 +0,0 @@ -import { Route } from '@tanstack/react-router'; -import { rootRoute } from "./main"; -import NotFound from './components/NotFound'; - -const notFoundRoute = new Route({ - getParentRoute: () => rootRoute, - path: "404", - component: () => -}); - -export default notFoundRoute; diff --git a/frontend/src/main.tsx b/frontend/src/main.tsx index b2aaa51e..afffc5fe 100644 --- a/frontend/src/main.tsx +++ b/frontend/src/main.tsx @@ -19,7 +19,7 @@ import finalizeTimetableRoute from "./FinalizeTimetable"; import getDegreesRoute from "./GetDegrees"; import homeRoute from "./Home"; import loginRoute from "./Login"; -import notFoundRoute from "./NotFound"; +import NotFound from "./components/NotFound"; import RootComponent from "./RootComponent"; import viewTimetableRoute from "./ViewTimetable"; import "./index.css"; @@ -63,7 +63,7 @@ export const router = new Router({ context: { queryClient, }, - notFoundRoute: notFoundRoute, + defaultNotFoundComponent: NotFound }); // Register things for typesafety From d47db0044b5e4552dc20b8b5524b98c3bdb6f123 Mon Sep 17 00:00:00 2001 From: skoriop Date: Wed, 17 Jul 2024 13:57:58 +0530 Subject: [PATCH 10/15] feat: use the `notFound` function to render the `NotFound` component --- frontend/src/EditTimetable.tsx | 144 ++++++++++++++---------------- frontend/src/ViewTimetable.tsx | 158 ++++++++++++++++----------------- 2 files changed, 144 insertions(+), 158 deletions(-) diff --git a/frontend/src/EditTimetable.tsx b/frontend/src/EditTimetable.tsx index 4bba943d..c4641fad 100644 --- a/frontend/src/EditTimetable.tsx +++ b/frontend/src/EditTimetable.tsx @@ -13,7 +13,7 @@ import { useQuery, useQueryClient, } from "@tanstack/react-query"; -import { ErrorComponent, Route } from "@tanstack/react-router"; +import { ErrorComponent, Route, notFound } from "@tanstack/react-router"; import axios, { AxiosError } from "axios"; import { AlertOctagon, @@ -36,6 +36,7 @@ import { } from "../../lib/src"; import { userWithTimetablesType } from "../../lib/src/index"; import authenticatedRoute from "./AuthenticatedRoute"; +import NotFound from "./components/NotFound"; import { TimetableGrid } from "./components/TimetableGrid"; import { SideMenu } from "./components/side-menu"; import Spinner from "./components/spinner"; @@ -148,33 +149,24 @@ const editTimetableRoute = new Route({ }); } + if ( + error instanceof AxiosError && + error.response && + error.response.status === 404 + ) { + throw notFound(); + } + throw error; }), component: EditTimetable, + notFoundComponent: NotFound, errorComponent: ({ error }) => { const { toast } = useToast(); if (error instanceof AxiosError) { if (error.response) { switch (error.response.status) { - case 404: - toast({ - title: "Error", - description: - "message" in error.response.data - ? error.response.data.message - : "API returned 404", - variant: "destructive", - action: ( - - - Report - - - ), - }); - router.navigate({ to: "/404" }); - break; case 500: toast({ title: "Server Error", @@ -476,8 +468,8 @@ function EditTimetable() { timetableQueryResult.data.degrees.length === 1 ? timetableQueryResult.data.degrees[0] : timetableQueryResult.data.degrees - .sort((a, b) => (b as any) - (a as any)) - .join("") + .sort((a, b) => (b as any) - (a as any)) + .join("") ) as keyof typeof CDCList; const cdcListKey = `${timetableQueryResult.data.year}-${timetableQueryResult.data.semester}` as keyof (typeof CDCList)[typeof degree]; @@ -551,19 +543,19 @@ function EditTimetable() { if (cdcs[i].id === null) { const option = cdcs[i] as | { - id: null; - type: "warning"; - warning: string; - } + id: null; + type: "warning"; + warning: string; + } | { - id: null; - type: "optional"; - options: { - id: string; - code: string; - name: string; - }[]; - }; + id: null; + type: "optional"; + options: { + id: string; + code: string; + name: string; + }[]; + }; if ( option.type === "optional" && !option.options.some((e) => @@ -930,46 +922,46 @@ function EditTimetable() { {userQueryResult.data.id === timetableQueryResult.data.authorId && ( - - - - - - - - -

Delete Timetable

-
-
- - - - Are you sure? - - - All your progress on this timetable will be lost, and - unrecoverable. - - - - Cancel - - - - - -
- )} + + + + + + + + +

Delete Timetable

+
+
+ + + + Are you sure? + + + All your progress on this timetable will be lost, and + unrecoverable. + + + + Cancel + + + + + +
+ )} {timetable.warnings.length !== 0 && ( @@ -992,8 +984,10 @@ function EditTimetable() {
))} {timetable.warnings.length > 2 && - ` and ${timetable.warnings.length - 2 - } other warning${timetable.warnings.length > 3 ? "s" : "" + ` and ${ + timetable.warnings.length - 2 + } other warning${ + timetable.warnings.length > 3 ? "s" : "" }`} diff --git a/frontend/src/ViewTimetable.tsx b/frontend/src/ViewTimetable.tsx index 15225b25..95adc102 100644 --- a/frontend/src/ViewTimetable.tsx +++ b/frontend/src/ViewTimetable.tsx @@ -7,7 +7,7 @@ import { useQuery, useQueryClient, } from "@tanstack/react-query"; -import { ErrorComponent, Route } from "@tanstack/react-router"; +import { ErrorComponent, Route, notFound } from "@tanstack/react-router"; import axios, { AxiosError } from "axios"; import { toPng } from "html-to-image"; import { @@ -29,6 +29,7 @@ import { } from "../../lib/src/index"; import { userWithTimetablesType } from "../../lib/src/index"; import authenticatedRoute from "./AuthenticatedRoute"; +import NotFound from "./components/NotFound"; import { TimetableGrid } from "./components/TimetableGrid"; import { SideMenu } from "./components/side-menu"; import Spinner from "./components/spinner"; @@ -147,33 +148,24 @@ const viewTimetableRoute = new Route({ }); } + if ( + error instanceof AxiosError && + error.response && + error.response.status === 404 + ) { + throw notFound(); + } + throw error; }), component: ViewTimetable, + notFoundComponent: NotFound, errorComponent: ({ error }) => { const { toast } = useToast(); if (error instanceof AxiosError) { if (error.response) { switch (error.response.status) { - case 404: - router.navigate({ to: "/404" }); - toast({ - title: "Error", - description: - "message" in error.response.data - ? error.response.data.message - : "API returned 404", - variant: "destructive", - action: ( - - - Report - - - ), - }); - break; case 500: toast({ title: "Server Error", @@ -615,8 +607,8 @@ function ViewTimetable() { timetableQueryResult.data.degrees.length === 1 ? timetableQueryResult.data.degrees[0] : timetableQueryResult.data.degrees - .sort((a, b) => (b as any) - (a as any)) - .join("") + .sort((a, b) => (b as any) - (a as any)) + .join("") ) as keyof typeof CDCList; const cdcListKey = `${timetableQueryResult.data.year}-${timetableQueryResult.data.semester}` as keyof (typeof CDCList)[typeof degree]; @@ -912,28 +904,28 @@ function ViewTimetable() { )} {userQueryResult.data.id === timetableQueryResult.data.authorId && ( - - - - - -

Edit Timetable

-
-
- )} + + + + + +

Edit Timetable

+
+
+ )} - - - -

Delete Timetable

-
-
- - - - Are you sure? - - - All your progress on this timetable will be lost, and - unrecoverable. - - - - Cancel - - - - - - - )} + + + + + + + + +

Delete Timetable

+
+
+ + + + Are you sure? + + + All your progress on this timetable will be lost, and + unrecoverable. + + + + Cancel + + + + + +
+ )}
{/* the bg-background here is necessary so the generated image has the background in it */} From e6a626152e94e9b94890d1a02a6a6fc7a30b0f15 Mon Sep 17 00:00:00 2001 From: skoriop Date: Wed, 17 Jul 2024 13:58:35 +0530 Subject: [PATCH 11/15] style: lint with biome --- frontend/src/components/NotFound.tsx | 38 +++++++++++------------ frontend/src/components/announcements.tsx | 11 ++++--- frontend/src/main.tsx | 4 +-- 3 files changed, 27 insertions(+), 26 deletions(-) diff --git a/frontend/src/components/NotFound.tsx b/frontend/src/components/NotFound.tsx index 207e1d9f..328ed192 100644 --- a/frontend/src/components/NotFound.tsx +++ b/frontend/src/components/NotFound.tsx @@ -1,24 +1,24 @@ import { router } from "../main"; -const NotFound = () => -
-

404

-
- Page Not Found -
-
-
- +const NotFound = () => ( +
+

404

+
+ Page Not Found +
+
+
+ - router.navigate({ to: "/" })} className="cursor-pointer relative block px-8 py-3 bg-[#1A2238] border border-current"> - GO HOME - -
-
+ router.navigate({ to: "/" })} + className="cursor-pointer relative block px-8 py-3 bg-[#1A2238] border border-current" + > + GO HOME + +
+
+); -export default NotFound; \ No newline at end of file +export default NotFound; diff --git a/frontend/src/components/announcements.tsx b/frontend/src/components/announcements.tsx index 73b63e89..1d722bfc 100644 --- a/frontend/src/components/announcements.tsx +++ b/frontend/src/components/announcements.tsx @@ -43,11 +43,12 @@ function Announcements() {
{Array.isArray(announcements) && announcements?.length ? ( - announcements?.sort( - (a, b) => - new Date(a.createdAt as string).getTime() - - new Date(b.createdAt as string).getTime(), - ) + announcements + ?.sort( + (a, b) => + new Date(a.createdAt as string).getTime() - + new Date(b.createdAt as string).getTime(), + ) .map((announcement) => (

diff --git a/frontend/src/main.tsx b/frontend/src/main.tsx index afffc5fe..c07f1d7d 100644 --- a/frontend/src/main.tsx +++ b/frontend/src/main.tsx @@ -19,9 +19,9 @@ import finalizeTimetableRoute from "./FinalizeTimetable"; import getDegreesRoute from "./GetDegrees"; import homeRoute from "./Home"; import loginRoute from "./Login"; -import NotFound from "./components/NotFound"; import RootComponent from "./RootComponent"; import viewTimetableRoute from "./ViewTimetable"; +import NotFound from "./components/NotFound"; import "./index.css"; const queryClient = new QueryClient({ @@ -63,7 +63,7 @@ export const router = new Router({ context: { queryClient, }, - defaultNotFoundComponent: NotFound + defaultNotFoundComponent: NotFound, }); // Register things for typesafety From 961952a29054c3f40f98f3397da205f80a6f6cd5 Mon Sep 17 00:00:00 2001 From: Samir Khairati Date: Wed, 17 Jul 2024 20:46:29 +0530 Subject: [PATCH 12/15] feat: Show not-allowed cursor + tooltip for editing/copying archived timetables --- frontend/src/EditTimetable.tsx | 124 ++++++++++++++-------------- frontend/src/ViewTimetable.tsx | 144 ++++++++++++++++++--------------- 2 files changed, 141 insertions(+), 127 deletions(-) diff --git a/frontend/src/EditTimetable.tsx b/frontend/src/EditTimetable.tsx index c4641fad..a52e5d73 100644 --- a/frontend/src/EditTimetable.tsx +++ b/frontend/src/EditTimetable.tsx @@ -468,8 +468,8 @@ function EditTimetable() { timetableQueryResult.data.degrees.length === 1 ? timetableQueryResult.data.degrees[0] : timetableQueryResult.data.degrees - .sort((a, b) => (b as any) - (a as any)) - .join("") + .sort((a, b) => (b as any) - (a as any)) + .join("") ) as keyof typeof CDCList; const cdcListKey = `${timetableQueryResult.data.year}-${timetableQueryResult.data.semester}` as keyof (typeof CDCList)[typeof degree]; @@ -543,19 +543,19 @@ function EditTimetable() { if (cdcs[i].id === null) { const option = cdcs[i] as | { - id: null; - type: "warning"; - warning: string; - } + id: null; + type: "warning"; + warning: string; + } | { - id: null; - type: "optional"; - options: { - id: string; - code: string; - name: string; - }[]; - }; + id: null; + type: "optional"; + options: { + id: string; + code: string; + name: string; + }[]; + }; if ( option.type === "optional" && !option.options.some((e) => @@ -898,7 +898,7 @@ function EditTimetable() { )} - + - - - -

Delete Timetable

-
-
- - - - Are you sure? - - - All your progress on this timetable will be lost, and - unrecoverable. - - - - Cancel - - - - - - - )} + + + + + + + + +

Delete Timetable

+
+
+ + + + Are you sure? + + + All your progress on this timetable will be lost, and + unrecoverable. + + + + Cancel + + + + + +
+ )} {timetable.warnings.length !== 0 && ( @@ -984,10 +990,8 @@ function EditTimetable() {

))} {timetable.warnings.length > 2 && - ` and ${ - timetable.warnings.length - 2 - } other warning${ - timetable.warnings.length > 3 ? "s" : "" + ` and ${timetable.warnings.length - 2 + } other warning${timetable.warnings.length > 3 ? "s" : "" }`} diff --git a/frontend/src/ViewTimetable.tsx b/frontend/src/ViewTimetable.tsx index 95adc102..b58010bd 100644 --- a/frontend/src/ViewTimetable.tsx +++ b/frontend/src/ViewTimetable.tsx @@ -595,8 +595,6 @@ function ViewTimetable() { let cdcs: string[]; const coursesList = []; - console.log(timetableQueryResult.data); - if ( timetableQueryResult.data === undefined || courseQueryResult.data === undefined @@ -607,8 +605,8 @@ function ViewTimetable() { timetableQueryResult.data.degrees.length === 1 ? timetableQueryResult.data.degrees[0] : timetableQueryResult.data.degrees - .sort((a, b) => (b as any) - (a as any)) - .join("") + .sort((a, b) => (b as any) - (a as any)) + .join("") ) as keyof typeof CDCList; const cdcListKey = `${timetableQueryResult.data.year}-${timetableQueryResult.data.semester}` as keyof (typeof CDCList)[typeof degree]; @@ -904,30 +902,36 @@ function ViewTimetable() { )} {userQueryResult.data.id === timetableQueryResult.data.authorId && ( - - - + + + { + timetableQueryResult.data.archived ? ( +

Cannot edit archived timetable

+ ) : ( +

Edit Timetable

+ ) } - > - - - - -

Edit Timetable

-
-
- )} + + + )} - + - - - -

Delete Timetable

-
-
- - - - Are you sure? - - - All your progress on this timetable will be lost, and - unrecoverable. - - - - Cancel - - - - - - - )} + + + + + + + + +

Delete Timetable

+
+
+ + + + Are you sure? + + + All your progress on this timetable will be lost, and + unrecoverable. + + + + Cancel + + + + + +
+ )}
{/* the bg-background here is necessary so the generated image has the background in it */} From 7f7eebd7b95253471dd367d8bb7c5d9bad4ee792 Mon Sep 17 00:00:00 2001 From: Samir Khairati Date: Wed, 17 Jul 2024 23:08:00 +0530 Subject: [PATCH 13/15] fix: remove the go home button, make the NotFound component fit in the remaining screen height --- frontend/src/components/NotFound.tsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/frontend/src/components/NotFound.tsx b/frontend/src/components/NotFound.tsx index 328ed192..3bde8fd6 100644 --- a/frontend/src/components/NotFound.tsx +++ b/frontend/src/components/NotFound.tsx @@ -1,7 +1,7 @@ import { router } from "../main"; const NotFound = () => ( -
+

404

Page Not Found @@ -10,12 +10,12 @@ const NotFound = () => (
- router.navigate({ to: "/" })} className="cursor-pointer relative block px-8 py-3 bg-[#1A2238] border border-current" > GO HOME - + */}
From 0bde73729cba9b0a95c07769a638cc5cd71df25b Mon Sep 17 00:00:00 2001 From: skoriop Date: Wed, 17 Jul 2024 23:33:35 +0530 Subject: [PATCH 14/15] fix: fix tooltip classnames if the timetable is not archived, the `&&` will result in `false`, which is not a Tailwind class that we want to be applying. --- frontend/src/EditTimetable.tsx | 134 ++++++++++++++------------- frontend/src/ViewTimetable.tsx | 162 +++++++++++++++++---------------- 2 files changed, 155 insertions(+), 141 deletions(-) diff --git a/frontend/src/EditTimetable.tsx b/frontend/src/EditTimetable.tsx index a52e5d73..0e94bca0 100644 --- a/frontend/src/EditTimetable.tsx +++ b/frontend/src/EditTimetable.tsx @@ -468,8 +468,8 @@ function EditTimetable() { timetableQueryResult.data.degrees.length === 1 ? timetableQueryResult.data.degrees[0] : timetableQueryResult.data.degrees - .sort((a, b) => (b as any) - (a as any)) - .join("") + .sort((a, b) => (b as any) - (a as any)) + .join("") ) as keyof typeof CDCList; const cdcListKey = `${timetableQueryResult.data.year}-${timetableQueryResult.data.semester}` as keyof (typeof CDCList)[typeof degree]; @@ -543,19 +543,19 @@ function EditTimetable() { if (cdcs[i].id === null) { const option = cdcs[i] as | { - id: null; - type: "warning"; - warning: string; - } + id: null; + type: "warning"; + warning: string; + } | { - id: null; - type: "optional"; - options: { - id: string; - code: string; - name: string; - }[]; - }; + id: null; + type: "optional"; + options: { + id: string; + code: string; + name: string; + }[]; + }; if ( option.type === "optional" && !option.options.some((e) => @@ -898,7 +898,13 @@ function EditTimetable() { )} - + - - - -

Delete Timetable

-
-
- - - - Are you sure? - - - All your progress on this timetable will be lost, and - unrecoverable. - - - - Cancel - - - - - - - )} + + + + + + + + +

Delete Timetable

+
+
+ + + + Are you sure? + + + All your progress on this timetable will be lost, and + unrecoverable. + + + + Cancel + + + + + +
+ )} {timetable.warnings.length !== 0 && ( @@ -990,8 +994,10 @@ function EditTimetable() {
))} {timetable.warnings.length > 2 && - ` and ${timetable.warnings.length - 2 - } other warning${timetable.warnings.length > 3 ? "s" : "" + ` and ${ + timetable.warnings.length - 2 + } other warning${ + timetable.warnings.length > 3 ? "s" : "" }`} diff --git a/frontend/src/ViewTimetable.tsx b/frontend/src/ViewTimetable.tsx index b58010bd..6716292d 100644 --- a/frontend/src/ViewTimetable.tsx +++ b/frontend/src/ViewTimetable.tsx @@ -605,8 +605,8 @@ function ViewTimetable() { timetableQueryResult.data.degrees.length === 1 ? timetableQueryResult.data.degrees[0] : timetableQueryResult.data.degrees - .sort((a, b) => (b as any) - (a as any)) - .join("") + .sort((a, b) => (b as any) - (a as any)) + .join("") ) as keyof typeof CDCList; const cdcListKey = `${timetableQueryResult.data.year}-${timetableQueryResult.data.semester}` as keyof (typeof CDCList)[typeof degree]; @@ -902,36 +902,46 @@ function ViewTimetable() { )} {userQueryResult.data.id === timetableQueryResult.data.authorId && ( - - - - - - { - timetableQueryResult.data.archived ? ( -

Cannot edit archived timetable

- ) : ( -

Edit Timetable

- ) + + + + + +

+ {timetableQueryResult.data.archived + ? "Cannot edit archived timetable" + : "Edit Timetable"} +

+
+
+ )} - + - - - -

Delete Timetable

-
-
- - - - Are you sure? - - - All your progress on this timetable will be lost, and - unrecoverable. - - - - Cancel - - - - - - - )} + + + + + + + + +

Delete Timetable

+
+
+ + + + Are you sure? + + + All your progress on this timetable will be lost, and + unrecoverable. + + + + Cancel + + + + + +
+ )}
{/* the bg-background here is necessary so the generated image has the background in it */} From dd83b9962f396458921aec25cdf1a084fb49d86f Mon Sep 17 00:00:00 2001 From: skoriop Date: Wed, 17 Jul 2024 23:37:34 +0530 Subject: [PATCH 15/15] fix: fix endpoint path not sure why this sometimes works and sometimes doesn't --- frontend/src/components/announcements.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/src/components/announcements.tsx b/frontend/src/components/announcements.tsx index 1d722bfc..f2e26a8c 100644 --- a/frontend/src/components/announcements.tsx +++ b/frontend/src/components/announcements.tsx @@ -18,7 +18,7 @@ const fetchAnnouncements = async (): Promise< z.infer[] > => { const response = await axios.get[]>( - "api/user/announcements", + "/api/user/announcements", ); return response.data; };