Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion packages/react/src/hooks/useShowCommands.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ const useShowCommands = (commands, setFilteredCommands, setShowCommandList) =>
const cursor = e.target.selectionStart;
const tokens = e.target.value.slice(0, cursor).split(/\s+/);

if (tokens.length === 1 && tokens[0].startsWith('/')) {
if (
tokens.length === 1 &&
tokens[0].startsWith('/') &&
getFilteredCommands(tokens[0]).length > 0
) {
setFilteredCommands(getFilteredCommands(tokens[0]));
setShowCommandList(true);
} else {
Expand Down
30 changes: 27 additions & 3 deletions packages/react/src/views/ChatInput/ChatInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -354,8 +354,25 @@ const ChatInput = ({ scrollToBottom, clearUnreadDividerRef }) => {

const handleCommandExecution = async (message) => {
const execCommand = async (command, params) => {
await RCInstance.execCommand({ command, params, tmid: threadId });
setFilteredCommands([]);
try {
const result = await RCInstance.execCommand({
command,
params,
tmid: threadId,
});
if (!result.success) {
dispatchToastMessage({
type: 'error',
message: result.error || 'No such command',
});
}
setFilteredCommands([]);
} catch (e) {
dispatchToastMessage({
type: 'error',
message: 'No such command',
});
}
};

const [command, ...paramsArray] = message.split(' ');
Expand All @@ -366,7 +383,14 @@ const ChatInput = ({ scrollToBottom, clearUnreadDividerRef }) => {
setDisableButton(true);
setEditMessage({});
await execCommand(command.replace('/', ''), params);
return true;
}

messageRef.current.value = '';
setDisableButton(true);
setEditMessage({});
await execCommand(command.replace('/', ''), params);
return true;
};

const sendMessage = async () => {
Expand All @@ -392,7 +416,7 @@ const ChatInput = ({ scrollToBottom, clearUnreadDividerRef }) => {
return;
}
if (message.startsWith('/')) {
handleCommandExecution(message);
await handleCommandExecution(message);
return;
}

Expand Down
4 changes: 3 additions & 1 deletion packages/react/src/views/CommandList/CommandsList.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ function CommandsList({
switch (event.key) {
case 'Enter': {
const selectedItem = filteredCommands[commandIndex];
handleCommandClick(selectedItem);
if (selectedItem) {
handleCommandClick(selectedItem);
}
break;
}
case 'ArrowDown':
Expand Down