Skip to content

Commit 1c6cb7a

Browse files
committed
feat: server side rendering of panes
1 parent e777dc0 commit 1c6cb7a

File tree

4 files changed

+31
-16
lines changed

4 files changed

+31
-16
lines changed

packages/app/components/landing/panes/posts.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,9 +139,9 @@ const PostCard: React.FC<{
139139
h5: ({ children }) => <h5 className="mb-2 mt-8 text-lg font-bold">{children}</h5>,
140140
h6: ({ children }) => <h6 className="text-medium mt-8 font-bold">{children}</h6>,
141141
p: ({ children }) => (
142-
<motion.p className="mb-4 break-words text-justify text-plug-green/60 leading-tight">
142+
<motion.div className="mb-4 break-words text-justify text-plug-green/60 leading-tight">
143143
{children}
144-
</motion.p>
144+
</motion.div>
145145
),
146146
ul: ({ children }) => (
147147
<motion.ul className="ml-8 list-disc break-words text-plug-green/60">
@@ -331,7 +331,7 @@ export const PostsPreview: React.FC<PostsProps> = ({ posts }) => {
331331
built by our team? Let us make a decision.
332332
</p>
333333

334-
<p className="mt-8 flex w-full flex-row items-center justify-between gap-8 font-bold">
334+
<div className="mt-8 flex w-full flex-row items-center justify-between gap-8 font-bold">
335335
<button
336336
className="flex cursor-pointer flex-row items-center gap-2 transition-all duration-200 ease-in-out hover:gap-4 group"
337337
onClick={() => handlePreview("api")}
@@ -344,7 +344,7 @@ export const PostsPreview: React.FC<PostsProps> = ({ posts }) => {
344344
<span className="whitespace-nowrap">Use our app</span>
345345
<ArrowRight className="inline-block h-4 w-4 opacity-40 group-hover:opacity-100 transition-all duration-200 ease-in-out" />
346346
</Link>
347-
</p>
347+
</div>
348348
</motion.div>
349349
</div>
350350
) : (

packages/app/contexts/PreviewProvider.tsx

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,14 @@ export const PreviewContext = createContext<{
1515
handleCollapse: () => { }
1616
});
1717

18-
export const PreviewProvider: React.FC<React.PropsWithChildren> = ({ children }) => {
18+
type PreviewProviderProps = React.PropsWithChildren<{
19+
initialPreview?: string | null
20+
}>
21+
22+
export const PreviewProvider: React.FC<PreviewProviderProps> = ({ children, initialPreview }) => {
1923
const router = useRouter()
2024

21-
const [preview, setPreview] = useState<string | undefined>(undefined);
25+
const [preview, setPreview] = useState<string | undefined>(initialPreview ?? undefined);
2226
const [collapsed, setCollapsed] = useState<boolean>(false);
2327

2428
const handlePreview = (service: string | undefined) => {
@@ -44,9 +48,9 @@ export const PreviewProvider: React.FC<React.PropsWithChildren> = ({ children })
4448

4549
useEffect(() => {
4650
if (!router.isReady) return
47-
const preview = router.query.p as string | undefined
48-
if (preview && ["app", "api", "posts", "terms"].includes(preview)) {
49-
setPreview(preview as "app" | "api" | "posts" | "terms")
51+
const queryPreview = router.query.p as string | undefined
52+
if (queryPreview && ["app", "api", "posts", "terms", "jobs"].includes(queryPreview)) {
53+
setPreview(queryPreview)
5054
}
5155
}, [router.isReady, router.query.p])
5256

packages/app/pages/_app.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ const PlugApp: FC<AppProps> = ({ Component, pageProps }) => {
4949

5050
<GoogleTagManager gtmId={GTM_ID} />
5151

52-
<PreviewProvider>
52+
<PreviewProvider initialPreview={pageProps.initialPreview}>
5353
<Component {...pageProps} />
5454
</PreviewProvider>
5555
</>

packages/app/pages/index.tsx

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import { GetStaticProps } from "next"
1+
import { GetServerSideProps, InferGetServerSidePropsType } from "next"
22
import Head from "next/head"
3-
import { InferGetStaticPropsType } from "next/types"
43
import { useEffect, useRef, useState } from "react"
54

65
import { AnimatePresence, motion } from "framer-motion"
@@ -17,14 +16,26 @@ import { usePreview } from "@/contexts/PreviewProvider"
1716
import { getPosts, Post } from "@/lib/functions/posts"
1817
import { cn } from "@/lib/utils/style"
1918

19+
const VALID_PREVIEWS = ["app", "api", "posts", "terms", "jobs"] as const
20+
type ValidPreview = typeof VALID_PREVIEWS[number]
2021

21-
export const getStaticProps = (async () => {
22+
export const getServerSideProps = (async (context) => {
2223
const { posts } = getPosts(1, 100)
2324

24-
return { props: { posts } }
25-
}) satisfies GetStaticProps<{ posts: Post[] }>
25+
const queryPreview = context.query.p as string | undefined
26+
const initialPreview = queryPreview && VALID_PREVIEWS.includes(queryPreview as ValidPreview)
27+
? queryPreview
28+
: undefined
2629

27-
const Page = ({ posts }: InferGetStaticPropsType<typeof getStaticProps>) => {
30+
return {
31+
props: {
32+
posts,
33+
initialPreview: initialPreview ?? null
34+
}
35+
}
36+
}) satisfies GetServerSideProps<{ posts: Post[], initialPreview: string | null }>
37+
38+
const Page = ({ posts }: InferGetServerSidePropsType<typeof getServerSideProps>) => {
2839
const { preview, handlePreview } = usePreview()
2940

3041
const leftPaneRef = useRef<HTMLDivElement>(null)

0 commit comments

Comments
 (0)