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:
parent
06855420da
commit
074a296a68
|
@ -17,18 +17,20 @@ class AttachmentsListController: ViewController {
|
|||
var isValid: Bool {
|
||||
!requiresAttachmentDescriptions && validAttachmentCombination
|
||||
}
|
||||
|
||||
|
||||
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)
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue