diff --git a/apps/frontend/src/app/(site)/preview/[id]/page.tsx b/apps/frontend/src/app/(site)/preview/[id]/page.tsx new file mode 100644 index 00000000..1d40ebbb --- /dev/null +++ b/apps/frontend/src/app/(site)/preview/[id]/page.tsx @@ -0,0 +1,16 @@ +import { Preview } from "@gitroom/frontend/components/preview/preview"; +import { isGeneralServerSide } from "@gitroom/helpers/utils/is.general.server.side"; +import { Metadata } from "next"; + +export const dynamic = 'force-dynamic'; + +export const metadata: Metadata = { + title: `${isGeneralServerSide() ? 'Postiz' : 'Gitroom'} Preview`, + description: 'Make a preview link for your posts.', +} + +export default async function Index({ params }: { params: { id: string } }) { + return ( + + ); +} diff --git a/apps/frontend/src/components/launches/add.edit.model.tsx b/apps/frontend/src/components/launches/add.edit.model.tsx index e0f7db99..0fb8a946 100644 --- a/apps/frontend/src/components/launches/add.edit.model.tsx +++ b/apps/frontend/src/components/launches/add.edit.model.tsx @@ -732,7 +732,7 @@ export const AddEditModal: FC<{ } >
-
+
{!canSendForPublication ? 'Not matching order' : postFor @@ -745,7 +745,7 @@ export const AddEditModal: FC<{ : 'Update'}
{!postFor && ( -
+
+ +
diff --git a/apps/frontend/src/components/launches/calendar.tsx b/apps/frontend/src/components/launches/calendar.tsx index 0918d238..2b90d17e 100644 --- a/apps/frontend/src/components/launches/calendar.tsx +++ b/apps/frontend/src/components/launches/calendar.tsx @@ -137,14 +137,14 @@ export const WeekView = () => { const { currentYear, currentWeek } = useCalendar(); return ( -
+
-
+
{days.map((day, index) => (
{day}
@@ -212,13 +212,13 @@ export const MonthView = () => { }, [currentYear, currentMonth]); return ( -
-
+
+
{days.map((day) => (
{day}
@@ -240,7 +240,7 @@ export const MonthView = () => { ); }; -export const Calendar = () => { +export const Calendar = () => { const { display } = useCalendar(); return ( diff --git a/apps/frontend/src/components/launches/general.preview.component.tsx b/apps/frontend/src/components/launches/general.preview.component.tsx index 52a348d1..dbcb4eed 100644 --- a/apps/frontend/src/components/launches/general.preview.component.tsx +++ b/apps/frontend/src/components/launches/general.preview.component.tsx @@ -9,6 +9,7 @@ import interClass from '@gitroom/react/helpers/inter.font'; export const GeneralPreviewComponent: FC<{maximumCharacters?: number}> = (props) => { const { value: topValue, integration } = useIntegration(); + const mediaDir = useMediaDirectory(); const newValues = useFormatting(topValue, { removeMarkdown: true, @@ -21,7 +22,7 @@ export const GeneralPreviewComponent: FC<{maximumCharacters?: number}> = (props) return (
-
+
{newValues.map((value, index) => (
+
( hideMenu?: boolean; show: boolean; }) => { + const toast = useToaster(); const existingData = useExistingData(); const { allIntegrations, integration, date } = useIntegration(); const [showLinkedinPopUp, setShowLinkedinPopUp] = useState(false); @@ -123,6 +124,7 @@ export const withProvider = function ( })) : [{ content: '' }] ); + const [showTab, setShowTab] = useState(0); const Component = useMemo(() => { @@ -230,6 +232,31 @@ export const withProvider = function ( [InPlaceValue] ); + // Share Post + const handleShare = async () => { + if (!existingData.posts.length) { + return toast.show('No posts available to share', 'warning'); + } + + const postId = existingData.posts[0].id; + + const previewPath = new URL( + `/preview/${postId}`, + window.location.origin + ).toString(); + + try { + if (!navigator.clipboard) { + throw new Error('Clipboard API not available'); + } + await navigator.clipboard.writeText(previewPath); + return toast.show('Link copied to clipboard.', 'success'); + } catch (err) { + if (err instanceof Error) + toast.show(`Failed to copy the link. ${err.message}`, 'warning'); + } + }; + // This is a function if we want to switch from the global editor to edit in place const changeToEditor = useCallback(async () => { if ( @@ -364,7 +391,7 @@ export const withProvider = function (
{!props.hideMenu && (
-
+
+ {(!!SettingsComponent || !!data?.internalPlugs?.length) && (
+
)} -
+
-
+
+
))} diff --git a/apps/frontend/src/components/preview/preview.tsx b/apps/frontend/src/components/preview/preview.tsx new file mode 100644 index 00000000..444ee602 --- /dev/null +++ b/apps/frontend/src/components/preview/preview.tsx @@ -0,0 +1,61 @@ +'use client'; + +import { GeneralPreviewComponent } from '@gitroom/frontend/components/launches/general.preview.component'; +import { IntegrationContext } from '@gitroom/frontend/components/launches/helpers/use.integration'; +import dayjs from 'dayjs'; +import { useCallback } from 'react'; +import useSWR from 'swr'; +import { useFetch } from '@gitroom/helpers/utils/custom.fetch'; +import { LoadingComponent } from '../layout/loading'; + +interface PreviewProps { + id: string; +} + +export const Preview = ({ id }: PreviewProps) => { + const fetch = useFetch(); + + const getPostsMarketplace = useCallback(async () => { + return (await fetch(`/posts/${id}`)).json(); + // eslint-disable-next-line react-hooks/exhaustive-deps + }, [id]); + + const { data, isLoading, error } = useSWR( + `/posts/${id}`, + getPostsMarketplace + ); + + if (isLoading) return ; + + if (!data?.posts || error) + return ( +
+

+ {!data?.posts ? 'No post founded.' : 'Oops! Something went wrong.'}{' '} +

+
+ ); + + const post = data?.posts?.[0]; + if (!post) return null; + + return ( + +
+ +
+
+ ); +};