Skip to content

Commit 74baea2

Browse files
authored
Merge pull request #2270 from citizenos/#2260
add save draft on close
2 parents 193e000 + eeb1167 commit 74baea2

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

src/app/ideation/components/add-idea/add-idea.component.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,8 @@ export class AddIdeaComponent {
229229

230230
if (this.app.addIdea.value || this.app.editIdea.value) {
231231
const isValueChanged = text && prevValue && text !== prevValue;
232-
const isNotSubscribed = !this.autosaveSubscription || this.autosaveSubscription.closed
232+
const isNotSubscribed =
233+
!this.autosaveSubscription || this.autosaveSubscription.closed;
233234

234235
if (isValueChanged && isNotSubscribed && !this.isPublished) {
235236
this.startAutosave();
@@ -241,7 +242,8 @@ export class AddIdeaComponent {
241242
if (this.app.addIdea.value || this.app.editIdea.value) {
242243
this.ideaForm.controls[key].markAsUntouched();
243244

244-
const isNotSubscribed = !this.autosaveSubscription || this.autosaveSubscription.closed
245+
const isNotSubscribed =
246+
!this.autosaveSubscription || this.autosaveSubscription.closed;
245247

246248
if (
247249
key === 'statement' &&
@@ -287,15 +289,14 @@ export class AddIdeaComponent {
287289
}
288290

289291
close() {
290-
if (
291-
this.ideaForm.controls['statement'].value ||
292-
this.ideaForm.controls['description'].value
293-
) {
292+
const isSubscribed = this.autosaveSubscription?.closed === false;
293+
if (isSubscribed) {
294294
const dialog = this.dialog.open(CloseWithoutSavingDialogComponent);
295295

296296
dialog.afterClosed().subscribe({
297297
next: (res) => {
298298
if (!res) {
299+
this, this.saveIdea(IdeaStatus.draft);
299300
this.app.addIdea.next(false);
300301
this.clear();
301302
}

src/app/ideation/components/edit-idea/edit-idea.component.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,9 @@ export class EditIdeaComponent extends AddIdeaComponent {
182182
}
183183

184184
ideaEditMode() {
185+
if (this.idea.status === IdeaStatus.draft) {
186+
this.saveIdea(IdeaStatus.draft);
187+
}
185188
this.ideaForm.patchValue({ statement: this.idea.statement });
186189
this.ideaForm.patchValue({ description: this.idea.description });
187190
this.showEdit.emit(false);

0 commit comments

Comments
 (0)