Show threading / reply to UI in post detail

This commit is contained in:
Thomas Ricouard 2023-02-16 12:15:13 +01:00
parent ab0b207596
commit f1919305ab
1 changed files with 30 additions and 6 deletions

View File

@ -42,18 +42,14 @@ public struct StatusDetailView: View {
case let .display(status, context, date):
if !context.ancestors.isEmpty {
ForEach(context.ancestors) { ancestor in
StatusRowView(viewModel: .init(status: ancestor, client: client, routerPath: routerPath, isCompact: false))
}
makeStatusesListView(statuses: context.ancestors)
}
makeCurrentStatusView(status: status)
.id(date)
if !context.descendants.isEmpty {
ForEach(context.descendants) { descendant in
StatusRowView(viewModel: .init(status: descendant, client: client, routerPath: routerPath, isCompact: false))
}
makeStatusesListView(statuses: context.descendants)
}
if !isLoaded {
@ -105,6 +101,34 @@ public struct StatusDetailView: View {
.navigationTitle(viewModel.title)
.navigationBarTitleDisplayMode(.inline)
}
private func makeStatusesListView(statuses: [Status]) -> some View {
ForEach(statuses) { status in
var isReplyToPrevious: Bool = false
if let index = statuses.firstIndex(where: { $0.id == status.id }),
index > 0,
statuses[index - 1].inReplyToAccountId == status.account.id {
isReplyToPrevious = true
}
let viewModel: StatusRowViewModel = .init(status: status,
client: client,
routerPath: routerPath,
isCompact: false)
return HStack {
if isReplyToPrevious {
Rectangle()
.fill(theme.tintColor)
.frame(width: 2)
}
StatusRowView(viewModel: viewModel)
}
.listRowBackground(viewModel.highlightRowColor)
.listRowInsets(.init(top: 12,
leading: .layoutPadding,
bottom: 12,
trailing: .layoutPadding))
}
}
private func makeCurrentStatusView(status: Status) -> some View {
StatusRowView(viewModel: .init(status: status,