diff --git a/src/app/(protected)/(dashboard)/@modal/(...)view-whiteboard/[id]/page.tsx b/src/app/(protected)/(dashboard)/@modal/(...)view-whiteboard/[id]/page.tsx new file mode 100644 index 0000000..5dd549e --- /dev/null +++ b/src/app/(protected)/(dashboard)/@modal/(...)view-whiteboard/[id]/page.tsx @@ -0,0 +1,21 @@ +import { IntercepModal } from '@/app/_shared/components/modal/intercep-modal' +import { getPublicWhiteboard } from '@/app/_whiteboards/actions/public-whiteboard' +import { WhiterboardFromCompressed } from '@/app/_whiteboards/components/whiteboard' + +export default async function Page({ params }: {params: {id: string}}) { + const whiteboardId = Number(params.id) + + const whiteboard = await getPublicWhiteboard(whiteboardId) + + return ( + +
+ +
+
+ ) +} diff --git a/src/app/(protected)/(dashboard)/@modal/default.tsx b/src/app/(protected)/(dashboard)/@modal/default.tsx new file mode 100644 index 0000000..827ef62 --- /dev/null +++ b/src/app/(protected)/(dashboard)/@modal/default.tsx @@ -0,0 +1,3 @@ +export default function Default() { + return null +} \ No newline at end of file diff --git a/src/app/(protected)/(dashboard)/layout.tsx b/src/app/(protected)/(dashboard)/layout.tsx index d00b56a..e999769 100644 --- a/src/app/(protected)/(dashboard)/layout.tsx +++ b/src/app/(protected)/(dashboard)/layout.tsx @@ -3,13 +3,15 @@ import React from 'react' import { SideNavigation } from '@/app/_shared/components/navigation/sidebar' const LayoutPage = ({ - children -}: {children: React.ReactNode}) => { + children, + modal +}: {children: React.ReactNode, modal: React.ReactNode}) => { return (
{children} + {modal}
) diff --git a/src/app/_shared/components/modal/intercep-modal.tsx b/src/app/_shared/components/modal/intercep-modal.tsx new file mode 100644 index 0000000..190a704 --- /dev/null +++ b/src/app/_shared/components/modal/intercep-modal.tsx @@ -0,0 +1,36 @@ +'use client' + +import React, { useState } from 'react' +import { useRouter } from 'next/navigation' + +import { Dialog, DialogContent, DialogHeader, DialogTitle } from '@/app/_shared/components/ui/dialog' + +interface Props { + title: string + children: React.ReactNode +} + +export const IntercepModal = ({ title, children }: Props) => { + const router = useRouter() + const [isOpen, setIsOpen] = useState(true) + + const onOpenChangeHandler = (value: boolean) => { + if (!value) { + setIsOpen(false) + router.back() + + return + } + } + + return ( + + + + {title} + + {children} + + + ) +} diff --git a/src/app/_whiteboards/actions/public-whiteboard.ts b/src/app/_whiteboards/actions/public-whiteboard.ts new file mode 100644 index 0000000..881c9ad --- /dev/null +++ b/src/app/_whiteboards/actions/public-whiteboard.ts @@ -0,0 +1,16 @@ +import { redirect } from 'next/navigation' + +import findWhiteboardContent from '@/server/api/whiteboard/usecases/find-whiteboard-content' +import { db } from '@/server/db' + +export const getPublicWhiteboard = async (id: number) => { + 'use server' + const whiteboard = await findWhiteboardContent(db, { id, isPublic: true }) + + if (!whiteboard){ + redirect('/not-found') + } + + return whiteboard +} + \ No newline at end of file diff --git a/src/app/_whiteboards/components/whiteboard-card.tsx b/src/app/_whiteboards/components/whiteboard-card.tsx index 4224d03..badde25 100644 --- a/src/app/_whiteboards/components/whiteboard-card.tsx +++ b/src/app/_whiteboards/components/whiteboard-card.tsx @@ -45,7 +45,6 @@ export const WhiteboardCard = ({ whiteboard, children }: ListItemProps) => {
@@ -53,8 +52,6 @@ export const WhiteboardCard = ({ whiteboard, children }: ListItemProps) => { {name} - -

{description}

@@ -62,10 +59,9 @@ export const WhiteboardCard = ({ whiteboard, children }: ListItemProps) => {
{ whiteboard.space && } -
{ - whiteboard.isPublic && + whiteboard.isPublic && Public } diff --git a/src/app/view-whiteboard/[id]/page.tsx b/src/app/view-whiteboard/[id]/page.tsx index 43f325d..f5fa13b 100644 --- a/src/app/view-whiteboard/[id]/page.tsx +++ b/src/app/view-whiteboard/[id]/page.tsx @@ -1,30 +1,16 @@ 'use server' import React from 'react' -import { redirect } from 'next/navigation' +import { getPublicWhiteboard } from '@/app/_whiteboards/actions/public-whiteboard' import { WhiterboardFromCompressed } from '@/app/_whiteboards/components/whiteboard' import { WhiteboardHeader } from '@/app/_whiteboards/components/whiteboard-header' -import findWhiteboardContent from '@/server/api/whiteboard/usecases/find-whiteboard-content' -import { db } from '@/server/db' - - -const getWhiteboard = async (id: number) => { - const whiteboard = await findWhiteboardContent(db, { id, isPublic: true }) - - if (!whiteboard){ - redirect('/not-found') - } - - return whiteboard -} - const WhitebardViewPage = async ({ params }: {params: {id: string}}) => { const whiteboardId = Number(params.id) - const whiteboard = await getWhiteboard(whiteboardId) + const whiteboard = await getPublicWhiteboard(whiteboardId) return (