Skip to content

Commit 3249b36

Browse files
huamanrajapsinghdev
authored andcommitted
fix: dynamic page for displaying sheet module content with a dedicated renderer and styling.
1 parent d8e651e commit 3249b36

File tree

3 files changed

+96
-95
lines changed

3 files changed

+96
-95
lines changed

apps/web/src/app/(main)/sheet/[moduleId]/page.tsx

Lines changed: 5 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { notFound } from "next/navigation";
22
import { getSheetModules } from "@/data/sheet";
33
import { SheetModuleHeader } from "@/components/sheet/SheetModuleHeader";
4+
import { SheetContentRenderer } from "@/components/sheet/SheetContentRenderer";
5+
import styles from "./sheet-content.module.css";
46

57
interface PageProps {
68
params: Promise<{ moduleId: string }>;
@@ -17,98 +19,6 @@ export default async function SheetModulePage({ params }: PageProps) {
1719

1820
return (
1921
<>
20-
<style
21-
dangerouslySetInnerHTML={{
22-
__html: `
23-
.sheet-content {
24-
color: rgb(225, 225, 225);
25-
line-height: 1.75;
26-
}
27-
.sheet-content p {
28-
margin-bottom: 1rem;
29-
color: rgb(225, 225, 225);
30-
}
31-
.sheet-content h3 {
32-
margin-top: 2.5rem;
33-
margin-bottom: 1.25rem;
34-
font-size: 1.125rem;
35-
font-weight: 600;
36-
color: rgb(148, 85, 244);
37-
}
38-
.sheet-content h2 {
39-
margin-top: 2rem;
40-
margin-bottom: 0.75rem;
41-
font-size: 1.25rem;
42-
font-weight: 600;
43-
color: rgb(255, 255, 255);
44-
}
45-
.sheet-content h1 {
46-
margin-top: 2rem;
47-
margin-bottom: 1rem;
48-
font-size: 1.875rem;
49-
font-weight: 700;
50-
color: rgb(255, 255, 255);
51-
}
52-
.sheet-content a {
53-
color: rgb(148, 85, 244);
54-
text-decoration: underline;
55-
}
56-
.sheet-content a:hover {
57-
color: rgb(168, 105, 255);
58-
}
59-
.sheet-content strong {
60-
font-weight: 600;
61-
color: rgb(255, 255, 255);
62-
}
63-
.sheet-content em {
64-
font-style: italic;
65-
}
66-
.sheet-content ul,
67-
.sheet-content ol {
68-
padding-left: 1.5rem;
69-
margin-bottom: 1rem;
70-
color: rgb(225, 225, 225);
71-
}
72-
.sheet-content li {
73-
margin-bottom: 0.5rem;
74-
}
75-
.sheet-content img {
76-
width: 60%;
77-
max-width: 60%;
78-
height: auto;
79-
border-radius: 0.5rem;
80-
margin: 1.25rem auto;
81-
display: block;
82-
}
83-
.sheet-content blockquote {
84-
border-left: 2px solid rgb(148, 85, 244);
85-
padding-left: 1rem;
86-
font-style: italic;
87-
color: rgb(209, 209, 209);
88-
margin: 1rem 0;
89-
}
90-
.sheet-content code {
91-
color: rgb(148, 85, 244);
92-
background-color: rgb(26, 26, 26);
93-
padding: 0.125rem 0.375rem;
94-
border-radius: 0.25rem;
95-
font-size: 0.875rem;
96-
}
97-
.sheet-content pre {
98-
background-color: rgb(26, 26, 26);
99-
border: 1px solid rgb(37, 37, 37);
100-
border-radius: 0.5rem;
101-
padding: 1rem;
102-
overflow-x: auto;
103-
margin: 1rem 0;
104-
}
105-
.sheet-content pre code {
106-
background: none;
107-
padding: 0;
108-
}
109-
`,
110-
}}
111-
/>
11222
<div className="min-h-screen bg-surface-primary">
11323
<div className="max-w-4xl mx-auto px-4 py-8 md:px-8">
11424
<SheetModuleHeader
@@ -141,9 +51,9 @@ export default async function SheetModulePage({ params }: PageProps) {
14151
)}
14252
</header>
14353

144-
<div
145-
className="sheet-content"
146-
dangerouslySetInnerHTML={{ __html: sheetModule.docContent }}
54+
<SheetContentRenderer
55+
className={styles.sheetContent}
56+
content={sheetModule.docContent}
14757
/>
14858
</article>
14959
</div>
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
.sheetContent {
2+
@apply text-text-secondary leading-7;
3+
}
4+
5+
.sheetContent p {
6+
@apply mb-4 text-text-secondary;
7+
}
8+
9+
.sheetContent h3 {
10+
@apply mt-10 mb-5 text-lg font-semibold text-brand-purple;
11+
}
12+
13+
.sheetContent h2 {
14+
@apply mt-8 mb-3 text-xl font-semibold text-text-primary;
15+
}
16+
17+
.sheetContent h1 {
18+
@apply mt-8 mb-4 text-3xl font-bold text-text-primary;
19+
}
20+
21+
.sheetContent a {
22+
@apply text-brand-purple underline;
23+
}
24+
25+
.sheetContent a:hover {
26+
@apply text-brand-purple-light;
27+
}
28+
29+
.sheetContent strong {
30+
@apply font-semibold text-text-primary;
31+
}
32+
33+
.sheetContent em {
34+
@apply italic;
35+
}
36+
37+
.sheetContent ul,
38+
.sheetContent ol {
39+
@apply pl-6 mb-4 text-text-secondary;
40+
}
41+
42+
.sheetContent li {
43+
@apply mb-2;
44+
}
45+
46+
.sheetContent img {
47+
@apply w-[60%] max-w-[60%] h-auto rounded-lg mx-auto my-5 block;
48+
}
49+
50+
.sheetContent blockquote {
51+
@apply border-l-2 border-brand-purple pl-4 italic text-text-tertiary my-4;
52+
}
53+
54+
.sheetContent code {
55+
@apply text-brand-purple bg-surface-tertiary px-1.5 py-0.5 rounded text-sm;
56+
}
57+
58+
.sheetContent pre {
59+
@apply bg-surface-tertiary border border-border rounded-lg p-4 overflow-x-auto my-4;
60+
}
61+
62+
.sheetContent pre code {
63+
@apply bg-transparent p-0;
64+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
"use client";
2+
3+
import React, { useEffect, useState } from "react";
4+
import DOMPurify from "dompurify";
5+
6+
interface SheetContentRendererProps {
7+
content: string;
8+
className?: string;
9+
}
10+
11+
export function SheetContentRenderer({
12+
content,
13+
className,
14+
}: SheetContentRendererProps) {
15+
const [sanitizedContent, setSanitizedContent] = useState("");
16+
17+
useEffect(() => {
18+
setSanitizedContent(DOMPurify.sanitize(content));
19+
}, [content]);
20+
21+
return (
22+
<div
23+
className={className}
24+
dangerouslySetInnerHTML={{ __html: sanitizedContent }}
25+
/>
26+
);
27+
}

0 commit comments

Comments
 (0)