Fix Post button always being disabled when require attachment descriptions is enabled

Also fix post button state not updating when description edited

Closes #371
This commit is contained in:
Shadowfacts 2023-04-21 18:02:30 -04:00
parent 06855420da
commit 074a296a68
2 changed files with 16 additions and 4 deletions

View File

@ -20,15 +20,17 @@ class AttachmentsListController: ViewController {
private var requiresAttachmentDescriptions: Bool {
if parent.config.requireAttachmentDescriptions {
return draft.attachments.allSatisfy {
!$0.attachmentDescription.isEmpty
if draft.attachments.isEmpty {
return false
} else {
return !parent.attachmentsMissingDescriptions.isEmpty
}
} else {
return false
}
}
private var validAttachmentCombination: Bool {
var validAttachmentCombination: Bool {
if !parent.mastodonController.instanceFeatures.mastodonAttachmentRestrictions {
return true
} else if draft.attachments.contains(where: { $0.data.type == .video }) &&
@ -139,6 +141,13 @@ class AttachmentsListController: ViewController {
.onDrag {
NSItemProvider(object: attachment)
}
.onReceive(attachment.$attachmentDescription.map(\.isEmpty).removeDuplicates()) { isEmpty in
if isEmpty {
controller.parent.attachmentsMissingDescriptions.insert(attachment.id)
} else {
controller.parent.attachmentsMissingDescriptions.remove(attachment.id)
}
}
}
.onMove(perform: controller.moveAttachments)
.onDelete(perform: controller.deleteAttachments)

View File

@ -32,6 +32,9 @@ public final class ComposeController: ViewController {
@Published var toolbarController: ToolbarController!
@Published var attachmentsListController: AttachmentsListController!
// this property is here rather than on the AttachmentsListController so that the ComposeView
// updates when it changes, because changes to it may alter postButtonEnabled
@Published var attachmentsMissingDescriptions = Set<UUID>()
@Published var contentWarningBecomeFirstResponder = false
@Published var mainComposeTextViewBecomeFirstResponder = false
@Published var currentInput: (any ComposeInput)? = nil