From fa2f8c66d1f385aa9b33e776d4bd5e9476f45225 Mon Sep 17 00:00:00 2001 From: Dean-YZG Date: Mon, 6 May 2024 22:23:21 +0800 Subject: [PATCH] feat: old page dark mode compatible --- app/components/MenuLayout/index.tsx | 1 + app/components/mask.tsx | 9 ++-- app/components/new-chat.tsx | 9 ++-- .../Chat/components/ModelSelect.tsx | 8 +++- app/containers/Chat/components/PromptHint.tsx | 17 ++++--- app/containers/Chat/index.module.scss | 47 +++++++++---------- app/containers/index.tsx | 26 +++++++++- app/hooks/useSwitchTheme.ts | 28 +++++++++++ 8 files changed, 98 insertions(+), 47 deletions(-) diff --git a/app/components/MenuLayout/index.tsx b/app/components/MenuLayout/index.tsx index 8145690c8..57f4c0c20 100644 --- a/app/components/MenuLayout/index.tsx +++ b/app/components/MenuLayout/index.tsx @@ -61,6 +61,7 @@ export default function MenuLayout<
diff --git a/app/components/mask.tsx b/app/components/mask.tsx index 82d980686..2a6cd3984 100644 --- a/app/components/mask.tsx +++ b/app/components/mask.tsx @@ -398,7 +398,7 @@ export function ContextPrompts(props: { ); } -export function MaskPage() { +export function MaskPage(props: { className?: string }) { const navigate = useNavigate(); const maskStore = useMaskStore(); @@ -470,9 +470,10 @@ export function MaskPage() { return ( <>
diff --git a/app/components/new-chat.tsx b/app/components/new-chat.tsx index aba3c5b1c..59a26ca32 100644 --- a/app/components/new-chat.tsx +++ b/app/components/new-chat.tsx @@ -72,7 +72,7 @@ function useMaskGroup(masks: Mask[]) { return groups; } -export function NewChat() { +export function NewChat(props: { className?: string }) { const chatStore = useChatStore(); const maskStore = useMaskStore(); @@ -115,9 +115,10 @@ export function NewChat() { return (
{ return ( {} })} + content={ +
+ {content({ close: () => {} })} +
+ } trigger="click" noArrow placement={ position?.poi.relativePosition[1] !== Orientation.bottom ? "lb" : "lt" } - popoverClassName="border border-select-popover rounded-lg shadow-select-popover-shadow w-actions-popover bg-model-select-popover-panel max-h-chat-actions-select-model-popover w-[280px]" + popoverClassName="border border-select-popover rounded-lg shadow-select-popover-shadow w-actions-popover bg-model-select-popover-panel w-[280px]" onShow={(e) => { if (e) { autoScrollToSelectedModal(); diff --git a/app/containers/Chat/components/PromptHint.tsx b/app/containers/Chat/components/PromptHint.tsx index ca7d59857..f956ebc43 100644 --- a/app/containers/Chat/components/PromptHint.tsx +++ b/app/containers/Chat/components/PromptHint.tsx @@ -67,15 +67,14 @@ export default function PromptHints(props: { return (
{internalPrompts.map((prompt, i) => (
} /> - } /> - } /> + + } + /> + + } + /> } /> } /> diff --git a/app/hooks/useSwitchTheme.ts b/app/hooks/useSwitchTheme.ts index 4fb094946..ac8132d62 100644 --- a/app/hooks/useSwitchTheme.ts +++ b/app/hooks/useSwitchTheme.ts @@ -1,5 +1,6 @@ import { useLayoutEffect } from "react"; import { Theme, useAppConfig } from "@/app/store/config"; +import { getCSSVar } from "../utils"; const DARK_CLASS = "dark-new"; const LIGHT_CLASS = "light-new"; @@ -17,4 +18,31 @@ export function useSwitchTheme() { document.body.classList.add(LIGHT_CLASS); } }, [config.theme]); + + useLayoutEffect(() => { + document.body.classList.remove("light"); + document.body.classList.remove("dark"); + + if (config.theme === "dark") { + document.body.classList.add("dark"); + } else if (config.theme === "light") { + document.body.classList.add("light"); + } + + const metaDescriptionDark = document.querySelector( + 'meta[name="theme-color"][media*="dark"]', + ); + const metaDescriptionLight = document.querySelector( + 'meta[name="theme-color"][media*="light"]', + ); + + if (config.theme === "auto") { + metaDescriptionDark?.setAttribute("content", "#151515"); + metaDescriptionLight?.setAttribute("content", "#fafafa"); + } else { + const themeColor = getCSSVar("--theme-color"); + metaDescriptionDark?.setAttribute("content", themeColor); + metaDescriptionLight?.setAttribute("content", themeColor); + } + }, [config.theme]); }