From 08541c74f3feff4caf8b7489917aad840c2cef23 Mon Sep 17 00:00:00 2001 From: soumitradev Date: Fri, 5 Jan 2024 14:28:47 +0530 Subject: [PATCH] feat: make view page repsonsive --- frontend/src/ViewTimetable.tsx | 72 +++++++++++++++++++++++++++------- 1 file changed, 57 insertions(+), 15 deletions(-) diff --git a/frontend/src/ViewTimetable.tsx b/frontend/src/ViewTimetable.tsx index d9d6a95c..4afa70c0 100644 --- a/frontend/src/ViewTimetable.tsx +++ b/frontend/src/ViewTimetable.tsx @@ -16,6 +16,7 @@ import { Edit2, GripHorizontal, GripVertical, + Menu, Trash, } from "lucide-react"; import { useCallback, useEffect, useMemo, useRef, useState } from "react"; @@ -51,6 +52,7 @@ import { } from "./components/ui/tooltip"; import { toast, useToast } from "./components/ui/use-toast"; import { router } from "./main"; +import { Popover, PopoverContent, PopoverTrigger } from "./components/ui/popover"; const fetchTimetable = async (timetableId: string) => { const response = await axios.get>( @@ -709,6 +711,16 @@ function ViewTimetable() { [currentCourseID], ); + const [screenIsLarge, setScreenIsLarge] = useState( + window.matchMedia("(min-width: 1024px)").matches, + ); + + useEffect(() => { + window + .matchMedia("(min-width: 1024px)") + .addEventListener("change", (e) => setScreenIsLarge(e.matches)); + }, []); + if (courseQueryResult.isFetching) { return Loading...; } @@ -818,12 +830,14 @@ function ViewTimetable() { return ( <> {!isSpinner ? ( -
+
-

{timetable.name}

- +

+ {timetable.name} +

+

{timetable.acadYear} @@ -833,8 +847,8 @@ function ViewTimetable() { {`${timetable.year}-${timetable.semester}`}

- -

Last Updated:

+ +

Last Updated:

{new Date(timetable.lastUpdated).toLocaleString()}

@@ -846,9 +860,9 @@ function ViewTimetable() { @@ -856,7 +870,7 @@ function ViewTimetable() {

Download timetable as image

- + {screenIsLarge && @@ -907,7 +921,7 @@ function ViewTimetable() { }, 2000); }} > - + @@ -924,7 +938,7 @@ function ViewTimetable() { variant="ghost" className="rounded-full p-3 hover:bg-destructive/90 hover:text-destructive-foreground" > - + @@ -960,9 +974,34 @@ function ViewTimetable() {
{/* the bg-background here is necessary so the generated image has the background in it */}
+ >{screenIsLarge ? ( + ) : ( + + + + + + + )} console.log(e)} handleUnitDelete={(e) => console.log("DELETING", e)}