From db11a75107aacf4ba7a1d5321560db69bf2624d5 Mon Sep 17 00:00:00 2001 From: Satindar Dhillon Date: Thu, 31 Mar 2022 22:53:03 -0700 Subject: [PATCH] stub in labels view --- .../App/Views/Profile/LabelsView.swift | 93 +++++++++++++++++++ .../App/Views/Profile/ProfileView.swift | 4 + 2 files changed, 97 insertions(+) create mode 100644 apple/OmnivoreKit/Sources/App/Views/Profile/LabelsView.swift diff --git a/apple/OmnivoreKit/Sources/App/Views/Profile/LabelsView.swift b/apple/OmnivoreKit/Sources/App/Views/Profile/LabelsView.swift new file mode 100644 index 000000000..830389bb3 --- /dev/null +++ b/apple/OmnivoreKit/Sources/App/Views/Profile/LabelsView.swift @@ -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() + + 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") + } +} diff --git a/apple/OmnivoreKit/Sources/App/Views/Profile/ProfileView.swift b/apple/OmnivoreKit/Sources/App/Views/Profile/ProfileView.swift index ca2443130..7cf3001e7 100644 --- a/apple/OmnivoreKit/Sources/App/Views/Profile/ProfileView.swift +++ b/apple/OmnivoreKit/Sources/App/Views/Profile/ProfileView.swift @@ -63,6 +63,10 @@ struct ProfileView: View { } Section { + NavigationLink(destination: LabelsView()) { + Text("Labels") + } + NavigationLink(destination: NewsletterEmailsView()) { Text("Emails") }