Files
Pulse/Sources/PulseUI/Features/Console/List/ConsoleListGroupedSectionView.swift

42 lines
1.2 KiB
Swift
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// The MIT License (MIT)
//
// Copyright (c) 2020–2023 Alexander Grebenyuk (github.com/kean).
#if os(iOS) || os(macOS)
import CoreData
import Pulse
import Combine
import SwiftUI
@available(iOS 15.0, *)
struct ConsoleListGroupedSectionView: View {
let section: NSFetchedResultsSectionInfo
@ObservedObject var viewModel: ConsoleListViewModel
@EnvironmentObject private var environment: ConsoleEnvironment
var body: some View {
let objects = (section.objects as? [NSManagedObject]) ?? []
let prefix = objects.prefix(3)
let title = viewModel.name(for: section)
PlainListExpandableSectionHeader(title: title, count: section.numberOfObjects, destination: { EmptyView() }, isSeeAllHidden: true)
ForEach(prefix, id: \.objectID, content: ConsoleEntityCell.init)
if prefix.count < objects.count {
#if os(iOS)
NavigationLink(destination: ConsoleStaticList(entities: objects).inlineNavigationTitle(title)) {
PlainListSeeAllView(count: objects.count)
}
#else
Button(action: { viewModel.focus(on: objects) }) {
PlainListSeeAllView(count: objects.count)
}.buttonStyle(.plain)
#endif
}
}
}
#endif