echoes/frontend/app/root.tsx

74 lines
2.3 KiB
TypeScript
Raw Normal View History

import {
Links,
Meta,
Outlet,
2024-11-27 19:52:49 +08:00
Scripts,
ScrollRestoration,
} from "@remix-run/react";
import { BaseProvider } from "hooks/servicesProvider";
import { MessageProvider } from "hooks/message";
import { MessageContainer } from "hooks/message";
2024-11-27 19:52:49 +08:00
import "~/index.css";
export function Layout({ children }: { children: React.ReactNode }) {
return (
<html lang="en">
<head>
<meta charSet="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="generator" content="echoes" />
<Meta />
<Links />
</head>
2024-11-27 19:52:49 +08:00
<body suppressHydrationWarning={true}>
<BaseProvider>
<MessageProvider>
<MessageContainer />
<Outlet />
</MessageProvider>
2024-11-27 19:52:49 +08:00
</BaseProvider>
<ScrollRestoration />
2024-11-27 19:52:49 +08:00
<script
dangerouslySetInnerHTML={{
__html: `
(function() {
function getInitialColorMode() {
const persistedColorPreference = window.localStorage.getItem('theme');
const hasPersistedPreference = typeof persistedColorPreference === 'string';
if (hasPersistedPreference) {
return persistedColorPreference;
}
const mql = window.matchMedia('(prefers-color-scheme: dark)');
const hasMediaQueryPreference = typeof mql.matches === 'boolean';
if (hasMediaQueryPreference) {
return mql.matches ? 'dark' : 'light';
}
return 'light';
}
const colorMode = getInitialColorMode();
document.documentElement.classList.toggle('dark', colorMode === 'dark');
window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', (e) => {
const newColorMode = e.matches ? 'dark' : 'light';
document.documentElement.classList.toggle('dark', newColorMode === 'dark');
localStorage.setItem('theme', newColorMode);
});
})()
`,
}}
/>
<Scripts />
</body>
</html>
);
}
export default function App() {
return (
2024-11-27 19:52:49 +08:00
<Layout>
<Outlet />
</Layout>
);
}