From bf14b915b108596012d963af0c1beef8a903fb06 Mon Sep 17 00:00:00 2001 From: QamarQ Date: Thu, 14 Nov 2024 22:57:21 +0100 Subject: [PATCH] fix: update based on reviewers' suggestions --- frontend/src/app/(homepage)/layout.tsx | 4 +- frontend/src/app/(homepage)/page.tsx | 174 +++++++----------- .../src/app/api/data/[facultyId]/route.ts | 9 +- frontend/src/app/api/profile/route.ts | 14 -- frontend/src/app/layout.tsx | 4 +- .../[id]/_components/CreateNewPlanPage.tsx | 10 +- frontend/src/app/plans/create/[id]/page.tsx | 4 +- frontend/src/app/plans/layout.tsx | 4 +- frontend/src/app/plans/page.tsx | 8 +- .../[id]/_components/SharePlanPage.tsx | 2 +- frontend/src/app/plans/preview/[id]/page.tsx | 4 +- frontend/src/components/GroupsAccordion.tsx | 2 +- frontend/src/components/Plan.tsx | 7 +- frontend/src/components/Providers.tsx | 4 +- frontend/src/components/ui/block.tsx | 39 ++++ frontend/src/components/ui/select.tsx | 4 +- 16 files changed, 143 insertions(+), 150 deletions(-) delete mode 100644 frontend/src/app/api/profile/route.ts create mode 100644 frontend/src/components/ui/block.tsx diff --git a/frontend/src/app/(homepage)/layout.tsx b/frontend/src/app/(homepage)/layout.tsx index b5bd7ca..affae71 100644 --- a/frontend/src/app/(homepage)/layout.tsx +++ b/frontend/src/app/(homepage)/layout.tsx @@ -6,7 +6,9 @@ import { Navbar } from "./_components/navbar"; export default function LayoutHomePage({ children, -}: Readonly<{ children: React.ReactNode }>) { +}: { + children: React.ReactNode; +}) { return (
{/* Blobs */} diff --git a/frontend/src/app/(homepage)/page.tsx b/frontend/src/app/(homepage)/page.tsx index 7187345..6f6d816 100644 --- a/frontend/src/app/(homepage)/page.tsx +++ b/frontend/src/app/(homepage)/page.tsx @@ -1,47 +1,14 @@ -"use client"; - -import { useQuery } from "@tanstack/react-query"; -import { motion } from "framer-motion"; import { Loader2Icon } from "lucide-react"; import Image from "next/image"; import Link from "next/link"; import type React from "react"; -import { type ComponentProps } from "react"; -import { twMerge } from "tailwind-merge"; +import { Suspense } from "react"; +import Block from "@/components/ui/block"; import { buttonVariants } from "@/components/ui/button"; +import { createUsosService } from "@/lib/usos"; import { cn } from "@/lib/utils"; -const Block = ({ - className, - ...rest -}: ComponentProps<(typeof motion)["div"]> & { className: string }) => { - return ( - - ); -}; - const AnimationLogo = () => ( ( ); -const JoinUsBlock = () => { - const query = useQuery({ - queryKey: ["auth"], - queryFn: async () => { - const res = await fetch("/api/profile"); +const JoinUsBlock = async () => { + try { + const usos = await createUsosService(); + await usos.getProfile(); - if (res.status === 401) { - throw new Error("Unauthorized"); - } - - return res.json(); - }, - retry: false, - gcTime: 5000, - }); - - return ( - -
-

- - Stwórz swój plan używając{" "} - darmowego zapisownika! - -

-
-
-

- Zaloguj się do platformy USOS i stwórz swój plan na semestr! -

-
-
- {query.isLoading ? ( -
- -
- ) : query.isError ? ( - - Zaloguj się - - ) : ( - - Twoje plany - - )} -
-
- ); + return ( + + Twoje plany + + ); + } catch (e) { + return ( + + Zaloguj się + + ); + } }; export default function HomePage() { @@ -157,7 +93,33 @@ export default function HomePage() {
- + +
+

+ + Stwórz swój plan używając{" "} + darmowego{" "} + zapisownika! + +

+
+
+

+ Zaloguj się do platformy USOS i stwórz swój plan na semestr! +

+
+
+ + +
+ } + > + + + +
); diff --git a/frontend/src/app/api/data/[facultyId]/route.ts b/frontend/src/app/api/data/[facultyId]/route.ts index 08683a8..845d801 100644 --- a/frontend/src/app/api/data/[facultyId]/route.ts +++ b/frontend/src/app/api/data/[facultyId]/route.ts @@ -5,11 +5,10 @@ import { createUsosService } from "@/lib/usos"; export const revalidate = 3600; -interface PageProps { - params: Promise<{ facultyId: string }>; -} - -export async function GET(_request: Request, { params }: PageProps) { +export async function GET( + _request: Request, + { params }: { params: Promise<{ facultyId: string }> }, +) { const { facultyId } = await params; const service = await createUsosService(); return NextResponse.json( diff --git a/frontend/src/app/api/profile/route.ts b/frontend/src/app/api/profile/route.ts deleted file mode 100644 index 518ee93..0000000 --- a/frontend/src/app/api/profile/route.ts +++ /dev/null @@ -1,14 +0,0 @@ -import { NextResponse } from "next/server"; - -import { createUsosService } from "@/lib/usos"; - -export const GET = async () => { - try { - const usos = await createUsosService(); - await usos.getProfile(); - - return NextResponse.json({ msg: "Authorized" }, { status: 200 }); - } catch (e) { - return NextResponse.json({ msg: "Unauthorized" }, { status: 401 }); - } -}; diff --git a/frontend/src/app/layout.tsx b/frontend/src/app/layout.tsx index e16df46..35acb3e 100644 --- a/frontend/src/app/layout.tsx +++ b/frontend/src/app/layout.tsx @@ -89,9 +89,9 @@ declare global { export default function RootLayout({ children, -}: Readonly<{ +}: { children: React.ReactNode; -}>) { +}) { return ( diff --git a/frontend/src/app/plans/create/[id]/_components/CreateNewPlanPage.tsx b/frontend/src/app/plans/create/[id]/_components/CreateNewPlanPage.tsx index cf11144..42b4537 100644 --- a/frontend/src/app/plans/create/[id]/_components/CreateNewPlanPage.tsx +++ b/frontend/src/app/plans/create/[id]/_components/CreateNewPlanPage.tsx @@ -28,7 +28,7 @@ import { usePlan } from "@/lib/usePlan"; import { registrationReplacer } from "@/lib/utils"; import { Day, Frequency, LessonType } from "@/services/usos/types"; -export default function CreateNewPlanPage({ planId }: { planId: string }) { +export function CreateNewPlanPage({ planId }: { planId: string }) { const plan = usePlan({ planId, }); @@ -107,11 +107,11 @@ export default function CreateNewPlanPage({ planId }: { planId: string }) {
- - - + +
{ diff --git a/frontend/src/app/plans/create/[id]/page.tsx b/frontend/src/app/plans/create/[id]/page.tsx index 9ef310c..4521fc9 100644 --- a/frontend/src/app/plans/create/[id]/page.tsx +++ b/frontend/src/app/plans/create/[id]/page.tsx @@ -2,7 +2,7 @@ import type { Metadata } from "next"; import { notFound } from "next/navigation"; import React from "react"; -import CreateNewPlanPage from "./_components/CreateNewPlanPage"; +import { CreateNewPlanPage } from "./_components/CreateNewPlanPage"; interface PageProps { params: Promise<{ id: string }>; @@ -14,7 +14,7 @@ export const metadata: Metadata = { export default async function CreateNewPlan({ params }: PageProps) { const { id } = await params; - if (!id || typeof id !== "string" || id.length === 0) { + if (typeof id !== "string" || id.length === 0) { return notFound(); } diff --git a/frontend/src/app/plans/layout.tsx b/frontend/src/app/plans/layout.tsx index 7b4b772..de93538 100644 --- a/frontend/src/app/plans/layout.tsx +++ b/frontend/src/app/plans/layout.tsx @@ -7,7 +7,9 @@ import { cn } from "@/lib/utils"; export default function PlansLayout({ children, -}: Readonly<{ children: React.ReactNode }>) { +}: { + children: React.ReactNode; +}) { return (
diff --git a/frontend/src/app/plans/page.tsx b/frontend/src/app/plans/page.tsx index 27bd583..6abcd28 100644 --- a/frontend/src/app/plans/page.tsx +++ b/frontend/src/app/plans/page.tsx @@ -14,11 +14,11 @@ const plansAtom = atom( set(plansIds, values); }, ); -const Plans = () => { +export default function Plans() { const [plans, setPlans] = useAtom(plansAtom); const router = useRouter(); - const uuid = crypto.randomUUID(); const addNewPlan = () => { + const uuid = crypto.randomUUID(); const newPlan = { id: uuid, }; @@ -46,6 +46,4 @@ const Plans = () => {
); -}; - -export default Plans; +} diff --git a/frontend/src/app/plans/preview/[id]/_components/SharePlanPage.tsx b/frontend/src/app/plans/preview/[id]/_components/SharePlanPage.tsx index 29cb9a1..2c5bb6c 100644 --- a/frontend/src/app/plans/preview/[id]/_components/SharePlanPage.tsx +++ b/frontend/src/app/plans/preview/[id]/_components/SharePlanPage.tsx @@ -12,7 +12,7 @@ import { Button } from "@/components/ui/button"; import { usePlan } from "@/lib/usePlan"; import { Day } from "@/services/usos/types"; -export default function SharePlanPage({ planId }: { planId: string }) { +export function SharePlanPage({ planId }: { planId: string }) { const uuid = React.useMemo(() => crypto.randomUUID(), []); const [plans, setPlans] = useAtom(plansIds); const plan = usePlan({ planId }); diff --git a/frontend/src/app/plans/preview/[id]/page.tsx b/frontend/src/app/plans/preview/[id]/page.tsx index 5156fa9..b5138ec 100644 --- a/frontend/src/app/plans/preview/[id]/page.tsx +++ b/frontend/src/app/plans/preview/[id]/page.tsx @@ -2,7 +2,7 @@ import type { Metadata } from "next"; import { notFound } from "next/navigation"; import React from "react"; -import SharePlanPage from "./_components/SharePlanPage"; +import { SharePlanPage } from "./_components/SharePlanPage"; interface PageProps { params: Promise<{ id: string }>; @@ -14,7 +14,7 @@ export const metadata: Metadata = { export default async function SharePlan({ params }: PageProps) { const { id } = await params; - if (!id || typeof id !== "string" || id.length === 0) { + if (typeof id !== "string" || id.length === 0) { return notFound(); } diff --git a/frontend/src/components/GroupsAccordion.tsx b/frontend/src/components/GroupsAccordion.tsx index 9212120..538cd64 100644 --- a/frontend/src/components/GroupsAccordion.tsx +++ b/frontend/src/components/GroupsAccordion.tsx @@ -68,7 +68,7 @@ export const GroupsAccordionItem = ({
{courses.map((course) => ( -
+
{course.type} diff --git a/frontend/src/components/Plan.tsx b/frontend/src/components/Plan.tsx index 37138b9..103acee 100644 --- a/frontend/src/components/Plan.tsx +++ b/frontend/src/components/Plan.tsx @@ -1,7 +1,9 @@ +"use client"; + import { useAtom } from "jotai"; import { Pencil } from "lucide-react"; import Link from "next/link"; -import router from "next/router"; +import { useRouter } from "next/navigation"; import React from "react"; import { plansIds } from "@/atoms/plansIds"; @@ -21,6 +23,7 @@ export const Plan = ({ id, name }: { id: string; name: string }) => { const [plans, setPlans] = useAtom(plansIds); const plan = usePlan({ planId: id }); const planToCopy = usePlan({ planId: uuid }); + const router = useRouter(); const copyPlan = () => { const newPlan = { @@ -38,7 +41,7 @@ export const Plan = ({ id, name }: { id: string; name: string }) => { }); setTimeout(() => { - void router.push(`/createplan/${newPlan.id}`); + router.push(`/createplan/${newPlan.id}`); }, 200); }; const deletePlan = () => { diff --git a/frontend/src/components/Providers.tsx b/frontend/src/components/Providers.tsx index 4c01459..c2ead65 100644 --- a/frontend/src/components/Providers.tsx +++ b/frontend/src/components/Providers.tsx @@ -5,7 +5,9 @@ import type React from "react"; export default function ClientProviders({ children, -}: Readonly<{ children: React.ReactNode }>) { +}: { + children: React.ReactNode; +}) { const queryClient = new QueryClient({ defaultOptions: { queries: { diff --git a/frontend/src/components/ui/block.tsx b/frontend/src/components/ui/block.tsx new file mode 100644 index 0000000..71b8cec --- /dev/null +++ b/frontend/src/components/ui/block.tsx @@ -0,0 +1,39 @@ +"use client"; + +import { motion } from "framer-motion"; +import type React from "react"; +import { type ComponentProps } from "react"; + +import { cn } from "@/lib/utils"; + +const Block = ({ + className, + ...rest +}: ComponentProps<(typeof motion)["div"]> & { className: string }) => { + return ( + + ); +}; + +export default Block; diff --git a/frontend/src/components/ui/select.tsx b/frontend/src/components/ui/select.tsx index 6b64c27..5d071cc 100644 --- a/frontend/src/components/ui/select.tsx +++ b/frontend/src/components/ui/select.tsx @@ -13,7 +13,7 @@ const SelectValue = SelectPrimitive.Value; const SelectTrigger = React.forwardRef< React.ElementRef, React.ComponentPropsWithoutRef & { - isLoading?: boolean; + disabled?: boolean; } // eslint-disable-next-line react/prop-types >(({ className, children, ...props }, ref) => ( @@ -28,7 +28,7 @@ const SelectTrigger = React.forwardRef< {children} {/* eslint-disable-next-line react/prop-types */} - {props.isLoading === true ? ( + {props.disabled === true ? ( ) : (