diff --git a/src/components/App.tsx b/src/components/App.tsx index e46d0ab..18d10ec 100644 --- a/src/components/App.tsx +++ b/src/components/App.tsx @@ -3,7 +3,7 @@ import { ColorSchemeProvider, MantineProvider, } from "@mantine/core"; -import { useHotkeys, useLocalStorage } from "@mantine/hooks"; +import { useColorScheme, useHotkeys, useLocalStorage } from "@mantine/hooks"; import { Notifications } from "@mantine/notifications"; import { createHashHistory, @@ -18,11 +18,11 @@ const history = createHashHistory(); const location = new ReactLocation({ history }); export function App() { - const prefersDark = window.matchMedia("(prefers-color-scheme: dark)").matches; + const preferredColorScheme = useColorScheme(); const [colorScheme, setColorScheme] = useLocalStorage({ key: "mantine-color-scheme", - defaultValue: prefersDark ? "dark" : "light", + defaultValue: preferredColorScheme, getInitialValueInEffect: true, }); diff --git a/src/components/Layout.tsx b/src/components/Layout.tsx index 3c39330..7be0f2d 100644 --- a/src/components/Layout.tsx +++ b/src/components/Layout.tsx @@ -21,11 +21,9 @@ import { IconBrandTwitter, IconDatabase, IconMessage, - IconMoonStars, IconPlus, IconSearch, IconSettings, - IconSunHigh, IconX, } from "@tabler/icons-react"; import { Link, Outlet, useNavigate, useRouter } from "@tanstack/react-location"; @@ -187,23 +185,6 @@ export function Layout() {
- {config.allowDarkModeToggle && ( - - toggleColorScheme()} - > - {colorScheme === "dark" ? ( - - ) : ( - - )} - - - )} {config.allowSettingsModal && ( diff --git a/src/components/SettingsModal.tsx b/src/components/SettingsModal.tsx index 824263c..489069d 100644 --- a/src/components/SettingsModal.tsx +++ b/src/components/SettingsModal.tsx @@ -10,6 +10,8 @@ import { Select, Stack, Text, + Tabs, + useMantineColorScheme, } from "@mantine/core"; import { useDisclosure } from "@mantine/hooks"; import { notifications } from "@mantine/notifications"; @@ -18,6 +20,11 @@ import { cloneElement, ReactElement, useEffect, useState } from "react"; import { db } from "../db"; import { config } from "../utils/config"; import { checkOpenAIKey } from "../utils/openai"; +import { + IconBrightnessHalf, + IconMoonStars, + IconSunHigh, +} from "@tabler/icons-react"; export function SettingsModal({ children }: { children: ReactElement }) { const [opened, { open, close }] = useDisclosure(false); @@ -29,6 +36,7 @@ export function SettingsModal({ children }: { children: ReactElement }) { const [auth, setAuth] = useState(config.defaultAuth); const [base, setBase] = useState(""); const [version, setVersion] = useState(""); + const { colorScheme, toggleColorScheme } = useMantineColorScheme(); const settings = useLiveQuery(async () => { return db.settings.where({ id: "general" }).first(); @@ -335,6 +343,33 @@ export function SettingsModal({ children }: { children: ReactElement }) { + {config.allowDarkModeToggle && ( + + + + + } + children="Light Mode" + onClick={() => toggleColorScheme()} + /> + } + children="Dark Mode" + onClick={() => toggleColorScheme()} + /> + } + children="System theme" + onClick={() => toggleColorScheme()} + /> + + + + )}