Skip to content

Commit

Permalink
fix the MathJax does not rerender after changes
Browse files Browse the repository at this point in the history
  • Loading branch information
xyTom committed Apr 23, 2024
1 parent 2c36e23 commit eca24ca
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
6 changes: 4 additions & 2 deletions src/renderer/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ declare global {

function App() {
const [screenShotResult, setscreenShotResult] = useState(null);
const [result, setResult] = useState("null");
const [result, setResult] = useState(null);
const [loading, setLoading] = useState(false);

//retry button
Expand Down Expand Up @@ -309,7 +309,9 @@ function App() {
{screenShotResult && <img src={`data:image/png;base64,${screenShotResult}`} alt="screenshot" className="mb-2 rounded-lg object-center border border-gray-100 dark:border-gray-800 mx-auto" />}

<div className="flex space-x-2 mb-2 justify-center">
<PromptSelect handlePromptChange={handlePromptChange} model={model} />
<PromptSelect handlePromptChange={handlePromptChange} model={model} disabled={loading}/>
{/* <button onClick={() => setLoading(!loading)} className="btn"
>set loading</button> */}

{/* When there is result or onError, show the retry button */}
{(result)
Expand Down
15 changes: 13 additions & 2 deletions src/renderer/components/displayLatex.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
import { MathJax } from "better-react-mathjax"
import React from "react"
import React, { useEffect } from "react"

declare global {
interface Window {
MathJax: any;
}
}
export default function displayLatexResult(props: { latex: string}) {

//rerender the latex result when props.latex is changed
useEffect(() => {
// Assuming MathJax object is available globally
if (window.MathJax) {
window.MathJax.typesetPromise();
}
}, [props.latex]);
return (
<div className="grid w-full gap-2 pb-3 min-w-60">
<MathJax>
Expand Down
4 changes: 2 additions & 2 deletions src/renderer/components/promptSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ import React from "react"
import { Tabs, TabsList, TabsTrigger } from "../components/ui/tabs"
import { promptOptions } from "../lib/models"

export default function promptSelect(props: { handlePromptChange: Function, model: string}) {
export default function promptSelect(props: { handlePromptChange: Function, model: string, disabled: boolean}) {
const options = promptOptions as { [key: string]: { value: string; label: string; prompt: string; }[] };
return (
<Tabs defaultValue="Auto" onValueChange={(value) => props.handlePromptChange(value)}>
<TabsList>
{options[props.model].map((prompt,index) => (
<TabsTrigger key={index} value={prompt.value}>{prompt.label}</TabsTrigger>
<TabsTrigger disabled={props.disabled} key={index} value={prompt.value}>{prompt.label}</TabsTrigger>
))}
</TabsList>
</Tabs>
Expand Down

0 comments on commit eca24ca

Please sign in to comment.