1- import { useState } from 'react' ;
21import { Button } from 'antd' ;
32import { staticModal } from '@chat2db/ui' ;
43import i18n from '@/i18n' ;
@@ -21,31 +20,24 @@ interface EditorCloseDialogFooterProps {
2120const footerButtonStyle = { marginInlineStart : 0 } ;
2221
2322function EditorCloseDialogFooter ( { editor, onDecision } : EditorCloseDialogFooterProps ) {
24- const [ saving , setSaving ] = useState ( false ) ;
25-
26- const handleSave = async ( ) => {
27- if ( ! editor . saveBeforeClose || saving ) {
23+ const handleSave = ( ) => {
24+ if ( ! editor . saveBeforeClose ) {
2825 return ;
2926 }
30- setSaving ( true ) ;
31- try {
32- if ( await editor . saveBeforeClose ( ) ) {
33- onDecision ( 'saved' ) ;
34- }
35- } finally {
36- setSaving ( false ) ;
37- }
27+ // Resolve the dialog before starting the save. An unnamed draft opens a
28+ // second modal to collect its name, which must be the only active layer.
29+ onDecision ( 'save' ) ;
3830 } ;
3931
4032 return (
4133 < div style = { { display : 'grid' , gap : 8 , width : '100%' } } >
42- < Button block type = "primary" loading = { saving } style = { footerButtonStyle } onClick = { handleSave } >
34+ < Button block type = "primary" style = { footerButtonStyle } onClick = { handleSave } >
4335 { i18n ( 'common.button.save' ) }
4436 </ Button >
45- < Button block disabled = { saving } style = { footerButtonStyle } onClick = { ( ) => onDecision ( 'discard' ) } >
37+ < Button block style = { footerButtonStyle } onClick = { ( ) => onDecision ( 'discard' ) } >
4638 { i18n ( 'workspace.editorClose.dontSave' ) }
4739 </ Button >
48- < Button block disabled = { saving } style = { footerButtonStyle } onClick = { ( ) => onDecision ( 'cancel' ) } >
40+ < Button block style = { footerButtonStyle } onClick = { ( ) => onDecision ( 'cancel' ) } >
4941 { i18n ( 'common.button.cancel' ) }
5042 </ Button >
5143 </ div >
@@ -54,14 +46,13 @@ function EditorCloseDialogFooter({ editor, onDecision }: EditorCloseDialogFooter
5446
5547function requestEditorCloseDecision ( tab : IWorkspaceTab , editor : EditorCloseGuardRef ) {
5648 return new Promise < EditorCloseDecision > ( ( resolve ) => {
57- let settled = false ;
58- const finish = ( decision : EditorCloseDecision ) => {
59- if ( settled ) {
49+ let selectedDecision : EditorCloseDecision | undefined ;
50+ const finish = ( nextDecision : EditorCloseDecision ) => {
51+ if ( selectedDecision !== undefined ) {
6052 return ;
6153 }
62- settled = true ;
54+ selectedDecision = nextDecision ;
6355 modal . destroy ( ) ;
64- resolve ( decision ) ;
6556 } ;
6657 const modal = staticModal . confirm ( {
6758 icon : null ,
@@ -75,10 +66,7 @@ function requestEditorCloseDecision(tab: IWorkspaceTab, editor: EditorCloseGuard
7566 footer : ( ) => < EditorCloseDialogFooter editor = { editor } onDecision = { finish } /> ,
7667 onCancel : ( ) => finish ( 'cancel' ) ,
7768 afterClose : ( ) => {
78- if ( ! settled ) {
79- settled = true ;
80- resolve ( 'cancel' ) ;
81- }
69+ resolve ( selectedDecision ?? 'cancel' ) ;
8270 } ,
8371 } ) ;
8472 } ) ;
0 commit comments