diff --git a/web/app/components/app/create-app-dialog/index.tsx b/web/app/components/app/create-app-dialog/index.tsx index acc3650211..794bbbf9e8 100644 --- a/web/app/components/app/create-app-dialog/index.tsx +++ b/web/app/components/app/create-app-dialog/index.tsx @@ -1,4 +1,6 @@ 'use client' +import { useCallback } from 'react' +import { useKeyPress } from 'ahooks' import AppList from './app-list' import FullScreenModal from '@/app/components/base/fullscreen-modal' @@ -10,6 +12,13 @@ type CreateAppDialogProps = { } const CreateAppTemplateDialog = ({ show, onSuccess, onClose, onCreateFromBlank }: CreateAppDialogProps) => { + const handleEscKeyPress = useCallback(() => { + if (show) + onClose() + }, [show, onClose]) + + useKeyPress('esc', handleEscKeyPress) + return ( { + if (show && !isAppsFull && ((currentTab === CreateFromDSLModalTab.FROM_FILE && currentFile) || (currentTab === CreateFromDSLModalTab.FROM_URL && dslUrlValue))) + handleCreateApp() + }) + + useKeyPress('esc', () => { + if (show && !showErrorModal) + onClose() + }) + const onDSLConfirm: MouseEventHandler = async () => { try { if (!importId) @@ -266,7 +279,18 @@ const CreateFromDSLModal = ({ show, onSuccess, onClose, activeTab = CreateFromDS )}
- +
= plan.total.buildApps) - const submit = () => { + const submit = useCallback(() => { if (!name.trim()) { Toast.notify({ type: 'error', message: t('explore.appCustomize.nameRequired') }) return @@ -80,7 +81,19 @@ const CreateAppModal = ({ use_icon_as_answer_icon: useIconAsAnswerIcon, }) onHide() - } + }, [name, appIcon, description, useIconAsAnswerIcon, onConfirm, onHide, t]) + + const { run: handleSubmit } = useDebounceFn(submit, { wait: 300 }) + + useKeyPress(['meta.enter', 'ctrl.enter'], () => { + if (show && !(!isEditModal && isAppsFull) && name.trim()) + handleSubmit() + }) + + useKeyPress('esc', () => { + if (show) + onHide() + }) return ( <> @@ -146,7 +159,18 @@ const CreateAppModal = ({ {!isEditModal && isAppsFull && }
- +