disabling enter keyboard when approve/reject pending (#1776)
<!-- This is an auto-generated description by cubic. --> ## Summary by cubic Disable Enter-to-send when approve/reject is pending to prevent accidental message submission. Enter now respects the disableSendButton state; Shift+Enter still adds a newline. - **Bug Fixes** - Pass disableSendButton from ChatInput to LexicalChatInput. - Update EnterKeyPlugin to ignore Enter when disableSendButton is true, while keeping Shift+Enter for newline. <sup>Written for commit 7b13908826e25ebf0f2699137c648e20de520f61. Summary will update automatically on new commits.</sup> <!-- End of auto-generated description by cubic. -->
This commit is contained in:
committed by
GitHub
parent
ed2bf680ba
commit
39876f114a
@@ -325,6 +325,7 @@ export function ChatInput({ chatId }: { chatId?: number }) {
|
|||||||
onPaste={handlePaste}
|
onPaste={handlePaste}
|
||||||
placeholder="Ask Dyad to build..."
|
placeholder="Ask Dyad to build..."
|
||||||
excludeCurrentApp={true}
|
excludeCurrentApp={true}
|
||||||
|
disableSendButton={disableSendButton}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
{isStreaming ? (
|
{isStreaming ? (
|
||||||
|
|||||||
@@ -86,6 +86,7 @@ export function HomeChatInput({
|
|||||||
placeholder="Ask Dyad to build..."
|
placeholder="Ask Dyad to build..."
|
||||||
disabled={isStreaming}
|
disabled={isStreaming}
|
||||||
excludeCurrentApp={false}
|
excludeCurrentApp={false}
|
||||||
|
disableSendButton={false}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
{/* File attachment dropdown */}
|
{/* File attachment dropdown */}
|
||||||
|
|||||||
@@ -90,7 +90,13 @@ function CustomMenu({ loading: _loading, ...props }: any) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Plugin to handle Enter key
|
// Plugin to handle Enter key
|
||||||
function EnterKeyPlugin({ onSubmit }: { onSubmit: () => void }) {
|
function EnterKeyPlugin({
|
||||||
|
onSubmit,
|
||||||
|
disableSendButton,
|
||||||
|
}: {
|
||||||
|
onSubmit: () => void;
|
||||||
|
disableSendButton: boolean;
|
||||||
|
}) {
|
||||||
const [editor] = useLexicalComposerContext();
|
const [editor] = useLexicalComposerContext();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -109,7 +115,7 @@ function EnterKeyPlugin({ onSubmit }: { onSubmit: () => void }) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!event.shiftKey) {
|
if (!event.shiftKey && !disableSendButton) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
onSubmit();
|
onSubmit();
|
||||||
return true;
|
return true;
|
||||||
@@ -118,7 +124,7 @@ function EnterKeyPlugin({ onSubmit }: { onSubmit: () => void }) {
|
|||||||
},
|
},
|
||||||
COMMAND_PRIORITY_HIGH, // Use higher priority to catch before mentions plugin
|
COMMAND_PRIORITY_HIGH, // Use higher priority to catch before mentions plugin
|
||||||
);
|
);
|
||||||
}, [editor, onSubmit]);
|
}, [editor, onSubmit, disableSendButton]);
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -231,6 +237,7 @@ interface LexicalChatInputProps {
|
|||||||
placeholder?: string;
|
placeholder?: string;
|
||||||
disabled?: boolean;
|
disabled?: boolean;
|
||||||
excludeCurrentApp: boolean;
|
excludeCurrentApp: boolean;
|
||||||
|
disableSendButton: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
function onError(error: Error) {
|
function onError(error: Error) {
|
||||||
@@ -245,6 +252,7 @@ export function LexicalChatInput({
|
|||||||
excludeCurrentApp,
|
excludeCurrentApp,
|
||||||
placeholder = "Ask Dyad to build...",
|
placeholder = "Ask Dyad to build...",
|
||||||
disabled = false,
|
disabled = false,
|
||||||
|
disableSendButton,
|
||||||
}: LexicalChatInputProps) {
|
}: LexicalChatInputProps) {
|
||||||
const { apps } = useLoadApps();
|
const { apps } = useLoadApps();
|
||||||
const { prompts } = usePrompts();
|
const { prompts } = usePrompts();
|
||||||
@@ -402,7 +410,10 @@ export function LexicalChatInput({
|
|||||||
/>
|
/>
|
||||||
<OnChangePlugin onChange={handleEditorChange} />
|
<OnChangePlugin onChange={handleEditorChange} />
|
||||||
<HistoryPlugin />
|
<HistoryPlugin />
|
||||||
<EnterKeyPlugin onSubmit={handleSubmit} />
|
<EnterKeyPlugin
|
||||||
|
onSubmit={handleSubmit}
|
||||||
|
disableSendButton={disableSendButton}
|
||||||
|
/>
|
||||||
<ExternalValueSyncPlugin
|
<ExternalValueSyncPlugin
|
||||||
value={value}
|
value={value}
|
||||||
promptsById={Object.fromEntries(
|
promptsById={Object.fromEntries(
|
||||||
|
|||||||
Reference in New Issue
Block a user