@@ -681,21 +681,21 @@ export class LSFWrapper {
681
681
else if ( status !== undefined ) this . datamanager . invoke ( "toast" , { message : "There was an error saving your draft" , type : "error" } ) ;
682
682
}
683
683
684
- needsDraftSave = ( annotation ) =>
685
- annotation ?. history ?. hasChanges &&
686
- ( annotation . draftSaved ? new Date ( annotation . history . lastAdditionTime ) > new Date ( annotation . draftSaved ) : true ) ;
684
+ needsDraftSave = ( annotation ) => {
685
+ if ( annotation . history ?. hasChanges && ! annotation . draftSaved ) return true ;
686
+ if ( annotation . history ?. hasChanges && new Date ( annotation . history . lastAdditionTime ) > new Date ( annotation . draftSaved ) ) return true ;
687
+ return false ;
688
+ }
687
689
688
690
saveDraft = async ( target = null ) => {
689
691
const selected = target || this . lsf ?. annotationStore ?. selected ;
690
- const hasChanges = selected . history . hasChanges ;
691
- const submissionInProgress = selected ?. submissionStarted ;
692
- const draftIsFresh = new Date ( selected . draftSaved ) > new Date ( ) - selected . autosaveDelay ;
692
+ const hasChanges = this . needsDraftSave ( selected ) ;
693
693
694
- if ( selected ?. isDraftSaving || draftIsFresh ) {
694
+ if ( selected ?. isDraftSaving ) {
695
695
await when ( ( ) => ! selected . isDraftSaving ) ;
696
696
this . draftToast ( 200 ) ;
697
697
}
698
- else if ( hasChanges && selected && ! submissionInProgress ) {
698
+ else if ( hasChanges && selected ) {
699
699
const res = await selected ?. saveDraftImmediatelyWithResults ( ) ;
700
700
const status = res ?. $meta ?. status ;
701
701
@@ -708,9 +708,10 @@ export class LSFWrapper {
708
708
const data = { body : this . prepareData ( annotation , { draft : true } ) } ; // serializedAnnotation
709
709
const hasChanges = this . needsDraftSave ( annotation ) ;
710
710
const showToast = params ?. useToast && hasChanges ;
711
+ // console.log('onSubmitDraft', params?.useToast, hasChanges);
711
712
712
713
if ( params ?. useToast ) delete params . useToast ;
713
-
714
+
714
715
Object . assign ( data . body , params ) ;
715
716
716
717
await this . saveUserLabels ( ) ;
0 commit comments