Add Browser UI

This commit is contained in:
Saoud Rizwan
2024-10-27 07:10:14 -04:00
parent 68df8809ad
commit 04b483a67f

View File

@@ -1,5 +1,5 @@
import deepEqual from "fast-deep-equal" import deepEqual from "fast-deep-equal"
import React, { memo, useEffect, useRef } from "react" import React, { memo, useEffect, useRef, useState } from "react"
import { useSize } from "react-use" import { useSize } from "react-use"
import { BrowserActionResult, ClineMessage, ClineSayBrowserAction } from "../../../../src/shared/ExtensionMessage" import { BrowserActionResult, ClineMessage, ClineSayBrowserAction } from "../../../../src/shared/ExtensionMessage"
import { vscode } from "../../utils/vscode" import { vscode } from "../../utils/vscode"
@@ -16,13 +16,113 @@ interface BrowserSessionRowProps {
onHeightChange: (isTaller: boolean) => void onHeightChange: (isTaller: boolean) => void
} }
/*
- console logs will be aggregate up to that current page
*/
const BrowserSessionRow = memo((props: BrowserSessionRowProps) => { const BrowserSessionRow = memo((props: BrowserSessionRowProps) => {
const { messages, isLast, onHeightChange } = props const { messages, isLast, onHeightChange } = props
const prevHeightRef = useRef(0) const prevHeightRef = useRef(0)
const [consoleLogsExpanded, setConsoleLogsExpanded] = useState(false)
const consoleLogs = "console logs\nhere\n..."
const [browserSessionRow, { height }] = useSize( const [browserSessionRow, { height }] = useSize(
<div style={{ padding: "10px 6px 10px 15px" }}> <div style={{ padding: "10px 6px 10px 15px" }}>
<h3>Browser Session Group</h3> <h3>Browser Session Group</h3>
<div
style={{
borderRadius: 3,
border: "1px solid var(--vscode-editorGroup-border)",
overflow: "hidden",
backgroundColor: CODE_BLOCK_BG_COLOR,
display: "flex",
flexDirection: "column",
justifyContent: "center",
alignItems: "center",
}}>
<div
style={{
width: "calc(100% - 10px)",
boxSizing: "border-box", // includes padding in width calculation
margin: "5px auto",
backgroundColor: "var(--vscode-input-background)",
border: "1px solid var(--vscode-input-border)",
borderRadius: "4px",
padding: "3px 5px",
display: "flex",
alignItems: "center",
justifyContent: "center",
color: "var(--vscode-input-foreground)",
fontSize: "12px",
wordBreak: "break-all", // Allow breaks anywhere
whiteSpace: "normal", // Allow wrapping
}}>
{"https://example.com/thisisalongurl/asdfasfdasdf?asdfasdfasf"}
</div>
<div
style={{
width: "100%",
paddingBottom: "75%", // This creates a 4:3 aspect ratio
position: "relative",
}}>
{/* <div
style={{
position: "absolute",
top: 0,
left: 0,
right: 0,
bottom: 0,
backgroundColor: "red",
}}
/> */}
<div
style={{
position: "absolute",
top: "50%",
left: "50%",
transform: "translate(-50%, -50%)",
display: "flex",
justifyContent: "center",
alignItems: "center",
width: "100%",
height: "100%",
}}>
<span
className="codicon codicon-globe"
style={{
fontSize: "80px",
color: "var(--vscode-input-background)",
}}></span>
</div>
<BrowserCursor style={{ position: "absolute", bottom: "10%", right: "20%" }} />
</div>
<div style={{ width: "100%" }}>
<div
onClick={() => {
if (consoleLogs) {
setConsoleLogsExpanded(!consoleLogsExpanded)
}
}}
style={{
display: "flex",
alignItems: "center",
gap: "4px",
width: "100%",
justifyContent: "flex-start",
cursor: consoleLogs ? "pointer" : "default",
opacity: consoleLogs ? 1 : 0.5,
padding: `8px 8px ${consoleLogsExpanded ? 0 : 8}px 8px`,
}}>
<span className={`codicon codicon-chevron-${consoleLogsExpanded ? "down" : "right"}`}></span>
<span style={{ fontSize: "0.8em" }}>Console Logs</span>
</div>
{consoleLogsExpanded && <CodeBlock source={`${"```"}shell\n${consoleLogs}\n${"```"}`} />}
</div>
</div>
{messages.map((message, index) => ( {messages.map((message, index) => (
<BrowserSessionRowContent key={message.ts} {...props} message={message} /> <BrowserSessionRowContent key={message.ts} {...props} message={message} />
))} ))}
@@ -156,4 +256,22 @@ const BrowserSessionRowContent = ({
} }
} }
const BrowserCursor: React.FC<{ style?: React.CSSProperties }> = ({ style }) => {
// (can't use svgs in vsc extensions)
const cursorBase64 =
"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABUAAAAYCAYAAAAVibZIAAAAAXNSR0IArs4c6QAAAERlWElmTU0AKgAAAAgAAYdpAAQAAAABAAAAGgAAAAAAA6ABA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IbLmgQR3Aw8QSi66hUXulOFbF73GxqjE5BNXWNeAAAAAElFTkSuQmCC"
return (
<img
src={cursorBase64}
style={{
width: "17px",
height: "22px",
...style,
}}
alt="cursor"
/>
)
}
export default BrowserSessionRow export default BrowserSessionRow