From 287f4040b49fd65fb224222b8c9abaedd9d26e4a Mon Sep 17 00:00:00 2001 From: Nevo David Date: Sun, 15 Dec 2024 13:17:10 +0700 Subject: [PATCH] feat: preview --- .../src/api/routes/public.controller.ts | 30 ++- .../src/app/(preview)/p/[id]/layout.tsx | 5 + .../src/app/(preview)/p/[id]/page.tsx | 247 ++++++++++++++++++ 3 files changed, 278 insertions(+), 4 deletions(-) create mode 100644 apps/frontend/src/app/(preview)/p/[id]/layout.tsx create mode 100644 apps/frontend/src/app/(preview)/p/[id]/page.tsx diff --git a/apps/backend/src/api/routes/public.controller.ts b/apps/backend/src/api/routes/public.controller.ts index e2098b7fe..993711dae 100644 --- a/apps/backend/src/api/routes/public.controller.ts +++ b/apps/backend/src/api/routes/public.controller.ts @@ -1,11 +1,15 @@ import { Controller, Get, Param } from '@nestjs/common'; import { ApiTags } from '@nestjs/swagger'; import { AgenciesService } from '@gitroom/nestjs-libraries/database/prisma/agencies/agencies.service'; +import { PostsService } from '@gitroom/nestjs-libraries/database/prisma/posts/posts.service'; @ApiTags('Public') @Controller('/public') export class PublicController { - constructor(private _agenciesService: AgenciesService) {} + constructor( + private _agenciesService: AgenciesService, + private _postsService: PostsService + ) {} @Get('/agencies-list') async getAgencyByUser() { return this._agenciesService.getAllAgencies(); @@ -17,9 +21,7 @@ export class PublicController { } @Get('/agencies-information/:agency') - async getAgencyInformation( - @Param('agency') agency: string, - ) { + async getAgencyInformation(@Param('agency') agency: string) { return this._agenciesService.getAgencyInformation(agency); } @@ -27,4 +29,24 @@ export class PublicController { async getAgenciesCount() { return this._agenciesService.getCount(); } + + @Get(`/posts/:id`) + async getPreview(@Param('id') id: string) { + return (await this._postsService.getPostsRecursively(id, true)).map( + ({ childrenPost, ...p }) => ({ + ...p, + ...(p.integration + ? { + integration: { + id: p.integration.id, + name: p.integration.name, + picture: p.integration.picture, + providerIdentifier: p.integration.providerIdentifier, + profile: p.integration.profile, + }, + } + : {}), + }) + ); + } } diff --git a/apps/frontend/src/app/(preview)/p/[id]/layout.tsx b/apps/frontend/src/app/(preview)/p/[id]/layout.tsx new file mode 100644 index 000000000..017e5745c --- /dev/null +++ b/apps/frontend/src/app/(preview)/p/[id]/layout.tsx @@ -0,0 +1,5 @@ +import { ReactNode } from 'react'; + +export default async function AppLayout({ children }: { children: ReactNode }) { + return children; +} \ No newline at end of file diff --git a/apps/frontend/src/app/(preview)/p/[id]/page.tsx b/apps/frontend/src/app/(preview)/p/[id]/page.tsx new file mode 100644 index 000000000..21a9d5f24 --- /dev/null +++ b/apps/frontend/src/app/(preview)/p/[id]/page.tsx @@ -0,0 +1,247 @@ +import { internalFetch } from '@gitroom/helpers/utils/internal.fetch'; + +export const dynamic = 'force-dynamic'; + +import { Metadata } from 'next'; +import { isGeneralServerSide } from '@gitroom/helpers/utils/is.general.server.side'; +import Image from 'next/image'; +import clsx from 'clsx'; +import Link from 'next/link'; +import { Button } from '@gitroom/react/form/button'; + +export const metadata: Metadata = { + title: `${isGeneralServerSide() ? 'Postiz' : 'Gitroom'} Preview`, + description: '', +}; + +export default async function Auth({ + params: { id }, + searchParams, +}: { + params: { id: string }; + searchParams: any; +}) { + const post = await (await internalFetch(`/public/posts/${id}`)).json(); + console.log(JSON.stringify(post, null, 2)); + return ( +
+
+
+
+
+
+ +
+ Logo +
+
+ + + + + + +
+ +
+
+
+
+ Publication Date: December 14, 2024 +
+
+
+ +
+
+
+ {post.map((p: any, index: number) => ( +
+
+
+ + John Doe + + {post.length - 1 !== index && ( +
+ )} +
+
+
+

+ {post[0].integration.name} +

+ + @{post[0].integration.profile} + +
+
+
+ + + +
+
+
+
+ ))} +
+
+
+
+

Add a comment

+
+
+