Skip to content

Commit

Permalink
fix: ssr pour les mentions légales (#3395)
Browse files Browse the repository at this point in the history
  • Loading branch information
rap2hpoutre authored Nov 28, 2023
1 parent 5680a6a commit 61d4e7e
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 7 deletions.
2 changes: 1 addition & 1 deletion server/src/http/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ function setupRoutes(app: Application) {
})
)
.get(
"/mentions-legales",
"/api/mentions-legales",
returnResult(async () => {
const recordMap = await notion.getPage("Mentions-l-gales-002a2868ea2f46cdb2d73207d12b6075");
return recordMap;
Expand Down
43 changes: 37 additions & 6 deletions ui/pages/mentions-legales.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,51 @@
import { Center, Spinner } from "@chakra-ui/react";
import { GetServerSidePropsContext } from "next";
import { ExtendedRecordMap } from "notion-types";
import { useEffect, useState } from "react";

import { _get } from "@/common/httpClient";
import { NotionDoc } from "@/components/NotionDoc";
import SimplePage from "@/components/Page/SimplePage";

import "react-notion-x/src/styles.css";

export async function getServerSideProps() {
const data = await _get("/mentions-legales");
return { props: { data } };
}
const isInitialServerSideProps = (context: GetServerSidePropsContext) =>
context.req?.url?.indexOf("/_next/data/") === -1;

export const getServerSideProps = async (context) => {
try {
const isInitial = isInitialServerSideProps(context);
if (!isInitial) return { props: {} };
const dataSSR = await _get("/api/mentions-legales");
return { props: { dataSSR } };
} catch (e) {
console.error(e);
return { props: {} };
}
};

export default function Home({ dataSSR }: { dataSSR: ExtendedRecordMap }) {
const [data, setData] = useState(dataSSR);
const [isLoading, setIsLoading] = useState(!dataSSR);

useEffect(() => {
if (dataSSR) return;
(async () => {
setIsLoading(true);
setData(await _get("/api/mentions-legales"));
setIsLoading(false);
})();
}, []);

export default function Home({ data }: { data: ExtendedRecordMap }) {
return (
<SimplePage title="Mentions légales">
<NotionDoc recordMap={data} />
{isLoading ? (
<Center>
<Spinner />
</Center>
) : (
<NotionDoc recordMap={data} />
)}
</SimplePage>
);
}

0 comments on commit 61d4e7e

Please sign in to comment.