mirror of
https://github.com/omnivore-app/omnivore.git
synced 2026-03-11 08:54:26 +00:00
stub in labels view
This commit is contained in:
parent
9519be128c
commit
db11a75107
2 changed files with 97 additions and 0 deletions
93
apple/OmnivoreKit/Sources/App/Views/Profile/LabelsView.swift
Normal file
93
apple/OmnivoreKit/Sources/App/Views/Profile/LabelsView.swift
Normal 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")
|
||||
}
|
||||
}
|
||||
|
|
@ -63,6 +63,10 @@ struct ProfileView: View {
|
|||
}
|
||||
|
||||
Section {
|
||||
NavigationLink(destination: LabelsView()) {
|
||||
Text("Labels")
|
||||
}
|
||||
|
||||
NavigationLink(destination: NewsletterEmailsView()) {
|
||||
Text("Emails")
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue