From 3d34b6bfcf64e0d23cb320f3f491abf5ef315e7f Mon Sep 17 00:00:00 2001 From: Henry Date: Fri, 17 Jan 2025 15:35:50 +0000 Subject: [PATCH] feat: public card modal --- apps/web/src/components/modal.tsx | 9 +- apps/web/src/views/public/board/CardModal.tsx | 117 ++++++++++++++++++ apps/web/src/views/public/board/index.tsx | 40 +++++- 3 files changed, 162 insertions(+), 4 deletions(-) create mode 100644 apps/web/src/views/public/board/CardModal.tsx diff --git a/apps/web/src/components/modal.tsx b/apps/web/src/components/modal.tsx index 54e7bb40..976267f0 100644 --- a/apps/web/src/components/modal.tsx +++ b/apps/web/src/components/modal.tsx @@ -6,9 +6,14 @@ import { useModal } from "~/providers/modal"; interface Props { children: React.ReactNode; modalSize?: "sm" | "md" | "lg"; + positionFromTop?: string; } -const Modal: React.FC = ({ children, modalSize = "sm" }) => { +const Modal: React.FC = ({ + children, + modalSize = "sm", + positionFromTop = "25vh", +}) => { const { isOpen, closeModal } = useModal(); const modalSizeMap = { @@ -44,7 +49,7 @@ const Modal: React.FC = ({ children, modalSize = "sm" }) => { leaveTo="opacity-0 translate-y-4 sm:translate-y-0 sm:scale-95" > {children} diff --git a/apps/web/src/views/public/board/CardModal.tsx b/apps/web/src/views/public/board/CardModal.tsx new file mode 100644 index 00000000..fa130471 --- /dev/null +++ b/apps/web/src/views/public/board/CardModal.tsx @@ -0,0 +1,117 @@ +import { useRouter } from "next/router"; +import { HiXMark } from "react-icons/hi2"; + +import { useModal } from "~/providers/modal"; +import { api } from "~/utils/api"; +import ActivityList from "~/views/card/components/ActivityList"; + +export function CardModal({ + cardPublicId, + workspaceSlug, + boardSlug, +}: { + cardPublicId: string | null | undefined; + workspaceSlug: string | null | undefined; + boardSlug: string | null | undefined; +}) { + const router = useRouter(); + const { closeModal, isOpen } = useModal(); + + const { data, isLoading } = api.card.byId.useQuery( + { + cardPublicId: cardPublicId ?? "", + }, + { + enabled: isOpen && !!cardPublicId, + }, + ); + + const labels = data?.labels ?? []; + + return ( +
+
+
+
+ + {isLoading ? ( +
+
+
+ ) : ( + <> +

+ {data?.title} +

+ + )} +
+
+ {labels.map((label) => ( +
+ +
{label.name}
+
+ ))} +
+ + {data?.description && ( +
+
+

+ {data.description} +

+
+
+ )} +
+

+ Activity +

+
+ {cardPublicId && ( + + )} +
+
+
+
+
+ ); +} diff --git a/apps/web/src/views/public/board/index.tsx b/apps/web/src/views/public/board/index.tsx index c8c093bf..f50c4020 100644 --- a/apps/web/src/views/public/board/index.tsx +++ b/apps/web/src/views/public/board/index.tsx @@ -1,19 +1,25 @@ import Link from "next/link"; import { useRouter } from "next/router"; +import { useEffect, useState } from "react"; import { HiLink } from "react-icons/hi2"; +import Modal from "~/components/modal"; import { PageHead } from "~/components/PageHead"; import PatternedBackground from "~/components/PatternedBackground"; import Popup from "~/components/Popup"; import ThemeToggle from "~/components/ThemeToggle"; +import { useModal } from "~/providers/modal"; import { usePopup } from "~/providers/popup"; import { api } from "~/utils/api"; import { formatToArray } from "~/utils/helpers"; import Filters from "~/views/board/components/Filters"; +import { CardModal } from "./CardModal"; export default function PublicBoardView() { const router = useRouter(); const { showPopup } = usePopup(); + const [isRouteLoaded, setIsRouteLoaded] = useState(false); + const { openModal } = useModal(); const boardSlug = Array.isArray(router.query.boardSlug) ? router.query.boardSlug[0] @@ -52,6 +58,25 @@ export default function PublicBoardView() { ); }; + const splitPath = router.asPath.split("/"); + const cardPublicId = splitPath.length > 3 ? splitPath[3] : null; + + useEffect(() => { + if (!isRouteLoaded && router.isReady) { + setIsRouteLoaded(true); + + if (cardPublicId) { + openModal("CARD"); + } + } + }, [ + router.isReady, + isRouteLoaded, + setIsRouteLoaded, + cardPublicId, + openModal, + ]); + return ( <>
-
+
{isLoading ? ( @@ -106,8 +131,12 @@ export default function PublicBoardView() { {list.cards.map((card) => ( { + openModal("CARD"); + }} >
{card.title}
{card.labels.length || card.members.length ? ( @@ -172,6 +201,13 @@ export default function PublicBoardView() {
+ + + ); }