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

View File

@@ -11,6 +11,7 @@ export const Sidebar = ({
activeLlm,
llmState,
showDiff,
autoScroll,
input,
output,
autoApproverConfig,
@@ -20,6 +21,7 @@ export const Sidebar = ({
onClearOutput,
onLlmChange,
onNextLlm,
onAutoScrollChange,
onAutoApproverConfigChange,
}) => (
<aside className={`
@@ -51,6 +53,14 @@ export const Sidebar = ({
{showDiff ? 'Hide Diff' : 'Show Diff'}
</Button>
<div className="flex items-center justify-between">
<label>Auto-Scroll</label>
<Switch
checked={autoScroll}
onCheckedChange={onAutoScrollChange}
/>
</div>
<Button
onClick={onApprove}
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,
validationError = null,
language = 'xml',
autoScroll = false,
}) => {
if (showDiff) {
return (
@@ -30,6 +31,7 @@ export const ContentEditor = ({
onChange={onChange}
language={language}
validationError={validationError}
autoScroll={autoScroll}
/>
);
};

View File

@@ -9,28 +9,54 @@ export const StandardEditor = ({
readOnly = false,
language = 'xml',
validationError = null,
}) => (
<Card className="h-[calc(100vh-8rem)]">
<CardContent className="p-0 h-full">
{validationError && (
<Alert variant="destructive" className="m-4">
<AlertDescription>{validationError}</AlertDescription>
</Alert>
)}
<Editor
height="100%"
language={language}
value={content}
onChange={onChange}
options={{
minimap: { enabled: false },
lineNumbers: 'on',
readOnly,
fontSize: 14,
automaticLayout: true,
wordWrap: 'on',
}}
/>
</CardContent>
</Card>
);
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)]">
<CardContent className="p-0 h-full">
{validationError && (
<Alert variant="destructive" className="m-4">
<AlertDescription>{validationError}</AlertDescription>
</Alert>
)}
<Editor
height="100%"
language={language}
value={content}
onChange={onChange}
onMount={handleEditorDidMount}
options={{
minimap: { enabled: false },
lineNumbers: 'on',
readOnly,
fontSize: 14,
automaticLayout: true,
wordWrap: 'on',
}}
/>
</CardContent>
</Card>
);
};