From 0d7cc699479a825947104f2b5e2e65bce5cd2a42 Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Tue, 18 Apr 2023 15:17:33 -0400 Subject: [PATCH] Fix not being able to close draft when automatic save preference is off --- .../Controllers/ComposeController.swift | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/Packages/ComposeUI/Sources/ComposeUI/Controllers/ComposeController.swift b/Packages/ComposeUI/Sources/ComposeUI/Controllers/ComposeController.swift index ceb8a227..df2db563 100644 --- a/Packages/ComposeUI/Sources/ComposeUI/Controllers/ComposeController.swift +++ b/Packages/ComposeUI/Sources/ComposeUI/Controllers/ComposeController.swift @@ -135,6 +135,16 @@ public final class ComposeController: ViewController { } } + @MainActor + func cancel(deleteDraft: Bool) { + if deleteDraft { + DraftsManager.shared.remove(draft) + } else { + DraftsManager.save() + } + config.dismiss(.cancel) + } + func postStatus() { guard !isPosting, draft.hasContent else { @@ -329,6 +339,14 @@ public final class ComposeController: ViewController { // otherwise all Buttons in the nav bar are made semibold .font(.system(size: 17, weight: .regular)) } + .confirmationDialog("Are you sure?", isPresented: $controller.isShowingSaveDraftSheet) { + Button(action: { controller.cancel(deleteDraft: false) }) { + Text("Save Draft") + } + Button(role: .destructive, action: { controller.cancel(deleteDraft: true) }) { + Text("Delete Draft") + } + } } @ViewBuilder