Skip to content

Commit 936a50b

Browse files
committed
remove Command verbiage, refactor slightly
1 parent 58e796a commit 936a50b

File tree

2 files changed

+34
-40
lines changed

2 files changed

+34
-40
lines changed

client/src/App.tsx

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import ResourcesTab, { Resource } from "./components/ResourcesTab";
1919
import NotificationsTab from "./components/NotificationsTab";
2020
import PromptsTab, { Prompt } from "./components/PromptsTab";
2121
import ToolsTab, { Tool as ToolType } from "./components/ToolsTab";
22-
import CommandHistory from "./components/CommandHistory";
22+
import History from "./components/CommandHistory";
2323

2424
const App = () => {
2525
const [socket, setSocket] = useState<WebSocket | null>(null);
@@ -40,8 +40,8 @@ const App = () => {
4040
"/Users/ashwin/code/example-servers/build/everything/index.js",
4141
);
4242
const [mcpConnected, setMcpConnected] = useState<boolean>(false);
43-
const [commandHistory, setCommandHistory] = useState<
44-
Array<{ command: string; response: string | null }>
43+
const [requestHistory, setRequestHistory] = useState<
44+
Array<{ request: string; response: string | null }>
4545
>([]);
4646

4747
useEffect(() => {
@@ -59,34 +59,28 @@ const App = () => {
5959
if (message.type === "resources") {
6060
setResources(message.data.resources);
6161
setError(null);
62-
updateCommandHistory(message);
6362
} else if (message.type === "resource") {
6463
setResourceContent(JSON.stringify(message.data, null, 2));
6564
setError(null);
66-
updateCommandHistory(message);
6765
} else if (message.type === "prompts") {
6866
setPrompts(message.data.prompts);
6967
setError(null);
70-
updateCommandHistory(message);
7168
} else if (message.type === "prompt") {
7269
setPromptContent(JSON.stringify(message.data, null, 2));
7370
setError(null);
74-
updateCommandHistory(message);
7571
} else if (message.type === "tools") {
7672
setTools(message.data.tools);
7773
setError(null);
78-
updateCommandHistory(message);
7974
} else if (message.type === "toolResult") {
8075
setToolResult(JSON.stringify(message.data, null, 2));
8176
setError(null);
82-
updateCommandHistory(message);
8377
} else if (message.type === "error") {
8478
setError(message.message);
85-
updateCommandHistory(message);
8679
} else if (message.type === "connected") {
8780
setMcpConnected(true);
88-
updateCommandHistory(message);
8981
}
82+
83+
updateRequestHistory(message);
9084
};
9185

9286
ws.onerror = () => {
@@ -101,13 +95,13 @@ const App = () => {
10195
return () => ws.close();
10296
}, []);
10397

104-
const updateCommandHistory = (response: unknown) => {
105-
setCommandHistory((prev) => {
106-
const lastCommand = prev[prev.length - 1];
107-
if (lastCommand && lastCommand.response === null) {
98+
const updateRequestHistory = (response: unknown) => {
99+
setRequestHistory((prev) => {
100+
const lastRequest = prev[prev.length - 1];
101+
if (lastRequest && lastRequest.response === null) {
108102
const updatedHistory = [...prev];
109103
updatedHistory[updatedHistory.length - 1] = {
110-
...lastCommand,
104+
...lastRequest,
111105
response: JSON.stringify(response),
112106
};
113107
return updatedHistory;
@@ -120,9 +114,9 @@ const App = () => {
120114
if (socket) {
121115
console.log("Sending WebSocket message:", message);
122116
socket.send(JSON.stringify(message));
123-
setCommandHistory((prev) => [
117+
setRequestHistory((prev) => [
124118
...prev,
125-
{ command: JSON.stringify(message), response: null },
119+
{ request: JSON.stringify(message), response: null },
126120
]);
127121
}
128122
};
@@ -260,7 +254,7 @@ const App = () => {
260254
</div>
261255
</div>
262256
</div>
263-
<CommandHistory commandHistory={commandHistory} />
257+
<History requestHistory={requestHistory} />
264258
</div>
265259
);
266260
};
Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
import { useState } from "react";
22
import { Copy } from "lucide-react";
33

4-
const CommandHistory = ({
5-
commandHistory,
4+
const History = ({
5+
requestHistory,
66
}: {
7-
commandHistory: Array<{ command: string; response: string | null }>;
7+
requestHistory: Array<{ request: string; response: string | null }>;
88
}) => {
9-
const [expandedCommands, setExpandedCommands] = useState<{
9+
const [expandedRequests, setExpandedRequests] = useState<{
1010
[key: number]: boolean;
1111
}>({});
1212

13-
const toggleCommandExpansion = (index: number) => {
14-
setExpandedCommands((prev) => ({ ...prev, [index]: !prev[index] }));
13+
const toggleRequestExpansion = (index: number) => {
14+
setExpandedRequests((prev) => ({ ...prev, [index]: !prev[index] }));
1515
};
1616

1717
const copyToClipboard = (text: string) => {
@@ -20,65 +20,65 @@ const CommandHistory = ({
2020

2121
return (
2222
<div className="w-64 bg-white shadow-md p-4 overflow-y-auto">
23-
<h2 className="text-lg font-semibold mb-4">Command History</h2>
23+
<h2 className="text-lg font-semibold mb-4">History</h2>
2424
<ul className="space-y-3">
25-
{commandHistory
25+
{requestHistory
2626
.slice()
2727
.reverse()
28-
.map((cmd, index) => (
28+
.map((request, index) => (
2929
<li
3030
key={index}
3131
className="text-sm text-gray-600 bg-gray-100 p-2 rounded"
3232
>
3333
<div
3434
className="flex justify-between items-center cursor-pointer"
3535
onClick={() =>
36-
toggleCommandExpansion(commandHistory.length - 1 - index)
36+
toggleRequestExpansion(requestHistory.length - 1 - index)
3737
}
3838
>
3939
<span className="font-mono">
40-
{commandHistory.length - index}.{" "}
41-
{JSON.parse(cmd.command).type}
40+
{requestHistory.length - index}.{" "}
41+
{JSON.parse(request.request).type}
4242
</span>
4343
<span>
44-
{expandedCommands[commandHistory.length - 1 - index]
44+
{expandedRequests[requestHistory.length - 1 - index]
4545
? "▼"
4646
: "▶"}
4747
</span>
4848
</div>
49-
{expandedCommands[commandHistory.length - 1 - index] && (
49+
{expandedRequests[requestHistory.length - 1 - index] && (
5050
<>
5151
<div className="mt-2">
5252
<div className="flex justify-between items-center mb-1">
5353
<span className="font-semibold text-blue-600">
54-
Command:
54+
Request:
5555
</span>
5656
<button
57-
onClick={() => copyToClipboard(cmd.command)}
57+
onClick={() => copyToClipboard(request.request)}
5858
className="text-blue-500 hover:text-blue-700"
5959
>
6060
<Copy size={16} />
6161
</button>
6262
</div>
6363
<pre className="whitespace-pre-wrap break-words bg-blue-50 p-2 rounded">
64-
{JSON.stringify(JSON.parse(cmd.command), null, 2)}
64+
{JSON.stringify(JSON.parse(request.request), null, 2)}
6565
</pre>
6666
</div>
67-
{cmd.response && (
67+
{request.response && (
6868
<div className="mt-2">
6969
<div className="flex justify-between items-center mb-1">
7070
<span className="font-semibold text-green-600">
7171
Response:
7272
</span>
7373
<button
74-
onClick={() => copyToClipboard(cmd.response!)}
74+
onClick={() => copyToClipboard(request.response!)}
7575
className="text-blue-500 hover:text-blue-700"
7676
>
7777
<Copy size={16} />
7878
</button>
7979
</div>
8080
<pre className="whitespace-pre-wrap break-words bg-green-50 p-2 rounded">
81-
{JSON.stringify(JSON.parse(cmd.response), null, 2)}
81+
{JSON.stringify(JSON.parse(request.response), null, 2)}
8282
</pre>
8383
</div>
8484
)}
@@ -91,4 +91,4 @@ const CommandHistory = ({
9191
);
9292
};
9393

94-
export default CommandHistory;
94+
export default History;

0 commit comments

Comments
 (0)