mirror of
https://gitlab.com/soapbox-pub/shakespeare.git
synced 2026-12-06 00:27:24 +00:00
Add dark support to code blocks in AI messages
This commit is contained in:
4 files changed
+43
-1
No files matched your search
@@ -0,0 +1,24 @@
|
||||
import { useEffect, useState } from "react";
|
||||
|
||||
export function useSystemTheme() {
|
||||
const getSystemTheme = (): "dark" | "light" =>
|
||||
window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light";
|
||||
|
||||
const [theme, setTheme] = useState<"dark" | "light">(getSystemTheme);
|
||||
|
||||
useEffect(() => {
|
||||
const mediaQuery = window.matchMedia("(prefers-color-scheme: dark)");
|
||||
|
||||
const handler = (event: MediaQueryListEvent): void => {
|
||||
setTheme(event.matches ? "dark" : "light");
|
||||
};
|
||||
|
||||
// Attach listener
|
||||
mediaQuery.addEventListener("change", handler);
|
||||
|
||||
// Cleanup
|
||||
return () => mediaQuery.removeEventListener("change", handler);
|
||||
}, []);
|
||||
|
||||
return theme;
|
||||
}
|
||||
+12
-1
@@ -1,15 +1,26 @@
|
||||
import { type Theme } from "@/contexts/AppContext";
|
||||
import { useAppContext } from "@/hooks/useAppContext";
|
||||
import { useSystemTheme } from "./useSystemTheme";
|
||||
|
||||
/**
|
||||
* Hook to get and set the active theme
|
||||
* @returns Theme context with theme and setTheme
|
||||
*/
|
||||
export function useTheme(): { theme: Theme; setTheme: (theme: Theme) => void } {
|
||||
export function useTheme(): {
|
||||
theme: Theme;
|
||||
systemTheme: "light" | "dark";
|
||||
displayTheme: "light" | "dark";
|
||||
setTheme: (theme: Theme) => void;
|
||||
} {
|
||||
const { config, updateConfig } = useAppContext();
|
||||
|
||||
const systemTheme = useSystemTheme();
|
||||
const displayTheme = config.theme === 'system' ? systemTheme : config.theme;
|
||||
|
||||
return {
|
||||
theme: config.theme,
|
||||
systemTheme,
|
||||
displayTheme,
|
||||
setTheme: (theme: Theme) => {
|
||||
updateConfig((currentConfig) => ({
|
||||
...currentConfig,
|
||||
|
||||
Reference in new issue
Block a user