stub in labels view

This commit is contained in:
Satindar Dhillon 2022-03-31 22:53:03 -07:00
parent 9519be128c
commit db11a75107
2 changed files with 97 additions and 0 deletions

View file

@ -0,0 +1,93 @@
import Combine
import Models
import Services
import SwiftUI
import Views
final class LabelsViewModel: ObservableObject {
private var hasLoadedInitialLabels = false
@Published var isLoading = false
@Published var labels = [FeedItemLabel]()
var subscriptions = Set<AnyCancellable>()
func loadLabels(dataService _: DataService) {
isLoading = true
// dataService.newsletterEmailsPublisher().sink(
// receiveCompletion: { _ in },
// receiveValue: { [weak self] result in
// self?.isLoading = false
// self?.emails = result
// self?.hasLoadedInitialLabels = true
// }
// )
// .store(in: &subscriptions)
}
func createLabel(dataService _: DataService) {
isLoading = true
// dataService.createNewsletterEmailPublisher().sink(
// receiveCompletion: { [weak self] _ in
// self?.isLoading = false
// },
// receiveValue: { [weak self] result in
// self?.isLoading = false
// self?.emails.insert(result, at: 0)
// }
// )
// .store(in: &subscriptions)
}
}
struct LabelsView: View {
@EnvironmentObject var dataService: DataService
@StateObject var viewModel = LabelsViewModel()
let footerText = "Use labels to create curated collections of links."
var body: some View {
Group {
#if os(iOS)
Form {
innerBody
}
#elseif os(macOS)
List {
innerBody
}
.listStyle(InsetListStyle())
#endif
}
.onAppear { viewModel.loadLabels(dataService: dataService) }
}
private var innerBody: some View {
Group {
Section(footer: Text(footerText)) {
Button(
action: {
viewModel.createLabel(dataService: dataService)
},
label: {
HStack {
Image(systemName: "plus.circle.fill").foregroundColor(.green)
Text("Create a new label")
Spacer()
}
}
)
.disabled(viewModel.isLoading)
}
if !viewModel.labels.isEmpty {
Section(header: Text("Labels")) {
ForEach(viewModel.labels, id: \.id) { label in
Text(label.name)
}
}
}
}
.navigationTitle("Labels")
}
}

View file

@ -63,6 +63,10 @@ struct ProfileView: View {
}
Section {
NavigationLink(destination: LabelsView()) {
Text("Labels")
}
NavigationLink(destination: NewsletterEmailsView()) {
Text("Emails")
}