Skip to content

Commit

Permalink
added TopBar to MarkdownPage
Browse files Browse the repository at this point in the history
  • Loading branch information
Yusef Almamari committed Aug 13, 2024
1 parent 657429a commit 88dc54b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 18 deletions.
15 changes: 3 additions & 12 deletions src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,18 +83,9 @@ export default function App() {
<Route path="/collab/:bibId" element={<Bibliography />} />
<Route path="/bib/:bibId/settings" element={<BibliographySettings />} />
<Route path="/collab/:bibId/settings" element={<BibliographySettings />} />
<Route
path="/about"
element={<MarkdownPage title="About CiteEase" filePath="/citeease/markdown/about.md" />}
/>
<Route
path="/terms"
element={<MarkdownPage title="Terms of Use" filePath="/citeease/markdown/terms.md" />}
/>
<Route
path="/privacy"
element={<MarkdownPage title="Privacy Policy" filePath="/citeease/markdown/privacy.md" />}
/>
<Route path="/about" element={<MarkdownPage filePath="/citeease/markdown/about.md" />} />
<Route path="/terms" element={<MarkdownPage filePath="/citeease/markdown/terms.md" />} />
<Route path="/privacy" element={<MarkdownPage filePath="/citeease/markdown/privacy.md" />} />
<Route path="*" element={<NotFoundPage />} />
</Routes>
</main>
Expand Down
21 changes: 15 additions & 6 deletions src/pages/MarkdownPage.jsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,32 @@
import { useState, useEffect } from "react";
import ReactMarkdown from "react-markdown";
import { TopBar } from "../components/ui/MaterialComponents";

export default function MarkdownPage(props) {
const { title, filePath } = props;
export default function MarkdownPage({ title = undefined, filePath }) {
const [content, setContent] = useState("");
const [firstHeading, setFirstHeading] = useState("");

useEffect(() => {
async function fetchContent() {
const response = await fetch(filePath);
const text = await response.text();
setContent(text);

const headings = text.split("\n").filter((line) => line.startsWith("#"));
const firstHeadingMatch = headings.find((heading) => heading.startsWith("# "));
if (firstHeadingMatch && !title) {
setContent(text.replace(firstHeadingMatch, ""));
setFirstHeading(firstHeadingMatch.trim().slice(2));
} else {
setContent(text);
}
}
fetchContent();
}, [filePath]);

return (
<div className="mx-auto max-w-[50rem] p-4">
<h1 className="hidden">{title}</h1> {/* For screen readers and tab title */}
<ReactMarkdown>{content}</ReactMarkdown>
<div className="mx-auto max-w-[50rem]">
<TopBar headline={title || firstHeading} />
<ReactMarkdown className="p-4">{content}</ReactMarkdown>
</div>
);
}

0 comments on commit 88dc54b

Please sign in to comment.