diff --git a/apple/OmnivoreKit/Sources/App/Views/Labels/ApplyLabelsView.swift b/apple/OmnivoreKit/Sources/App/Views/Labels/ApplyLabelsView.swift index 0280b6a2f..c9bc20261 100644 --- a/apple/OmnivoreKit/Sources/App/Views/Labels/ApplyLabelsView.swift +++ b/apple/OmnivoreKit/Sources/App/Views/Labels/ApplyLabelsView.swift @@ -34,43 +34,12 @@ struct ApplyLabelsView: View { @Environment(\.presentationMode) private var presentationMode @StateObject var viewModel = LabelsViewModel() + func isSelected(_ label: LinkedItemLabel) -> Bool { + viewModel.selectedLabels.contains(where: { $0.id == label.id }) + } + var innerBody: some View { List { - Section(header: Text("Assigned Labels")) { - if viewModel.selectedLabels.isEmpty { - Text("No labels are currently assigned.") - } - ForEach(viewModel.selectedLabels.applySearchFilter(viewModel.labelSearchFilter), id: \.self) { label in - HStack { - TextChip(feedItemLabel: label) - Spacer() - Button( - action: { - withAnimation { - viewModel.removeLabelFromItem(label) - } - }, - label: { Image(systemName: "xmark.circle").foregroundColor(.appGrayTextContrast) } - ) - } - } - } - Section(header: Text("Available Labels")) { - ForEach(viewModel.unselectedLabels.applySearchFilter(viewModel.labelSearchFilter), id: \.self) { label in - HStack { - TextChip(feedItemLabel: label) - Spacer() - Button( - action: { - withAnimation { - viewModel.addLabelToItem(label) - } - }, - label: { Image(systemName: "plus").foregroundColor(.appGrayTextContrast) } - ) - } - } - } Section { Button( action: { viewModel.showCreateEmailModal = true }, @@ -84,6 +53,28 @@ struct ApplyLabelsView: View { ) .disabled(viewModel.isLoading) } + Section { + ForEach(viewModel.labels.applySearchFilter(viewModel.labelSearchFilter), id: \.self) { label in + Button( + action: { + if isSelected(label) { + viewModel.selectedLabels.removeAll(where: { $0.id == label.id }) + } else { + viewModel.selectedLabels.append(label) + } + }, + label: { + HStack { + TextChip(feedItemLabel: label) + Spacer() + if isSelected(label) { + Image(systemName: "checkmark") + } + } + } + ) + } + } } .navigationTitle(mode.navTitle) #if os(iOS) diff --git a/apple/OmnivoreKit/Sources/App/Views/Labels/FilterByLabelsView.swift b/apple/OmnivoreKit/Sources/App/Views/Labels/FilterByLabelsView.swift index 023765f90..3d2311041 100644 --- a/apple/OmnivoreKit/Sources/App/Views/Labels/FilterByLabelsView.swift +++ b/apple/OmnivoreKit/Sources/App/Views/Labels/FilterByLabelsView.swift @@ -12,10 +12,6 @@ struct FilterByLabelsView: View { @EnvironmentObject var dataService: DataService @Environment(\.presentationMode) private var presentationMode -// init(initiallySelected: [LinkedItemLabel], initiallyNegated: [LinkedItemLabel], onSave:) { -// -// } - func isNegated(_ label: LinkedItemLabel) -> Bool { viewModel.negatedLabels.contains(where: { $0.id == label.id }) }