From f5ece2ddbe066921e6fd165fb87fc95a226a1324 Mon Sep 17 00:00:00 2001 From: Kobe Date: Tue, 29 Oct 2024 15:10:16 -0400 Subject: [PATCH] adding pagination layout --- .../FullPageModal/FullPageModal.tsx | 89 ------------------- .../Fall2024ReleaseModalContent.tsx | 72 +++++++++++++++ .../WhatsNewModal/ModalBodyPagination.tsx | 77 ++++++++++++++++ .../WhatsNewModal/WhatsNewModal.tsx | 21 +++++ packages/frontend/pages/home.tsx | 9 +- 5 files changed, 177 insertions(+), 91 deletions(-) delete mode 100644 packages/frontend/components/FullPageModal/FullPageModal.tsx create mode 100644 packages/frontend/components/WhatsNewModal/Fall2024ReleaseModalContent.tsx create mode 100644 packages/frontend/components/WhatsNewModal/ModalBodyPagination.tsx create mode 100644 packages/frontend/components/WhatsNewModal/WhatsNewModal.tsx diff --git a/packages/frontend/components/FullPageModal/FullPageModal.tsx b/packages/frontend/components/FullPageModal/FullPageModal.tsx deleted file mode 100644 index 49644a764..000000000 --- a/packages/frontend/components/FullPageModal/FullPageModal.tsx +++ /dev/null @@ -1,89 +0,0 @@ -import React, { useState } from "react"; -import { - Button, - Modal, - ModalBody, - ModalContent, - ModalFooter, - ModalHeader, - ModalOverlay, - Text, -} from "@chakra-ui/react"; - -interface WhatsNewPopUpProps { - // is model open or not? - isOpen: boolean; - // Closes the modal - onClose: () => void; -} - -export const WhatsNewPopUp: React.FC = ({ - isOpen, - onClose, -}) => { - const [pageNum, setPageNum] = useState(1); - const nextPage = () => setPageNum((prev) => prev + 1); - const prevPage = () => setPageNum((prev) => prev - 1); - const renderPage = () => { - switch (pageNum) { - case 1: - return ( - <> - - NEW PAGE 1 - - these are the new features - - ); - case 2: - return ( - <> - - NEW PAGE 2 - - these are the new features - - ); - case 3: - return ( - <> - - NEW PAGE 3 - - these are the new features - - ); - } - }; - return ( - - - - - Latest Release v26.09.24 - - {renderPage()} - - {pageNum > 1 && ( - - )} - {pageNum < 3 ? ( - - ) : ( - - )} - - - - ); -}; diff --git a/packages/frontend/components/WhatsNewModal/Fall2024ReleaseModalContent.tsx b/packages/frontend/components/WhatsNewModal/Fall2024ReleaseModalContent.tsx new file mode 100644 index 000000000..3b1835329 --- /dev/null +++ b/packages/frontend/components/WhatsNewModal/Fall2024ReleaseModalContent.tsx @@ -0,0 +1,72 @@ +import { + Box, + Button, + ModalContent, + ModalFooter, + ModalHeader, + Text, +} from "@chakra-ui/react"; +import { ModalBodyPagination } from "./ModalBodyPagination"; + +interface ModalContentProps { + onClose: () => void; +} + +export const Fall2024ReleaseModalContent: React.FC = ({ + onClose, +}) => { + const featurePages: React.ReactNode[] = [ + , + , + , + ]; + + return ( + + + Latest Release v26.09.24 + + + + + + + + ); +}; + +const FeaturePage1: React.FC = () => { + return ( + + Feature 1 + + ); +}; + +const FeaturePage2: React.FC = () => { + return ( + + Feature 2 + + ); +}; + +const FeaturePage3: React.FC = () => { + return ( + + Feature 3 + + ); +}; diff --git a/packages/frontend/components/WhatsNewModal/ModalBodyPagination.tsx b/packages/frontend/components/WhatsNewModal/ModalBodyPagination.tsx new file mode 100644 index 000000000..7ba1b847a --- /dev/null +++ b/packages/frontend/components/WhatsNewModal/ModalBodyPagination.tsx @@ -0,0 +1,77 @@ +import { ChevronLeftIcon, ChevronRightIcon } from "@chakra-ui/icons"; +import { Box, IconButton, ModalBody, Text } from "@chakra-ui/react"; +import { useState } from "react"; + +interface ModalBodyPaginationProps { + pages: React.ReactNode[]; +} + +export const ModalBodyPagination: React.FC = ({ + pages, +}) => { + const [currentPageIndex, setCurrentPageIndex] = useState(0); + + const totalPages = pages.length; + + function goToNextPage() { + setCurrentPageIndex((prev) => Math.min(prev + 1, totalPages)); + } + + function goToPreviousPage() { + setCurrentPageIndex((prev) => Math.max(prev - 1, 0)); + } + + function setCurrentPage(index: number) { + setCurrentPageIndex(index); + } + + return ( + + {pages[currentPageIndex]} + + + ); +}; + +interface PaginationProps { + goToPreviousPage: () => void; + goToNextPage: () => void; + currentPageIndex: number; + totalPages: number; +} + +const Pagination: React.FC = ({ + goToPreviousPage, + goToNextPage, + currentPageIndex, + totalPages, +}) => { + return ( + + } + onClick={goToPreviousPage} + isDisabled={currentPageIndex === 0} + aria-label="Previous page" + /> + + {currentPageIndex + 1} / {totalPages} + + } + onClick={goToNextPage} + isDisabled={currentPageIndex >= totalPages - 1} + aria-label="Next page" + /> + + ); +}; diff --git a/packages/frontend/components/WhatsNewModal/WhatsNewModal.tsx b/packages/frontend/components/WhatsNewModal/WhatsNewModal.tsx new file mode 100644 index 000000000..8e450378d --- /dev/null +++ b/packages/frontend/components/WhatsNewModal/WhatsNewModal.tsx @@ -0,0 +1,21 @@ +import React from "react"; +import { Modal, ModalOverlay } from "@chakra-ui/react"; + +interface WhatsNewModalProps { + isOpen: boolean; + onClose: () => void; + children: React.ReactNode; +} + +export const WhatsNewModal: React.FC = ({ + isOpen, + onClose, + children, +}) => { + return ( + + + {children} + + ); +}; diff --git a/packages/frontend/pages/home.tsx b/packages/frontend/pages/home.tsx index 28a1016bd..e740f0916 100644 --- a/packages/frontend/pages/home.tsx +++ b/packages/frontend/pages/home.tsx @@ -50,8 +50,9 @@ import { getPreReqWarnings, } from "../utils/plan/preAndCoReqCheck"; import { IsGuestContext } from "./_app"; -import { WhatsNewPopUp } from "../components/FullPageModal/FullPageModal"; +import { WhatsNewModal } from "../components/WhatsNewModal/WhatsNewModal"; import Cookies from "universal-cookie"; +import { Fall2024ReleaseModalContent } from "../components/WhatsNewModal/Fall2024ReleaseModalContent"; // Algorithm to decide which droppable the course is currently over (if any). // See https://docs.dndkit.com/api-documentation/context-provider/collision-detection-algorithms for more info. @@ -347,7 +348,11 @@ const HomePage: NextPage = () => { ) : null} - + } + /> ); };