autoscroll wip

This commit is contained in:
Niels Geens
2024-11-22 17:43:23 +01:00
parent 69f4f8a6fc
commit eb89564aac
5 changed files with 67 additions and 62 deletions

View File

@@ -39,6 +39,7 @@ const App = () => {
const [activeTab, setActiveTab] = useState(Tabs.CONTEXT); const [activeTab, setActiveTab] = useState(Tabs.CONTEXT);
const [showDiff, setShowDiff] = useState(false); const [showDiff, setShowDiff] = useState(false);
const [showSidebar, setShowSidebar] = useState(false); const [showSidebar, setShowSidebar] = useState(false);
const [autoScroll, setAutoScroll] = useState(false);
// WebSocket connections // WebSocket connections
const wsRoot = `${window.location.protocol === 'https:' ? 'wss:' : 'ws:'}//${window.location.host}/ws` const wsRoot = `${window.location.protocol === 'https:' ? 'wss:' : 'ws:'}//${window.location.host}/ws`
@@ -239,7 +240,7 @@ const App = () => {
originalContent={generatedContext} originalContent={generatedContext}
modifiedContent={modifiedContext} modifiedContent={modifiedContext}
onChange={handleContextEdit} onChange={handleContextEdit}
validationError={null} autoScroll={autoScroll}
/> />
)} )}
{activeTab === Tabs.RESPONSE && ( {activeTab === Tabs.RESPONSE && (
@@ -251,7 +252,6 @@ const App = () => {
...prev, ...prev,
[activeLlm]: value [activeLlm]: value
}))} }))}
validationError={null}
/> />
)} )}
{activeTab === Tabs.INPUT && ( {activeTab === Tabs.INPUT && (
@@ -276,6 +276,8 @@ const App = () => {
activeLlm={activeLlm} activeLlm={activeLlm}
llmState={llms[activeLlm]} llmState={llms[activeLlm]}
showDiff={showDiff} showDiff={showDiff}
autoScroll={autoScroll}
onAutoScrollChange={(enabled) => setAutoScroll(enabled)}
input={input} input={input}
output={output} output={output}
autoApproverConfig={autoApproverConfig} autoApproverConfig={autoApproverConfig}

View File

@@ -11,6 +11,7 @@ export const Sidebar = ({
activeLlm, activeLlm,
llmState, llmState,
showDiff, showDiff,
autoScroll,
input, input,
output, output,
autoApproverConfig, autoApproverConfig,
@@ -20,6 +21,7 @@ export const Sidebar = ({
onClearOutput, onClearOutput,
onLlmChange, onLlmChange,
onNextLlm, onNextLlm,
onAutoScrollChange,
onAutoApproverConfigChange, onAutoApproverConfigChange,
}) => ( }) => (
<aside className={` <aside className={`
@@ -51,6 +53,14 @@ export const Sidebar = ({
{showDiff ? 'Hide Diff' : 'Show Diff'} {showDiff ? 'Hide Diff' : 'Show Diff'}
</Button> </Button>
<div className="flex items-center justify-between">
<label>Auto-Scroll</label>
<Switch
checked={autoScroll}
onCheckedChange={onAutoScrollChange}
/>
</div>
<Button <Button
onClick={onApprove} onClick={onApprove}
disabled={llmState === LlmState.INFERENCE} disabled={llmState === LlmState.INFERENCE}

View File

@@ -1,35 +0,0 @@
import React from 'react';
import Editor from '@monaco-editor/react';
import { Card, CardContent } from '@/components/ui/card';
import { Alert, AlertDescription } from '@/components/ui/alert';
export const BaseEditor = ({
content,
onChange,
readOnly = false,
language = 'xml',
validationError = null,
}) => (
<Card className="h-full">
<CardContent className="p-0 h-full">
{validationError && (
<Alert variant="destructive" className="m-4">
<AlertDescription>{validationError}</AlertDescription>
</Alert>
)}
<Editor
height="100%"
defaultLanguage={language}
value={content}
onChange={onChange}
options={{
minimap: { enabled: false },
lineNumbers: 'on',
readOnly,
fontSize: 14,
automaticLayout: true,
}}
/>
</CardContent>
</Card>
);

View File

@@ -9,6 +9,7 @@ export const ContentEditor = ({
onChange, onChange,
validationError = null, validationError = null,
language = 'xml', language = 'xml',
autoScroll = false,
}) => { }) => {
if (showDiff) { if (showDiff) {
return ( return (
@@ -30,6 +31,7 @@ export const ContentEditor = ({
onChange={onChange} onChange={onChange}
language={language} language={language}
validationError={validationError} validationError={validationError}
autoScroll={autoScroll}
/> />
); );
}; };

View File

@@ -9,7 +9,31 @@ export const StandardEditor = ({
readOnly = false, readOnly = false,
language = 'xml', language = 'xml',
validationError = null, validationError = null,
}) => ( autoScroll = false,
}) => {
const editorRef = React.useRef(null);
const scrollToBottom = () => {
if (editorRef.current && autoScroll) {
const model = editorRef.current.getModel();
const lineCount = model.getLineCount();
editorRef.current.revealPositionInCenter({
lineNumber: lineCount,
column: 1
});
}
};
const handleEditorDidMount = (editor) => {
editorRef.current = editor;
scrollToBottom();
};
React.useEffect(() => {
scrollToBottom();
}, [content, autoScroll]);
return (
<Card className="h-[calc(100vh-8rem)]"> <Card className="h-[calc(100vh-8rem)]">
<CardContent className="p-0 h-full"> <CardContent className="p-0 h-full">
{validationError && ( {validationError && (
@@ -22,6 +46,7 @@ export const StandardEditor = ({
language={language} language={language}
value={content} value={content}
onChange={onChange} onChange={onChange}
onMount={handleEditorDidMount}
options={{ options={{
minimap: { enabled: false }, minimap: { enabled: false },
lineNumbers: 'on', lineNumbers: 'on',
@@ -33,4 +58,5 @@ export const StandardEditor = ({
/> />
</CardContent> </CardContent>
</Card> </Card>
); );
};