1
0
mirror of https://github.com/metabolist/metatext synced 2025-01-24 08:22:54 +01:00
metatext-app-ios-iphone-ipad/Shared/Views/StatusesView.swift

57 lines
1.9 KiB
Swift
Raw Normal View History

2020-08-18 07:13:37 +02:00
// Copyright © 2020 Metabolist. All rights reserved.
import SwiftUI
struct StatusesView: View {
@StateObject var viewModel: StatusesViewModel
var body: some View {
2020-08-20 00:16:03 +02:00
ScrollViewReader { scrollViewProxy in
ScrollView {
LazyVStack {
ForEach(Array(zip(viewModel.statusSections.indices, viewModel.statusSections)),
id: \.0) { _, statuses in
ForEach(statuses) { status in
if status == viewModel.contextParent {
statusView(status: status)
} else {
NavigationLink(destination:
LazyView(StatusesView(viewModel:
viewModel.contextViewModel(status: status)))) {
statusView(status: status)
}
.buttonStyle(PlainButtonStyle())
}
Divider()
}
2020-08-18 07:13:37 +02:00
}
2020-08-20 00:16:03 +02:00
if viewModel.loading {
ProgressView()
}
}
}
.onReceive(viewModel.scrollToStatusID.receive(on: DispatchQueue.main)) { id in
withAnimation {
scrollViewProxy.scrollTo(id)
2020-08-18 07:13:37 +02:00
}
}
}
.onAppear { viewModel.request() }
.alertItem($viewModel.alertItem)
}
}
2020-08-20 00:16:03 +02:00
private extension StatusesView {
func statusView(status: Status) -> some View {
Text(status.content)
}
}
2020-08-18 07:13:37 +02:00
#if DEBUG
struct StatusesView_Previews: PreviewProvider {
static var previews: some View {
StatusesView(viewModel: .development)
}
}
#endif