Skip to content

Commit

Permalink
refactor: Simplify theme import logic
Browse files Browse the repository at this point in the history
  • Loading branch information
StreetLamb committed Aug 25, 2024
1 parent 4e7abd4 commit 32f2211
Showing 1 changed file with 10 additions and 16 deletions.
26 changes: 10 additions & 16 deletions frontend/src/components/Markdown/Markdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,23 @@ import {
import CopyButton from "./CopyButton";
import { FiTerminal } from "react-icons/fi";
import { v4 } from "uuid";
import { useEffect, useState } from "react";
import { useEffect } from "react";

const Markdown = ({ content }: { content: string }) => {
const textColor = useColorModeValue("ui.dark", "ui.white");
const secBgColor = useColorModeValue("ui.secondary", "ui.darkSlate");
const { colorMode } = useColorMode();
const [currentColorMode, setCurrentColorMode] = useState(colorMode);

useEffect(() => {
const loadMarkdownCSSStyle = async () => {
if (currentColorMode === "dark") {
await import("highlight.js/styles/github-dark.css");
} else {
await import("highlight.js/styles/github.css");
}
};

loadMarkdownCSSStyle();
}, [currentColorMode]);

useEffect(() => {
setCurrentColorMode(colorMode);
}, [colorMode]);
const loadMarkdownCSSStyle = async () => {
if (colorMode === "dark") {
await import("highlight.js/styles/github-dark.css");
} else {
await import("highlight.js/styles/github.css");
}
};
loadMarkdownCSSStyle();
}, [colorMode]);

return (
<ReactMarkdown
Expand Down

0 comments on commit 32f2211

Please sign in to comment.