Skip to content

Commit c5bd973

Browse files
committed
Introduce 'connecting' status
1 parent 24ceb90 commit c5bd973

File tree

2 files changed

+24
-10
lines changed

2 files changed

+24
-10
lines changed

examples/basic/app/index.tsx

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ interface CommandResult {
1717

1818
function REPL() {
1919
const [client, setClient] = useState<HttpClient | null>(null);
20-
const [isConnected, setIsConnected] = useState(false);
20+
const [connectionStatus, setConnectionStatus] = useState<"disconnected" | "connecting" | "connected">("disconnected");
2121
const [sessionId, setSessionId] = useState<string | null>(null);
2222
const [commandInput, setCommandInput] = useState("");
2323
const [results, setResults] = useState<CommandResult[]>([]);
@@ -109,18 +109,20 @@ function REPL() {
109109
// Initialize connection by creating a session
110110
const initializeConnection = async () => {
111111
try {
112+
setConnectionStatus("connecting");
113+
112114
// Test connection with ping
113115
await httpClient.ping();
114116
console.log("Server is reachable");
115117

116118
// Create a session
117119
const session = await httpClient.createSession();
118120
setSessionId(session);
119-
setIsConnected(true);
121+
setConnectionStatus("connected");
120122
console.log("Connected with session:", session);
121123
} catch (error: any) {
122124
console.error("Failed to connect:", error);
123-
setIsConnected(false);
125+
setConnectionStatus("disconnected");
124126
}
125127
};
126128

@@ -135,7 +137,7 @@ function REPL() {
135137
}, []);
136138

137139
const executeCommand = async () => {
138-
if (!client || !isConnected || !commandInput.trim() || isExecuting) {
140+
if (!client || connectionStatus !== "connected" || !commandInput.trim() || isExecuting) {
139141
return;
140142
}
141143

@@ -199,7 +201,7 @@ function REPL() {
199201
};
200202

201203
const executeStreamingCommand = async () => {
202-
if (!client || !isConnected || !commandInput.trim() || isExecuting) {
204+
if (!client || connectionStatus !== "connected" || !commandInput.trim() || isExecuting) {
203205
return;
204206
}
205207

@@ -287,11 +289,13 @@ function REPL() {
287289
<div className="header">
288290
<h1>HTTP REPL</h1>
289291
<div
290-
className={`connection-status ${
291-
isConnected ? "connected" : "disconnected"
292-
}`}
292+
className={`connection-status ${connectionStatus}`}
293293
>
294-
{isConnected ? `Connected (${sessionId})` : "Disconnected"}
294+
{connectionStatus === "connected"
295+
? `Connected (${sessionId})`
296+
: connectionStatus === "connecting"
297+
? "Connecting..."
298+
: "Disconnected"}
295299
</div>
296300
</div>
297301

@@ -318,7 +322,7 @@ function REPL() {
318322
<button
319323
type="button"
320324
onClick={executeStreamingCommand}
321-
disabled={!isConnected || !commandInput.trim() || isExecuting}
325+
disabled={connectionStatus !== "connected" || !commandInput.trim() || isExecuting}
322326
className="btn btn-stream"
323327
title="Execute with real-time streaming output"
324328
>

examples/basic/app/style.css

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,16 @@ body {
7676
background-color: #f85149;
7777
}
7878

79+
.connection-status.connecting {
80+
background-color: rgba(255, 193, 7, 0.2);
81+
color: #ffc107;
82+
}
83+
84+
.connection-status.connecting::before {
85+
background-color: #ffc107;
86+
animation: pulse 1s infinite;
87+
}
88+
7989
/* Command Input Bar */
8090
.command-bar {
8191
display: flex;

0 commit comments

Comments
 (0)