field_ios

In-the-field app for Radroots on iOS
git clone https://radroots.dev/git/field_ios.git
Log | Files | Refs | README | LICENSE

TeraAddAffordances.swift (1648B)


      1 import Foundation
      2 
      3 extension TeraAddStore {
      4   var canCreateNewComposer: Bool {
      5     !isWorking && submissions.canReplaceEditing && !protection.isWorking && !protection.failed
      6   }
      7 
      8   func selectType(_ type: TeraAddCommandType) {
      9     guard canCreateNewComposer, isFormEditable, form.commandType != type else { return }
     10     newDraft(type: type)
     11   }
     12 
     13   var selectedSchema: TeraAddSchema? {
     14     schemas.first(where: { $0.commandType == form.commandType })
     15   }
     16 
     17   var isFormEditable: Bool {
     18     guard !revisionPreparation.isCaptured, activeDraft?.isRevision != true, activeDraft?.kind != .retraction else { return false }
     19     return activeDraft?.isEditable ?? true
     20   }
     21 
     22   var isProductReady: Bool {
     23     state == .ready && selectedSchema != nil
     24   }
     25 
     26   var canSave: Bool {
     27     isProductReady && (isFormEditable || revisionPreparation.isCaptured) && !isWorking
     28   }
     29 
     30   var canSubmit: Bool {
     31     if activeDraft == nil, submissions.usesCurrentAction {
     32       return isProductReady && !isWorking && submissions.canContinue
     33     }
     34     return isProductReady && !isWorking && !submissions.isWorking
     35       && activeDraft?.coordinateWritable != false
     36       && (activeDraft?.isRevision == true || activeDraft?.canAdvance == true
     37         || activeDraft?.canQueue == true
     38         || isFormEditable || revisionPreparation.isCaptured)
     39   }
     40 
     41   var acceptsMedia: Bool {
     42     mediaLimit > 0
     43   }
     44 
     45   var canAddMedia: Bool {
     46     isFormEditable && acceptsMedia && form.media.count < mediaLimit
     47   }
     48 
     49   var mediaLimit: Int {
     50     guard
     51       let maximum = selectedSchema?.fields
     52         .first(where: { $0.kind == .media })?.maxItems
     53     else { return 0 }
     54     return Int(maximum)
     55   }
     56 }