@@ -12,6 +12,7 @@ const UNSAVED_SESSION = `<em>${UNSAVED_SESSION_NAME}</em>`;
1212const nodes = { } ;
1313let globalSelectedSpace ;
1414let bannerState ;
15+ let isSaving = false ;
1516
1617// METHODS FOR RENDERING SIDENAV (spaces list)
1718
@@ -312,37 +313,42 @@ function handleAutoUpdateRequest(spaces) {
312313}
313314
314315async function handleNameSave ( ) {
315- const newName = nodes . nameFormInput . value ;
316- const oldName = globalSelectedSpace . name ;
317- const { sessionId } = globalSelectedSpace ;
318- const { windowId } = globalSelectedSpace ;
316+ if ( isSaving ) return ;
317+ isSaving = true ;
318+
319+ try {
320+ const newName = nodes . nameFormInput . value ;
321+ const { name, sessionId, windowId } = globalSelectedSpace ;
319322
320- // if invalid name set then revert back to non-edit mode
321- if ( newName === oldName || newName . trim ( ) === '' ) {
322- updateNameForm ( globalSelectedSpace ) ;
323- toggleNameEditMode ( false ) ;
324- return ;
325- }
323+ // if invalid name set then revert back to non-edit mode
324+ if ( newName === name || newName . trim ( ) === '' ) {
325+ updateNameForm ( globalSelectedSpace ) ;
326+ toggleNameEditMode ( false ) ;
327+ return ;
328+ }
326329
327- const canOverwrite = await checkSessionOverwrite ( newName ) ;
328- if ( ! canOverwrite ) {
329- updateNameForm ( globalSelectedSpace ) ;
330- toggleNameEditMode ( false ) ;
331- return ;
332- }
330+ const canOverwrite = await checkSessionOverwrite ( newName ) ;
331+ if ( ! canOverwrite ) {
332+ updateNameForm ( globalSelectedSpace ) ;
333+ toggleNameEditMode ( false ) ;
334+ return ;
335+ }
333336
334- // otherwise call the save service
335- if ( sessionId ) {
336- const session = await performSessionUpdate ( newName , sessionId ) ;
337- if ( session ) reroute ( session . id , false , true ) ;
338- } else if ( windowId ) {
339- const session = await performNewSessionSave ( newName , windowId ) ;
340- if ( session ) reroute ( session . id , false , true ) ;
341- }
337+ // otherwise call the save service
338+ if ( sessionId ) {
339+ const session = await performSessionUpdate ( newName , sessionId ) ;
340+ if ( session ) reroute ( session . id , false , true ) ;
341+ } else if ( windowId ) {
342+ const session = await performNewSessionSave ( newName , windowId ) ;
343+ if ( session ) reroute ( session . id , false , true ) ;
344+ }
342345
343- // handle banner
344- if ( bannerState === 1 ) {
345- setBannerState ( 2 ) ;
346+ // handle banner
347+ if ( bannerState === 1 ) {
348+ setBannerState ( 2 ) ;
349+ }
350+ } finally {
351+ isSaving = false ;
346352 }
347353}
348354
0 commit comments