Fix not being able to close draft when automatic save preference is off

This commit is contained in:
Shadowfacts 2023-04-18 15:17:33 -04:00
parent cfc69627e5
commit 0d7cc69947
1 changed files with 18 additions and 0 deletions

View File

@ -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() { func postStatus() {
guard !isPosting, guard !isPosting,
draft.hasContent else { draft.hasContent else {
@ -329,6 +339,14 @@ public final class ComposeController: ViewController {
// otherwise all Buttons in the nav bar are made semibold // otherwise all Buttons in the nav bar are made semibold
.font(.system(size: 17, weight: .regular)) .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 @ViewBuilder