IceCubesApp/Packages/Explore/Sources/Explore/TrendingLinksListView.swift

53 lines
1.3 KiB
Swift
Raw Normal View History

2024-02-10 10:26:22 +00:00
import DesignSystem
import Models
2024-02-14 11:48:14 +00:00
import Network
2024-02-10 10:26:22 +00:00
import StatusKit
import SwiftUI
public struct TrendingLinksListView: View {
@Environment(Theme.self) private var theme
@Environment(Client.self) private var client
@State private var links: [Card]
public init(cards: [Card]) {
_links = .init(initialValue: cards)
}
public var body: some View {
List {
ForEach(links) { card in
StatusRowCardView(card: card)
.environment(\.isCompact, true)
2024-02-14 11:48:14 +00:00
#if !os(visionOS)
2024-02-10 10:26:22 +00:00
.listRowBackground(theme.primaryBackgroundColor)
2024-02-14 11:48:14 +00:00
#endif
2024-02-10 10:26:22 +00:00
.padding(.vertical, 8)
}
NextPageView {
let nextPage: [Card] = try await client.get(endpoint: Trends.links(offset: links.count))
links.append(contentsOf: nextPage)
2024-02-10 10:26:22 +00:00
}
2024-02-10 11:16:32 +00:00
#if !os(visionOS)
.listRowBackground(theme.primaryBackgroundColor)
#endif
2024-02-10 10:26:22 +00:00
}
#if os(visionOS)
.listStyle(.insetGrouped)
#else
.listStyle(.plain)
#endif
.refreshable {
do {
links = try await client.get(endpoint: Trends.links(offset: nil))
} catch {}
}
#if !os(visionOS)
.scrollContentBackground(.hidden)
.background(theme.primaryBackgroundColor)
#endif
.navigationTitle("explore.section.trending.links")
.navigationBarTitleDisplayMode(.inline)
}
}