Prevent conditional loading of ChatView; bug fixes

This commit is contained in:
Saoud Rizwan
2024-07-10 05:48:22 -04:00
parent fc9b1435fd
commit fa2669802d
3 changed files with 35 additions and 14 deletions

View File

@@ -65,7 +65,9 @@ const App: React.FC = () => {
<> <>
{showWelcome ? ( {showWelcome ? (
<WelcomeView apiKey={apiKey} setApiKey={setApiKey} /> <WelcomeView apiKey={apiKey} setApiKey={setApiKey} />
) : showSettings ? ( ) : (
<>
{showSettings && (
<SettingsView <SettingsView
apiKey={apiKey} apiKey={apiKey}
setApiKey={setApiKey} setApiKey={setApiKey}
@@ -73,8 +75,10 @@ const App: React.FC = () => {
setMaxRequestsPerTask={setMaxRequestsPerTask} setMaxRequestsPerTask={setMaxRequestsPerTask}
onDone={() => setShowSettings(false)} onDone={() => setShowSettings(false)}
/> />
) : ( )}
<ChatView messages={claudeMessages} /> {/* Do not conditionally load ChatView, it's expensive and there's state we don't want to lose (user input, disableInput, askResponse promise, etc.) */}
<ChatView messages={claudeMessages} isHidden={showSettings} />
</>
)} )}
</> </>
) )

View File

@@ -13,9 +13,10 @@ import { animateScroll as scroll } from "react-scroll"
interface ChatViewProps { interface ChatViewProps {
messages: ClaudeMessage[] messages: ClaudeMessage[]
isHidden: boolean
} }
// maybe instead of storing state in App, just make chatview always show so dont conditionally load/unload? need to make sure messages are persisted (i remember seeing something about how webviews can be frozen in docs) // maybe instead of storing state in App, just make chatview always show so dont conditionally load/unload? need to make sure messages are persisted (i remember seeing something about how webviews can be frozen in docs)
const ChatView = ({ messages }: ChatViewProps) => { const ChatView = ({ messages, isHidden }: ChatViewProps) => {
//const task = messages.length > 0 ? (messages[0].say === "task" ? messages[0] : undefined) : undefined //const task = messages.length > 0 ? (messages[0].say === "task" ? messages[0] : undefined) : undefined
const task = messages.length > 0 ? messages[0] : undefined // leaving this less safe version here since if the first message is not a task, then the extension is in a bad state and needs to be debugged (see ClaudeDev.abort) const task = messages.length > 0 ? messages[0] : undefined // leaving this less safe version here since if the first message is not a task, then the extension is in a bad state and needs to be debugged (see ClaudeDev.abort)
const modifiedMessages = useMemo(() => combineApiRequests(combineCommandSequences(messages.slice(1))), [messages]) const modifiedMessages = useMemo(() => combineApiRequests(combineCommandSequences(messages.slice(1))), [messages])
@@ -247,6 +248,13 @@ const ChatView = ({ messages }: ChatViewProps) => {
// eslint-disable-next-line react-hooks/exhaustive-deps // eslint-disable-next-line react-hooks/exhaustive-deps
}, []) }, [])
useEffect(() => {
if (!isHidden && !textAreaDisabled) {
textAreaRef.current?.focus()
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [isHidden])
return ( return (
<div <div
style={{ style={{
@@ -255,7 +263,7 @@ const ChatView = ({ messages }: ChatViewProps) => {
left: 0, left: 0,
right: 0, right: 0,
bottom: 0, bottom: 0,
display: "flex", display: isHidden ? "none" : "flex",
flexDirection: "column", flexDirection: "column",
overflow: "hidden", overflow: "hidden",
}}> }}>
@@ -271,8 +279,15 @@ const ChatView = ({ messages }: ChatViewProps) => {
<div style={{ padding: "0 25px" }}> <div style={{ padding: "0 25px" }}>
<h2>What can I do for you?</h2> <h2>What can I do for you?</h2>
<p> <p>
{/* prettier-ignore */} Thanks to{" "}
Thanks to <VSCodeLink href="https://www-cdn.anthropic.com/fed9cc193a14b84131812372d8d5857f8f304c52/Model_Card_Claude_3_Addendum.pdf" style={{ display: "inline" }}>Claude 3.5 Sonnet's agentic coding capabilities</VSCodeLink>, I can handle complex software development tasks step-by-step. With tools that let me read & write files, create entire projects from scratch, and execute terminal commands (after you grant permission), I can assist you in ways that go beyond simple code completion or tech support. <VSCodeLink
href="https://www-cdn.anthropic.com/fed9cc193a14b84131812372d8d5857f8f304c52/Model_Card_Claude_3_Addendum.pdf"
style={{ display: "inline" }}>
Claude 3.5 Sonnet's agentic coding capabilities,
</VSCodeLink>{" "}
I can handle complex software development tasks step-by-step. With tools that let me read &
write files, create entire projects from scratch, and execute terminal commands (after you grant
permission), I can assist you in ways that go beyond simple code completion or tech support.
</p> </p>
</div> </div>
)} )}

View File

@@ -99,7 +99,9 @@ const CodeBlock = ({ code, diff, language, path }: CodeBlockProps) => {
justifyContent: "space-between", justifyContent: "space-between",
alignItems: "center", alignItems: "center",
padding: "6px 10px", padding: "6px 10px",
}}> cursor: "pointer",
}}
onClick={() => setIsExpanded(!isExpanded)}>
<span <span
style={{ style={{
color: "var(--vscode-descriptionForeground)", color: "var(--vscode-descriptionForeground)",