Skip to content

Commit

Permalink
fix: fix dark mode not updated bug (#251)
Browse files Browse the repository at this point in the history
* feat: add iframe key to refresh content based on color mode

* refactor: optimize iframe key management in editor component
  • Loading branch information
HashCookie authored Jul 25, 2024
1 parent bc2aca8 commit d2853f6
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/pages/editor.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from "react";
import React, {useEffect, useState} from "react";
import Layout from "@theme/Layout";
import Giscus from "@giscus/react";
import {useColorMode} from "@docusaurus/theme-common";
Expand All @@ -8,11 +8,17 @@ function EditorContent() {
const {colorMode} = useColorMode();
const {i18n} = useDocusaurusContext();
const currentLanguage = i18n.currentLocale;
const [editorUrl, setEditorUrl] = useState("");

useEffect(() => {
setEditorUrl(`https://editor.casbin.org/?theme=${colorMode}&lang=${currentLanguage}`);
}, [colorMode, currentLanguage]);

return (
<>
<div className="editor-container">
<iframe
src={`https://editor.casbin.org/?theme=${colorMode}&lang=${currentLanguage}`}
src={editorUrl}
className="editor-iframe"
title="Casbin-editor"
/>
Expand Down

0 comments on commit d2853f6

Please sign in to comment.