diff --git a/src/components/App.tsx b/src/components/App.tsx index e46d0ab..1186948 100644 --- a/src/components/App.tsx +++ b/src/components/App.tsx @@ -13,6 +13,7 @@ import { import { ChatRoute } from "../routes/ChatRoute"; import { IndexRoute } from "../routes/IndexRoute"; import { Layout } from "./Layout"; +import { usePrimaryColor } from "../hooks/usePrimaryColor"; const history = createHashHistory(); const location = new ReactLocation({ history }); @@ -26,6 +27,8 @@ export function App() { getInitialValueInEffect: true, }); + const [primaryColor] = usePrimaryColor(); + const toggleColorScheme = (value?: ColorScheme) => setColorScheme(value || (colorScheme === "dark" ? "light" : "dark")); @@ -49,7 +52,7 @@ export function App() { withCSSVariables theme={{ colorScheme, - primaryColor: "teal", + primaryColor, globalStyles: (theme) => ({ body: { backgroundColor: diff --git a/src/components/Chats.tsx b/src/components/Chats.tsx index 5f15bf0..399a6ae 100644 --- a/src/components/Chats.tsx +++ b/src/components/Chats.tsx @@ -42,7 +42,7 @@ export function Chats({ search }: { search: string }) { } - color="teal" + color="primary" chat={chat} label={chat.description} /> diff --git a/src/components/Layout.tsx b/src/components/Layout.tsx index 3c39330..884f486 100644 --- a/src/components/Layout.tsx +++ b/src/components/Layout.tsx @@ -41,6 +41,7 @@ import { LogoText } from "./Logo"; import { Prompts } from "./Prompts"; import { SettingsModal } from "./SettingsModal"; import { config } from "../utils/config"; +import { usePrimaryThemeColor } from "../hooks/usePrimaryColor"; declare global { interface Window { @@ -67,6 +68,8 @@ export function Layout() { theme.colorScheme === "dark" ? theme.colors.dark[4] : theme.colors.gray[2] }`; + const primaryColor = usePrimaryThemeColor(); + useEffect(() => { setOpened(false); }, [router.state.location]); @@ -95,7 +98,7 @@ export function Layout() { diff --git a/src/components/Logo.tsx b/src/components/Logo.tsx index 06469f3..1e7c967 100644 --- a/src/components/Logo.tsx +++ b/src/components/Logo.tsx @@ -1,3 +1,5 @@ +import { usePrimaryThemeColor } from '../hooks/usePrimaryColor' + export function LogoText(props: JSX.IntrinsicElements["svg"]) { return ( - - + + @@ -50,6 +54,8 @@ export function Logo(props: JSX.IntrinsicElements["svg"]) { } export function LogoIcon(props: JSX.IntrinsicElements["svg"]) { + const primaryColor = usePrimaryThemeColor(); + return ( - - + + diff --git a/src/components/SettingsModal.tsx b/src/components/SettingsModal.tsx index 824263c..9606240 100644 --- a/src/components/SettingsModal.tsx +++ b/src/components/SettingsModal.tsx @@ -10,6 +10,11 @@ import { Select, Stack, Text, + useMantineTheme, + Group, + ColorSwatch, + CheckIcon, + rem, } from "@mantine/core"; import { useDisclosure } from "@mantine/hooks"; import { notifications } from "@mantine/notifications"; @@ -18,6 +23,7 @@ import { cloneElement, ReactElement, useEffect, useState } from "react"; import { db } from "../db"; import { config } from "../utils/config"; import { checkOpenAIKey } from "../utils/openai"; +import { usePrimaryColor } from "../hooks/usePrimaryColor"; export function SettingsModal({ children }: { children: ReactElement }) { const [opened, { open, close }] = useDisclosure(false); @@ -29,6 +35,9 @@ export function SettingsModal({ children }: { children: ReactElement }) { const [auth, setAuth] = useState(config.defaultAuth); const [base, setBase] = useState(""); const [version, setVersion] = useState(""); + const [primaryColor, setPrimaryColor] = usePrimaryColor(); + + const theme = useMantineTheme(); const settings = useLiveQuery(async () => { return db.settings.where({ id: "general" }).first(); @@ -335,6 +344,21 @@ export function SettingsModal({ children }: { children: ReactElement }) { + + + + {["red", "pink", "grape", "violet", "indigo", "blue", "cyan", "green", "lime", "yellow", "orange", "teal"].map((color) => ( + setPrimaryColor(color)} + sx={{ color: "#fff", cursor: "pointer" }} + > + {color === primaryColor && } + + ))} + + diff --git a/src/hooks/usePrimaryColor.ts b/src/hooks/usePrimaryColor.ts new file mode 100644 index 0000000..f55a460 --- /dev/null +++ b/src/hooks/usePrimaryColor.ts @@ -0,0 +1,15 @@ +import { useMantineTheme } from '@mantine/core' +import { useLocalStorage } from '@mantine/hooks' + +export function usePrimaryColor() { + return useLocalStorage({ + key: "mantine-primary-color", + defaultValue: "teal", + }) +} + +export function usePrimaryThemeColor() { + const [primaryColor] = usePrimaryColor() + const theme = useMantineTheme() + return theme.colors[primaryColor] +}