mirror of
https://github.com/AykutSarac/jsoncrack.com.git
synced 2025-02-04 01:32:54 +08:00
fix: theme color
This commit is contained in:
parent
536353239a
commit
c6147418d9
@ -1,6 +1,6 @@
|
||||
import React from "react";
|
||||
import dynamic from "next/dynamic";
|
||||
import { MantineProvider } from "@mantine/core";
|
||||
import { MantineProvider, useMantineColorScheme } from "@mantine/core";
|
||||
import { ThemeProvider } from "styled-components";
|
||||
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
||||
import { lightTheme, darkTheme } from "src/constants/theme";
|
||||
@ -20,8 +20,13 @@ const queryClient = new QueryClient({
|
||||
export const EditorWrapper: React.FC<{
|
||||
children: React.ReactNode;
|
||||
}> = ({ children }) => {
|
||||
const { setColorScheme } = useMantineColorScheme();
|
||||
const darkmodeEnabled = useConfig(state => state.darkmodeEnabled);
|
||||
|
||||
React.useEffect(() => {
|
||||
if (darkmodeEnabled) setColorScheme("dark");
|
||||
}, [darkmodeEnabled, setColorScheme]);
|
||||
|
||||
return (
|
||||
<ThemeProvider theme={darkmodeEnabled ? darkTheme : lightTheme}>
|
||||
<MantineProvider forceColorScheme={darkmodeEnabled ? "dark" : "light"}>
|
||||
|
@ -2,7 +2,7 @@ import React from "react";
|
||||
import dynamic from "next/dynamic";
|
||||
import Head from "next/head";
|
||||
import { useRouter } from "next/router";
|
||||
import { MantineProvider } from "@mantine/core";
|
||||
import { MantineProvider, useMantineColorScheme } from "@mantine/core";
|
||||
import { ThemeProvider } from "styled-components";
|
||||
import toast from "react-hot-toast";
|
||||
import { darkTheme, lightTheme } from "src/constants/theme";
|
||||
@ -23,6 +23,7 @@ const Graph = dynamic(() => import("src/containers/Views/GraphView").then(c => c
|
||||
|
||||
const WidgetPage = () => {
|
||||
const { query, push, isReady } = useRouter();
|
||||
const { setColorScheme } = useMantineColorScheme();
|
||||
const [theme, setTheme] = React.useState<"dark" | "light">("dark");
|
||||
const checkEditorSession = useFile(state => state.checkEditorSession);
|
||||
const setContents = useFile(state => state.setContents);
|
||||
@ -42,6 +43,7 @@ const WidgetPage = () => {
|
||||
try {
|
||||
if (!event.data?.json) return;
|
||||
if (event.data?.options?.theme === "light" || event.data?.options?.theme === "dark") {
|
||||
setColorScheme(event.data.options.theme);
|
||||
setTheme(event.data.options.theme);
|
||||
}
|
||||
|
||||
@ -55,7 +57,7 @@ const WidgetPage = () => {
|
||||
|
||||
window.addEventListener("message", handler);
|
||||
return () => window.removeEventListener("message", handler);
|
||||
}, [setContents, setDirection, theme]);
|
||||
}, [setColorScheme, setContents, setDirection, theme]);
|
||||
|
||||
return (
|
||||
<MantineProvider forceColorScheme={theme}>
|
||||
|
Loading…
x
Reference in New Issue
Block a user