Link to parent post (#1736)

The "reply to ..."-text is now a link to the parent post. A tap scrolls to the
parent if the whole hierarchy over a post is shown (detail view). Otherwise,
the detail view for the parent is opened.
This commit is contained in:
Paul Schuetz 2023-12-14 07:12:12 +01:00 committed by GitHub
parent 81ba1e9bee
commit e4df8a8b69
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 37 additions and 21 deletions

View file

@ -112,7 +112,8 @@ public struct StatusDetailView: View {
let (indentationLevel, extraInsets) = viewModel.getIndentationLevel(id: status.id)
let viewModel: StatusRowViewModel = .init(status: status,
client: client,
routerPath: routerPath)
routerPath: routerPath,
scrollToId: $viewModel.scrollToId)
let isFocused = self.viewModel.statusId == status.id
StatusRowView(viewModel: viewModel)

View file

@ -39,6 +39,8 @@ import SwiftUI
var isLoadingRemoteContent: Bool = false
var localStatusId: String?
var localStatus: Status?
private var scrollToId = nil as Binding<String?>?
// The relationship our user has to the author of this post, if available
var authorRelationship: Relationship? {
@ -108,7 +110,8 @@ import SwiftUI
routerPath: RouterPath,
isRemote: Bool = false,
showActions: Bool = true,
textDisabled: Bool = false)
textDisabled: Bool = false,
scrollToId: Binding<String?>? = nil)
{
self.status = status
finalStatus = status.reblog ?? status
@ -117,6 +120,7 @@ import SwiftUI
self.isRemote = isRemote
self.showActions = showActions
self.textDisabled = textDisabled
self.scrollToId = scrollToId
if let reblog = status.reblog {
isPinned = reblog.pinned == true
} else {
@ -195,6 +199,15 @@ import SwiftUI
routerPath.navigate(to: .accountDetail(id: mention.id))
}
}
func goToParent() {
guard let id = status.inReplyToId else {return}
if let _ = scrollToId {
scrollToId?.wrappedValue = id
} else {
routerPath.navigate(to: .statusDetail(id: id))
}
}
func loadAuthorRelationship() async {
let relationships: [Relationship]? = try? await client.get(endpoint: Accounts.relationships(ids: [status.reblog?.account.id ?? status.account.id]))

View file

@ -7,28 +7,30 @@ struct StatusRowReplyView: View {
var body: some View {
Group {
if let accountId = viewModel.status.inReplyToAccountId {
if let mention = viewModel.status.mentions.first(where: { $0.id == accountId }) {
HStack(spacing: 2) {
Image(systemName: "arrowshape.turn.up.left.fill")
Text("status.row.was-reply \(mention.username)")
Group {
if let mention = viewModel.status.mentions.first(where: { $0.id == accountId }) {
HStack(spacing: 2) {
Image(systemName: "arrowshape.turn.up.left.fill")
Text("status.row.was-reply \(mention.username)")
}
.accessibilityElement(children: .combine)
.accessibilityLabel(
Text("status.row.was-reply \(mention.username)")
)
} else if viewModel.isThread && accountId == viewModel.status.account.id {
HStack(spacing: 2) {
Image(systemName: "quote.opening")
Text("status.row.is-thread")
}
.accessibilityElement(children: .combine)
.accessibilityLabel(
Text("status.row.is-thread")
)
}
}
.accessibilityElement(children: .combine)
.accessibilityLabel(
Text("status.row.was-reply \(mention.username)")
)
.onTapGesture {
viewModel.navigateToMention(mention: mention)
viewModel.goToParent()
}
} else if viewModel.isThread && accountId == viewModel.status.account.id {
HStack(spacing: 2) {
Image(systemName: "quote.opening")
Text("status.row.is-thread")
}
.accessibilityElement(children: .combine)
.accessibilityLabel(
Text("status.row.is-thread")
)
}
}
}
.font(.scaledFootnote)