Use same UI for LabelsView as Apply Labels View

Mostly changes the create label button and list style.
This commit is contained in:
Jackson Harper
2023-01-25 22:41:26 +08:00
parent f36eb0ed32
commit 409ca5ce6d

View File

@ -11,17 +11,24 @@ struct LabelsView: View {
@State private var labelToRemove: LinkedItemLabel?
var body: some View {
Group {
#if os(iOS)
Form {
innerBody
List {
ForEach(viewModel.labels, id: \.id) { label in
HStack {
TextChip(feedItemLabel: label).allowsHitTesting(false)
Spacer()
Button(
action: {
labelToRemove = label
showDeleteConfirmation = true
},
label: { Image(systemName: "trash") }
)
}
#elseif os(macOS)
List {
innerBody
}
#endif
}
createLabelButton
}
.listStyle(PlainListStyle())
.navigationTitle(LocalText.labelsGeneric)
.alert("Are you sure you want to delete this label?", isPresented: $showDeleteConfirmation) {
Button("Delete Label", role: .destructive) {
if let label = labelToRemove {
@ -43,41 +50,26 @@ struct LabelsView: View {
.task { await viewModel.loadLabels(dataService: dataService, item: nil) }
}
private var innerBody: some View {
Group {
Section(footer: Text(LocalText.labelsPurposeDescription)) {
Button(
action: { viewModel.showCreateLabelModal = true },
label: {
HStack {
Image(systemName: "plus.circle.fill").foregroundColor(.green)
Text(LocalText.createLabelMessage).foregroundColor(.appGrayTextContrast)
Spacer()
}
}
)
.disabled(viewModel.isLoading)
}
if !viewModel.labels.isEmpty {
Section(header: Text(LocalText.labelsGeneric)) {
ForEach(viewModel.labels, id: \.id) { label in
HStack {
TextChip(feedItemLabel: label).allowsHitTesting(false)
Spacer()
Button(
action: {
labelToRemove = label
showDeleteConfirmation = true
},
label: { Image(systemName: "trash") }
)
}
}
var createLabelButton: some View {
Button(
action: { viewModel.showCreateLabelModal = true },
label: {
HStack {
Image(systemName: "tag").foregroundColor(.blue)
Text(
viewModel.labelSearchFilter.count > 0 ?
"Create: \"\(viewModel.labelSearchFilter)\" label" :
LocalText.createLabelMessage
).foregroundColor(.blue)
.font(Font.system(size: 14))
Spacer()
}
}
}
.navigationTitle(LocalText.labelsGeneric)
)
.buttonStyle(PlainButtonStyle())
.disabled(viewModel.isLoading)
.listRowSeparator(.hidden, edges: .bottom)
.padding(.vertical, 10)
}
}