Skip to content

Commit

Permalink
fix: fix theme in ai assit editor (#2212)
Browse files Browse the repository at this point in the history
  • Loading branch information
mscolnick authored Sep 4, 2024
1 parent acc6505 commit 42d8c06
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
10 changes: 9 additions & 1 deletion frontend/src/components/editor/Output.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import { invariant } from "@/utils/invariant";
import { CsvViewer } from "./file-tree/renderers";
import { LazyAnyLanguageCodeMirror } from "@/plugins/impl/code/LazyAnyLanguageCodeMirror";
import { MarimoTracebackOutput } from "./output/MarimoTracebackOutput";
import { useTheme } from "@emotion/react";

/**
* Renders an output based on an OutputMessage.
Expand All @@ -37,6 +38,7 @@ export const OutputRenderer: React.FC<{
onRefactorWithAI?: (opts: { prompt: string }) => void;
}> = memo((props) => {
const { message, onRefactorWithAI } = props;
const theme = useTheme();

// Memoize parsing the json data
const parsedJsonData = useMemo(() => {
Expand Down Expand Up @@ -125,7 +127,13 @@ export const OutputRenderer: React.FC<{
typeof data === "string",
`Expected string data for mime=${mimetype}. Got ${typeof data}`,
);
return <LazyAnyLanguageCodeMirror value={data} language="markdown" />;
return (
<LazyAnyLanguageCodeMirror
theme={theme === "dark" ? "dark" : "light"}
value={data}
language="markdown"
/>
);
default:
logNever(mimetype);
return null;
Expand Down
7 changes: 7 additions & 0 deletions frontend/src/components/editor/ai/add-cell-with-ai.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import {
import { sql } from "@codemirror/lang-sql";
import { SQLLanguageAdapter } from "@/core/codemirror/language/sql";
import { atomWithStorage } from "jotai/utils";
import { type ResolvedTheme, useTheme } from "@/theme/useTheme";

const pythonExtensions = [
customPythonLanguageSupport(),
Expand Down Expand Up @@ -89,6 +90,7 @@ export const AddCellWithAI: React.FC<{
const { createNewCell } = useCellActions();
const [completionBody, setCompletionBody] = useState<object>({});
const [language, setLanguage] = useAtom(languageAtom);
const { theme } = useTheme();

const {
completion,
Expand Down Expand Up @@ -139,6 +141,7 @@ export const AddCellWithAI: React.FC<{
</DropdownMenuContent>
</DropdownMenu>
<PromptInput
theme={theme}
onClose={() => {
setCompletion("");
onClose();
Expand Down Expand Up @@ -207,6 +210,7 @@ export const AddCellWithAI: React.FC<{
value={completion}
className="cm border-t"
onChange={setCompletion}
theme={theme === "dark" ? "dark" : "light"}
extensions={language === "python" ? pythonExtensions : sqlExtensions}
/>
)}
Expand All @@ -219,13 +223,15 @@ interface PromptInputProps {
onClose: () => void;
onChange: (value: string) => void;
onSubmit: () => void;
theme: ResolvedTheme;
}

const PromptInput = ({
value,
onChange,
onSubmit,
onClose,
theme,
}: PromptInputProps) => {
const handleSubmit = onSubmit;
const handleEscape = onClose;
Expand Down Expand Up @@ -327,6 +333,7 @@ const PromptInput = ({
basicSetup={false}
extensions={extensions}
onChange={onChange}
theme={theme === "dark" ? "dark" : "light"}
placeholder={"Generate with AI"}
/>
);
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/plugins/impl/code/any-language-editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
import React, { useMemo } from "react";
import { Logger } from "@/utils/Logger";
import { ErrorBanner } from "../common/error-banner";
import type { ResolvedTheme } from "@/theme/useTheme";

/**
* A code editor that supports any language.
Expand All @@ -21,6 +22,7 @@ import { ErrorBanner } from "../common/error-banner";
const AnyLanguageCodeMirror: React.FC<
ReactCodeMirrorProps & {
language: string;
theme: ResolvedTheme;
}
> = ({ language, extensions = [], ...props }) => {
const isNotSupported = !(language in langs);
Expand Down

0 comments on commit 42d8c06

Please sign in to comment.