mirror of
https://gitlab.com/soapbox-pub/shakespeare.git
synced 2026-12-05 16:23:36 +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
@@ -5,6 +5,7 @@ import type { AIMessage } from '@/lib/SessionManager';
|
||||
import { cn } from '@/lib/utils';
|
||||
import { UserMessage } from '@/components/UserMessage';
|
||||
import OpenAI from 'openai';
|
||||
import { useTheme } from '@/hooks/useTheme';
|
||||
|
||||
interface AIMessageItemProps {
|
||||
message: AIMessage;
|
||||
@@ -18,6 +19,7 @@ export const AIMessageItem = memo(({
|
||||
toolCall
|
||||
}: AIMessageItemProps) => {
|
||||
const [isToolExpanded, setIsToolExpanded] = useState(false);
|
||||
const { displayTheme } = useTheme();
|
||||
|
||||
// Get content to display
|
||||
const getContent = () => {
|
||||
@@ -232,6 +234,7 @@ export const AIMessageItem = memo(({
|
||||
<Streamdown
|
||||
className='size-full [&>*:first-child]:mt-0 [&>*:last-child]:mb-0'
|
||||
parseIncompleteMarkdown={isCurrentlyLoading}
|
||||
shikiTheme={displayTheme === 'dark' ? 'github-dark' : 'github-light'}
|
||||
>
|
||||
{getContent()}
|
||||
</Streamdown>
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -247,6 +247,10 @@
|
||||
max-height: 100dvh;
|
||||
}
|
||||
|
||||
pre.shiki {
|
||||
background-color: transparent !important;
|
||||
}
|
||||
|
||||
/* Fallback for browsers that don't support dvh */
|
||||
@supports not (height: 100dvh) {
|
||||
.h-dvh {
|
||||
|
||||
Reference in new issue
Block a user