diff --git a/course-matrix/frontend/index.html b/course-matrix/frontend/index.html index 7ce8c4c3..f1256cda 100644 --- a/course-matrix/frontend/index.html +++ b/course-matrix/frontend/index.html @@ -2,7 +2,7 @@ - + Course Matrix diff --git a/course-matrix/frontend/package-lock.json b/course-matrix/frontend/package-lock.json index c9ab7e61..2cc0b991 100644 --- a/course-matrix/frontend/package-lock.json +++ b/course-matrix/frontend/package-lock.json @@ -25,6 +25,7 @@ "@radix-ui/react-separator": "^1.1.2", "@radix-ui/react-slot": "^1.1.2", "@radix-ui/react-switch": "^1.1.3", + "@radix-ui/react-toast": "^1.2.6", "@radix-ui/react-tooltip": "^1.1.8", "@reduxjs/toolkit": "^2.5.1", "@schedule-x/drag-and-drop": "^2.21.1", @@ -2828,6 +2829,39 @@ } } }, + "node_modules/@radix-ui/react-toast": { + "version": "1.2.6", + "resolved": "https://registry.npmjs.org/@radix-ui/react-toast/-/react-toast-1.2.6.tgz", + "integrity": "sha512-gN4dpuIVKEgpLn1z5FhzT9mYRUitbfZq9XqN/7kkBMUgFTzTG8x/KszWJugJXHcwxckY8xcKDZPz7kG3o6DsUA==", + "dependencies": { + "@radix-ui/primitive": "1.1.1", + "@radix-ui/react-collection": "1.1.2", + "@radix-ui/react-compose-refs": "1.1.1", + "@radix-ui/react-context": "1.1.1", + "@radix-ui/react-dismissable-layer": "1.1.5", + "@radix-ui/react-portal": "1.1.4", + "@radix-ui/react-presence": "1.1.2", + "@radix-ui/react-primitive": "2.0.2", + "@radix-ui/react-use-callback-ref": "1.1.0", + "@radix-ui/react-use-controllable-state": "1.1.0", + "@radix-ui/react-use-layout-effect": "1.1.0", + "@radix-ui/react-visually-hidden": "1.1.2" + }, + "peerDependencies": { + "@types/react": "*", + "@types/react-dom": "*", + "react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc", + "react-dom": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc" + }, + "peerDependenciesMeta": { + "@types/react": { + "optional": true + }, + "@types/react-dom": { + "optional": true + } + } + }, "node_modules/@radix-ui/react-tooltip": { "version": "1.1.8", "resolved": "https://registry.npmjs.org/@radix-ui/react-tooltip/-/react-tooltip-1.1.8.tgz", diff --git a/course-matrix/frontend/package.json b/course-matrix/frontend/package.json index 367abe76..a7944a0b 100644 --- a/course-matrix/frontend/package.json +++ b/course-matrix/frontend/package.json @@ -30,6 +30,7 @@ "@radix-ui/react-separator": "^1.1.2", "@radix-ui/react-slot": "^1.1.2", "@radix-ui/react-switch": "^1.1.3", + "@radix-ui/react-toast": "^1.2.6", "@radix-ui/react-tooltip": "^1.1.8", "@reduxjs/toolkit": "^2.5.1", "@schedule-x/drag-and-drop": "^2.21.1", diff --git a/course-matrix/frontend/public/img/course-matrix-logo.png b/course-matrix/frontend/public/img/course-matrix-logo.png new file mode 100644 index 00000000..6f41280f Binary files /dev/null and b/course-matrix/frontend/public/img/course-matrix-logo.png differ diff --git a/course-matrix/frontend/public/img/grey-avatar.png b/course-matrix/frontend/public/img/grey-avatar.png new file mode 100644 index 00000000..6ffe1296 Binary files /dev/null and b/course-matrix/frontend/public/img/grey-avatar.png differ diff --git a/course-matrix/frontend/src/App.tsx b/course-matrix/frontend/src/App.tsx index 60b97279..1b58ce9f 100644 --- a/course-matrix/frontend/src/App.tsx +++ b/course-matrix/frontend/src/App.tsx @@ -6,6 +6,7 @@ import SignupPage from "./pages/Signup/SignUpPage"; import AuthRoute from "./components/auth-route"; import SignupSuccessfulPage from "./pages/Signup/SignupSuccessfulPage"; import LoginRoute from "./components/login-route"; +import { Toaster } from "./components/ui/toaster"; /** * App Component @@ -44,6 +45,7 @@ function App() { element={} /> + ); } diff --git a/course-matrix/frontend/src/components/UserMenu.tsx b/course-matrix/frontend/src/components/UserMenu.tsx index 76abca62..fd9750a3 100644 --- a/course-matrix/frontend/src/components/UserMenu.tsx +++ b/course-matrix/frontend/src/components/UserMenu.tsx @@ -111,7 +111,7 @@ export function UserMenu({ setOpen }: UserMenuProps) { {username} {/* Avatar Image is the profile picture of the user. The default avatar is used as a placeholder for now. */} - + {/* Avatar Fallback is the initials of the user. Avatar Fallback will be used if Avatar Image fails to load */} {initials} diff --git a/course-matrix/frontend/src/components/imagePlaceholder.tsx b/course-matrix/frontend/src/components/imagePlaceholder.tsx new file mode 100644 index 00000000..5d025b4c --- /dev/null +++ b/course-matrix/frontend/src/components/imagePlaceholder.tsx @@ -0,0 +1,16 @@ +export const ImagePlaceholder = () => { + const blurredImagePlaceholder = + "data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAAAAAAD/2wBDAAUDBAQEAwUEBAQFBQUGBwwIBwcHBw8LCwkMEQ8SEhEPERETFhwXExQaFRERGCEYGh0dHx8fExciJCIeJBweHx7/2wBDAQUFBQcGBw4ICA4eFBEUHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh7/wAARCAAIAAgDASIAAhEBAxEB/8QAFQABAQAAAAAAAAAAAAAAAAAAAAb/xAAhEAACAQMDBQAAAAAAAAAAAAABAgMABAUGIWEREiMxUf/EABUBAQEAAAAAAAAAAAAAAAAAAAMF/8QAGhEAAgIDAAAAAAAAAAAAAAAAAQIAAxEhMf/aAAwDAQACEQMRAD8ASlWzQwxoGsuragA8nk6c+ONWNeOixw2aRm2AMbs5JAJJPk9aUpAJViJIGenZEwn/2Q=="; + + return ( +
+ ); +}; diff --git a/course-matrix/frontend/src/components/logo.tsx b/course-matrix/frontend/src/components/logo.tsx index d05d3411..4ec495dc 100644 --- a/course-matrix/frontend/src/components/logo.tsx +++ b/course-matrix/frontend/src/components/logo.tsx @@ -1,14 +1,27 @@ -import logoImg from "/img/logo.png"; +import { useState, useEffect } from "react"; +import logoImg from "/img/course-matrix-logo.png"; +import { ImagePlaceholder } from "./imagePlaceholder"; const Logo = () => { + const [imageLoaded, setImageLoaded] = useState(false); + return ( <>
- profile-img +
+ {!imageLoaded && } + + Course Matrix logo setImageLoaded(true)} + /> +
+
Course
Matrix
diff --git a/course-matrix/frontend/src/components/ui/toast.tsx b/course-matrix/frontend/src/components/ui/toast.tsx new file mode 100644 index 00000000..2bc23c1f --- /dev/null +++ b/course-matrix/frontend/src/components/ui/toast.tsx @@ -0,0 +1,127 @@ +import * as React from "react"; +import * as ToastPrimitives from "@radix-ui/react-toast"; +import { cva, type VariantProps } from "class-variance-authority"; +import { X } from "lucide-react"; + +import { cn } from "@/lib/utils"; + +const ToastProvider = ToastPrimitives.Provider; + +const ToastViewport = React.forwardRef< + React.ElementRef, + React.ComponentPropsWithoutRef +>(({ className, ...props }, ref) => ( + +)); +ToastViewport.displayName = ToastPrimitives.Viewport.displayName; + +const toastVariants = cva( + "group pointer-events-auto relative flex w-full items-center justify-between space-x-4 overflow-hidden rounded-md border p-6 pr-8 shadow-lg transition-all data-[swipe=cancel]:translate-x-0 data-[swipe=end]:translate-x-[var(--radix-toast-swipe-end-x)] data-[swipe=move]:translate-x-[var(--radix-toast-swipe-move-x)] data-[swipe=move]:transition-none data-[state=open]:animate-in data-[state=closed]:animate-out data-[swipe=end]:animate-out data-[state=closed]:fade-out-80 data-[state=closed]:slide-out-to-right-full data-[state=open]:slide-in-from-top-full data-[state=open]:sm:slide-in-from-bottom-full", + { + variants: { + variant: { + default: "border bg-background text-foreground", + destructive: + "destructive group border-destructive bg-destructive text-destructive-foreground", + }, + }, + defaultVariants: { + variant: "default", + }, + }, +); + +const Toast = React.forwardRef< + React.ElementRef, + React.ComponentPropsWithoutRef & + VariantProps +>(({ className, variant, ...props }, ref) => { + return ( + + ); +}); +Toast.displayName = ToastPrimitives.Root.displayName; + +const ToastAction = React.forwardRef< + React.ElementRef, + React.ComponentPropsWithoutRef +>(({ className, ...props }, ref) => ( + +)); +ToastAction.displayName = ToastPrimitives.Action.displayName; + +const ToastClose = React.forwardRef< + React.ElementRef, + React.ComponentPropsWithoutRef +>(({ className, ...props }, ref) => ( + + + +)); +ToastClose.displayName = ToastPrimitives.Close.displayName; + +const ToastTitle = React.forwardRef< + React.ElementRef, + React.ComponentPropsWithoutRef +>(({ className, ...props }, ref) => ( + +)); +ToastTitle.displayName = ToastPrimitives.Title.displayName; + +const ToastDescription = React.forwardRef< + React.ElementRef, + React.ComponentPropsWithoutRef +>(({ className, ...props }, ref) => ( + +)); +ToastDescription.displayName = ToastPrimitives.Description.displayName; + +type ToastProps = React.ComponentPropsWithoutRef; + +type ToastActionElement = React.ReactElement; + +export { + type ToastProps, + type ToastActionElement, + ToastProvider, + ToastViewport, + Toast, + ToastTitle, + ToastDescription, + ToastClose, + ToastAction, +}; diff --git a/course-matrix/frontend/src/components/ui/toaster.tsx b/course-matrix/frontend/src/components/ui/toaster.tsx new file mode 100644 index 00000000..5887f080 --- /dev/null +++ b/course-matrix/frontend/src/components/ui/toaster.tsx @@ -0,0 +1,33 @@ +import { useToast } from "@/hooks/use-toast"; +import { + Toast, + ToastClose, + ToastDescription, + ToastProvider, + ToastTitle, + ToastViewport, +} from "@/components/ui/toast"; + +export function Toaster() { + const { toasts } = useToast(); + + return ( + + {toasts.map(function ({ id, title, description, action, ...props }) { + return ( + +
+ {title && {title}} + {description && ( + {description} + )} +
+ {action} + +
+ ); + })} + +
+ ); +} diff --git a/course-matrix/frontend/src/hooks/use-toast.ts b/course-matrix/frontend/src/hooks/use-toast.ts new file mode 100644 index 00000000..6555e795 --- /dev/null +++ b/course-matrix/frontend/src/hooks/use-toast.ts @@ -0,0 +1,191 @@ +"use client"; + +// Inspired by react-hot-toast library +import * as React from "react"; + +import type { ToastActionElement, ToastProps } from "@/components/ui/toast"; + +const TOAST_LIMIT = 1; +const TOAST_REMOVE_DELAY = 1000000; + +type ToasterToast = ToastProps & { + id: string; + title?: React.ReactNode; + description?: React.ReactNode; + action?: ToastActionElement; +}; + +const actionTypes = { + ADD_TOAST: "ADD_TOAST", + UPDATE_TOAST: "UPDATE_TOAST", + DISMISS_TOAST: "DISMISS_TOAST", + REMOVE_TOAST: "REMOVE_TOAST", +} as const; + +let count = 0; + +function genId() { + count = (count + 1) % Number.MAX_SAFE_INTEGER; + return count.toString(); +} + +type ActionType = typeof actionTypes; + +type Action = + | { + type: ActionType["ADD_TOAST"]; + toast: ToasterToast; + } + | { + type: ActionType["UPDATE_TOAST"]; + toast: Partial; + } + | { + type: ActionType["DISMISS_TOAST"]; + toastId?: ToasterToast["id"]; + } + | { + type: ActionType["REMOVE_TOAST"]; + toastId?: ToasterToast["id"]; + }; + +interface State { + toasts: ToasterToast[]; +} + +const toastTimeouts = new Map>(); + +const addToRemoveQueue = (toastId: string) => { + if (toastTimeouts.has(toastId)) { + return; + } + + const timeout = setTimeout(() => { + toastTimeouts.delete(toastId); + dispatch({ + type: "REMOVE_TOAST", + toastId: toastId, + }); + }, TOAST_REMOVE_DELAY); + + toastTimeouts.set(toastId, timeout); +}; + +export const reducer = (state: State, action: Action): State => { + switch (action.type) { + case "ADD_TOAST": + return { + ...state, + toasts: [action.toast, ...state.toasts].slice(0, TOAST_LIMIT), + }; + + case "UPDATE_TOAST": + return { + ...state, + toasts: state.toasts.map((t) => + t.id === action.toast.id ? { ...t, ...action.toast } : t, + ), + }; + + case "DISMISS_TOAST": { + const { toastId } = action; + + // ! Side effects ! - This could be extracted into a dismissToast() action, + // but I'll keep it here for simplicity + if (toastId) { + addToRemoveQueue(toastId); + } else { + state.toasts.forEach((toast) => { + addToRemoveQueue(toast.id); + }); + } + + return { + ...state, + toasts: state.toasts.map((t) => + t.id === toastId || toastId === undefined + ? { + ...t, + open: false, + } + : t, + ), + }; + } + case "REMOVE_TOAST": + if (action.toastId === undefined) { + return { + ...state, + toasts: [], + }; + } + return { + ...state, + toasts: state.toasts.filter((t) => t.id !== action.toastId), + }; + } +}; + +const listeners: Array<(state: State) => void> = []; + +let memoryState: State = { toasts: [] }; + +function dispatch(action: Action) { + memoryState = reducer(memoryState, action); + listeners.forEach((listener) => { + listener(memoryState); + }); +} + +type Toast = Omit; + +function toast({ ...props }: Toast) { + const id = genId(); + + const update = (props: ToasterToast) => + dispatch({ + type: "UPDATE_TOAST", + toast: { ...props, id }, + }); + const dismiss = () => dispatch({ type: "DISMISS_TOAST", toastId: id }); + + dispatch({ + type: "ADD_TOAST", + toast: { + ...props, + id, + open: true, + onOpenChange: (open) => { + if (!open) dismiss(); + }, + }, + }); + + return { + id: id, + dismiss, + update, + }; +} + +function useToast() { + const [state, setState] = React.useState(memoryState); + + React.useEffect(() => { + listeners.push(setState); + return () => { + const index = listeners.indexOf(setState); + if (index > -1) { + listeners.splice(index, 1); + } + }; + }, [state]); + + return { + ...state, + toast, + dismiss: (toastId?: string) => dispatch({ type: "DISMISS_TOAST", toastId }), + }; +} + +export { useToast, toast }; diff --git a/course-matrix/frontend/src/pages/Home/EmailNotificationSettings.tsx b/course-matrix/frontend/src/pages/Home/EmailNotificationSettings.tsx index 6214575d..cf52be96 100644 --- a/course-matrix/frontend/src/pages/Home/EmailNotificationSettings.tsx +++ b/course-matrix/frontend/src/pages/Home/EmailNotificationSettings.tsx @@ -14,6 +14,7 @@ import { DialogTrigger, } from "@/components/ui/dialog"; import { Switch } from "@/components/ui/switch"; +import { useToast } from "@/hooks/use-toast"; import { TimetableModel } from "@/models/models"; import { useEffect, useState } from "react"; @@ -26,6 +27,7 @@ export const EmailNotificationSettings = ({ }: EmailNotificationSettingsProps) => { const { data, isLoading, refetch } = useGetTimetableQuery(timetableId); const [updateTimetable] = useUpdateTimetableMutation(); + const { toast } = useToast(); const [toggled, setToggled] = useState(false); const handleCancel = () => { @@ -47,6 +49,9 @@ export const EmailNotificationSettings = ({ id: timetableId, email_notifications_enabled: toggled, }).unwrap(); + toast({ + description: `Email notifications have been ${toggled ? "enabled" : "disabled"}.`, + }); refetch(); } catch (error) { console.error("Failed to update timetable:", error); diff --git a/course-matrix/frontend/src/pages/Home/Home.tsx b/course-matrix/frontend/src/pages/Home/Home.tsx index 36d07893..ba29e039 100644 --- a/course-matrix/frontend/src/pages/Home/Home.tsx +++ b/course-matrix/frontend/src/pages/Home/Home.tsx @@ -114,7 +114,7 @@ const Home = () => {

My Timetables

- +

{


-
+
{isLoading ? (

Loading...

) : activeTab === "Mine" ? ( diff --git a/course-matrix/frontend/src/pages/Home/TimetableCard.tsx b/course-matrix/frontend/src/pages/Home/TimetableCard.tsx index 059b8a39..8a5618f0 100644 --- a/course-matrix/frontend/src/pages/Home/TimetableCard.tsx +++ b/course-matrix/frontend/src/pages/Home/TimetableCard.tsx @@ -19,8 +19,19 @@ import { } from "@/api/timetableApiSlice"; import { Link } from "react-router-dom"; import { TimetableModel } from "@/models/models"; +import { SemesterIcon } from "@/components/semester-icon"; import { convertTimestampToLocaleTime } from "../../utils/convert-timestamp-to-locale-time"; +const semesterToBgColor = (semester: string) => { + if (semester.startsWith("Fall")) { + return "bg-red-100"; + } else if (semester.startsWith("Winter")) { + return "bg-blue-100"; + } else { + return "bg-yellow-100"; + } +}; + interface TimetableCardProps { refetchMyTimetables: () => void; refetchSharedTimetables: () => void; @@ -53,6 +64,8 @@ const TimetableCard = ({ setSelectedSharedTimetable, favorite, }: TimetableCardProps) => { + /// small blurred version + const [updateTimetable] = useUpdateTimetableMutation(); const timetableId = timetable.id; @@ -119,14 +132,18 @@ const TimetableCard = ({ }; return isShared ? ( - + - Timetable default image setSelectedSharedTimetable(timetable)} - /> +
+
+ +
+
+
) : ( - + - Timetable default image +
+
+ +
+
@@ -190,20 +212,19 @@ const TimetableCard = ({ onChange={(e) => setTimetableCardTitle(e.target.value)} /> -
- handleFavourite()} - /> -
{!isEditingTitle && ( <> + handleFavourite()} + />