Skip to content
This repository was archived by the owner on Apr 18, 2024. It is now read-only.

Commit 7b0790d

Browse files
committed
improve draft needs save logic
1 parent 2e35577 commit 7b0790d

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

src/sdk/lsf-sdk.js

+10-9
Original file line numberDiff line numberDiff line change
@@ -681,21 +681,21 @@ export class LSFWrapper {
681681
else if (status !== undefined) this.datamanager.invoke("toast", { message: "There was an error saving your draft", type: "error" });
682682
}
683683

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+
}
687689

688690
saveDraft = async (target = null) => {
689691
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);
693693

694-
if (selected?.isDraftSaving || draftIsFresh) {
694+
if (selected?.isDraftSaving) {
695695
await when(() => !selected.isDraftSaving);
696696
this.draftToast(200);
697697
}
698-
else if (hasChanges && selected && !submissionInProgress) {
698+
else if (hasChanges && selected) {
699699
const res = await selected?.saveDraftImmediatelyWithResults();
700700
const status = res?.$meta?.status;
701701

@@ -708,9 +708,10 @@ export class LSFWrapper {
708708
const data = { body: this.prepareData(annotation, { draft: true }) }; // serializedAnnotation
709709
const hasChanges = this.needsDraftSave(annotation);
710710
const showToast = params?.useToast && hasChanges;
711+
// console.log('onSubmitDraft', params?.useToast, hasChanges);
711712

712713
if (params?.useToast) delete params.useToast;
713-
714+
714715
Object.assign(data.body, params);
715716

716717
await this.saveUserLabels();

0 commit comments

Comments
 (0)