Skip to content

Papermark is the open-source DocSend alternative and secure data rooms with built-in analytics and custom domains.

fix: pass theme option as url params (#1097)

Anne Deepa Prasanna89e2f5a973cc
diff --git a/components/NotionPage.tsx b/components/NotionPage.tsx
index 976a158c..36945267 100644
--- a/components/NotionPage.tsx
+++ b/components/NotionPage.tsx
@@ -11,6 +11,7 @@ import { NotionRenderer } from "react-notion-x";
// core styles shared by all of react-notion-x (required)
import "react-notion-x/src/styles.css";
+import { NotionTheme } from "@/lib/types";
import { determineTextColor } from "@/lib/utils/determine-text-color";
// custom styles for notion
@@ -46,6 +47,7 @@ export const NotionPage = ({
dataroomId,
setDocumentData,
isPreview,
+ theme,
}: {
recordMap: ExtendedRecordMap;
rootPageId?: string;
@@ -58,6 +60,7 @@ export const NotionPage = ({
dataroomId?: string;
setDocumentData?: React.Dispatch<React.SetStateAction<TDocumentData | null>>;
isPreview?: boolean;
+ theme?: NotionTheme;
}) => {
const [pageNumber, setPageNumber] = useState<number>(1); // start on first page
const [maxScrollPercentage, setMaxScrollPercentage] = useState<number>(0);
@@ -315,7 +318,7 @@ export const NotionPage = ({
<NotionRenderer
recordMap={recordMapState}
fullPage={true}
- darkMode={false}
+ darkMode={theme ? theme === "dark" : false}
rootPageId={rootPageId}
disableHeader={true}
components={{
@@ -324,16 +327,16 @@ export const NotionPage = ({
className: string;
href: any;
children:
- | string
- | number
- | boolean
- | React.ReactElement<
- any,
- string | React.JSXElementConstructor<any>
- >
- | React.ReactPortal
- | null
- | undefined;
+ | string
+ | number
+ | boolean
+ | React.ReactElement<
+ any,
+ string | React.JSXElementConstructor<any>
+ >
+ | React.ReactPortal
+ | null
+ | undefined;
}) => {
return (
<div
diff --git a/components/view/dataroom/dataroom-view.tsx b/components/view/dataroom/dataroom-view.tsx
index 3936fd6c..c8226f4d 100644
--- a/components/view/dataroom/dataroom-view.tsx
+++ b/components/view/dataroom/dataroom-view.tsx
@@ -18,7 +18,7 @@ import AccessForm, {
import { useAnalytics } from "@/lib/analytics";
import { SUPPORTED_DOCUMENT_SIMPLE_TYPES } from "@/lib/constants";
-import { LinkWithDataroom, WatermarkConfig } from "@/lib/types";
+import { LinkWithDataroom, NotionTheme, WatermarkConfig } from "@/lib/types";
import DataroomViewer from "../DataroomViewer";
import PagesViewerNew from "../PagesViewerNew";
@@ -66,7 +66,10 @@ export type DEFAULT_DOCUMENT_VIEW_TYPE = {
}[]
| null;
sheetData?: SheetData[] | null;
- notionData?: { recordMap: ExtendedRecordMap | null };
+ notionData?: {
+ recordMap: ExtendedRecordMap | null;
+ theme: NotionTheme | undefined;
+ };
fileType?: string;
ipAddress?: string;
useAdvancedExcelViewer?: boolean;
@@ -340,6 +343,7 @@ export default function DataroomView({
versionNumber={documentData.documentVersionNumber}
brand={brand}
dataroomId={dataroom.id}
+ theme={viewData.notionData.theme}
setDocumentData={setDocumentData}
/>
</div>
diff --git a/components/view/document-view.tsx b/components/view/document-view.tsx
index 4a4d7749..6b3d6c16 100644
--- a/components/view/document-view.tsx
+++ b/components/view/document-view.tsx
@@ -15,7 +15,7 @@ import AccessForm, {
} from "@/components/view/access-form";
import { useAnalytics } from "@/lib/analytics";
-import { LinkWithDocument, WatermarkConfig } from "@/lib/types";
+import { LinkWithDocument, NotionTheme, WatermarkConfig } from "@/lib/types";
import EmailVerificationMessage from "./email-verification-form";
import ViewData from "./view-data";
@@ -69,6 +69,7 @@ export default function DocumentView({
notionData?: {
rootNotionPageId: string | null;
recordMap: ExtendedRecordMap | null;
+ theme: NotionTheme | undefined;
};
brand?: Partial<Brand> | null;
token?: string;
diff --git a/components/view/view-data.tsx b/components/view/view-data.tsx
index a2859821..af5d6d46 100644
--- a/components/view/view-data.tsx
+++ b/components/view/view-data.tsx
@@ -8,7 +8,7 @@ import PDFViewer from "@/components/view/PDFViewer";
import PagesViewerNew from "@/components/view/PagesViewerNew";
import { DEFAULT_DOCUMENT_VIEW_TYPE } from "@/components/view/document-view";
-import { LinkWithDocument, WatermarkConfig } from "@/lib/types";
+import { LinkWithDocument, NotionTheme, WatermarkConfig } from "@/lib/types";
import AdvancedExcelViewer from "./viewer/advanced-excel-viewer";
import ImageViewer from "./viewer/image-viewer";
@@ -33,6 +33,7 @@ export default function ViewData({
notionData?: {
rootNotionPageId: string | null;
recordMap: ExtendedRecordMap | null;
+ theme: NotionTheme | undefined;
};
brand?: Partial<Brand> | null;
showPoweredByBanner?: boolean;
@@ -52,6 +53,7 @@ export default function ViewData({
documentId={document.id}
versionNumber={document.versions[0].versionNumber}
brand={brand}
+ theme={notionData.theme}
/>
) : viewData.fileType === "sheet" && viewData.sheetData ? (
<ExcelViewer
diff --git a/lib/types.ts b/lib/types.ts
index b2fa01a3..cab3e01f 100644
--- a/lib/types.ts
+++ b/lib/types.ts
@@ -282,3 +282,5 @@ export const WatermarkConfigSchema = z.object({
});
export type WatermarkConfig = z.infer<typeof WatermarkConfigSchema>;
+
+export type NotionTheme = "light" | "dark";
diff --git a/pages/api/views-dataroom.ts b/pages/api/views-dataroom.ts
index 21d51ef6..42431ae3 100644
--- a/pages/api/views-dataroom.ts
+++ b/pages/api/views-dataroom.ts
@@ -557,10 +557,10 @@ export default async function handle(
// if document version has pages, then return pages
// otherwise, check if notion document,
- // if notion, return recordMap from document version file
+ // if notion, return recordMap and theme from document version file
// otherwise, return file from document version
let documentPages, documentVersion;
- let recordMap;
+ let recordMap, theme;
let sheetData;
if (hasPages) {
@@ -615,6 +615,10 @@ export default async function handle(
}
if (documentVersion.type === "notion") {
+ // get theme `mode` param from document version file
+ const modeMatch = documentVersion.file.match(/[?&]mode=(dark|light)/);
+ theme = modeMatch ? modeMatch[1] : undefined;
+
let notionPageId = parsePageId(documentVersion.file, { uuid: false });
if (!notionPageId) {
notionPageId = "";
@@ -696,7 +700,7 @@ export default async function handle(
? documentVersion.file
: undefined,
pages: documentPages ? documentPages : undefined,
- notionData: recordMap ? { recordMap } : undefined,
+ notionData: recordMap ? { recordMap, theme } : undefined,
sheetData:
documentVersion &&
documentVersion.type === "sheet" &&
diff --git a/pages/view/[linkId]/index.tsx b/pages/view/[linkId]/index.tsx
index 1ee3b34c..ce65f495 100644
--- a/pages/view/[linkId]/index.tsx
+++ b/pages/view/[linkId]/index.tsx
@@ -16,7 +16,12 @@ import DataroomView from "@/components/view/dataroom/dataroom-view";
import DocumentView from "@/components/view/document-view";
import notion from "@/lib/notion";
-import { CustomUser, LinkWithDataroom, LinkWithDocument } from "@/lib/types";
+import {
+ CustomUser,
+ LinkWithDataroom,
+ LinkWithDocument,
+ NotionTheme,
+} from "@/lib/types";
type DocumentLinkData = {
linkType: "DOCUMENT_LINK";
@@ -52,11 +57,13 @@ export const getStaticProps = async (context: GetStaticPropsContext) => {
if (linkType === "DOCUMENT_LINK") {
let pageId = null;
let recordMap = null;
+ let theme = undefined;
const { type, file, ...versionWithoutTypeAndFile } =
link.document.versions[0];
if (type === "notion") {
+ theme = new URL(file).searchParams.get("mode");
const notionPageId = parsePageId(file, { uuid: false });
if (!notionPageId) {
return {
@@ -88,6 +95,7 @@ export const getStaticProps = async (context: GetStaticPropsContext) => {
notionData: {
rootNotionPageId: null, // do not pass rootNotionPageId to the client
recordMap,
+ theme,
},
meta: {
enableCustomMetatag: link.enableCustomMetatag || false,
@@ -187,6 +195,7 @@ export default function ViewPage({
notionData: {
rootNotionPageId: string | null;
recordMap: ExtendedRecordMap | null;
+ theme: NotionTheme | undefined;
};
meta: {
enableCustomMetatag: boolean;
diff --git a/pages/view/domains/[domain]/[slug]/index.tsx b/pages/view/domains/[domain]/[slug]/index.tsx
index 154c413c..781e74c9 100644
--- a/pages/view/domains/[domain]/[slug]/index.tsx
+++ b/pages/view/domains/[domain]/[slug]/index.tsx
@@ -16,7 +16,12 @@ import DataroomView from "@/components/view/dataroom/dataroom-view";
import DocumentView from "@/components/view/document-view";
import notion from "@/lib/notion";
-import { CustomUser, LinkWithDataroom, LinkWithDocument } from "@/lib/types";
+import {
+ CustomUser,
+ LinkWithDataroom,
+ LinkWithDocument,
+ NotionTheme,
+} from "@/lib/types";
type DocumentLinkData = {
linkType: "DOCUMENT_LINK";
@@ -57,11 +62,13 @@ export const getStaticProps = async (context: GetStaticPropsContext) => {
if (linkType === "DOCUMENT_LINK") {
let pageId = null;
let recordMap = null;
+ let theme = undefined;
const { type, file, ...versionWithoutTypeAndFile } =
link.document.versions[0];
if (type === "notion") {
+ theme = new URL(file).searchParams.get("mode");
const notionPageId = parsePageId(file, { uuid: false });
if (!notionPageId) {
return {
@@ -93,6 +100,7 @@ export const getStaticProps = async (context: GetStaticPropsContext) => {
notionData: {
rootNotionPageId: null, // do not pass rootNotionPageId to the client
recordMap,
+ theme,
},
meta: {
enableCustomMetatag: link.enableCustomMetatag || false,
@@ -190,6 +198,7 @@ export default function ViewPage({
notionData: {
rootNotionPageId: string | null;
recordMap: ExtendedRecordMap | null;
+ theme: NotionTheme | undefined;
};
meta: {
enableCustomMetatag: boolean;