From e4df8a8b69a145c8d74318184b97a80ebe1bd282 Mon Sep 17 00:00:00 2001 From: Paul Schuetz Date: Thu, 14 Dec 2023 07:12:12 +0100 Subject: [PATCH] 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. --- .../Status/Detail/StatusDetailView.swift | 3 +- .../Status/Row/StatusRowViewModel.swift | 15 ++++++- .../Row/Subviews/StatusRowReplyView.swift | 40 ++++++++++--------- 3 files changed, 37 insertions(+), 21 deletions(-) diff --git a/Packages/Status/Sources/Status/Detail/StatusDetailView.swift b/Packages/Status/Sources/Status/Detail/StatusDetailView.swift index edc5af50..eaf0cfcf 100644 --- a/Packages/Status/Sources/Status/Detail/StatusDetailView.swift +++ b/Packages/Status/Sources/Status/Detail/StatusDetailView.swift @@ -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) diff --git a/Packages/Status/Sources/Status/Row/StatusRowViewModel.swift b/Packages/Status/Sources/Status/Row/StatusRowViewModel.swift index 9b80fa67..9e289910 100644 --- a/Packages/Status/Sources/Status/Row/StatusRowViewModel.swift +++ b/Packages/Status/Sources/Status/Row/StatusRowViewModel.swift @@ -39,6 +39,8 @@ import SwiftUI var isLoadingRemoteContent: Bool = false var localStatusId: String? var localStatus: Status? + + private var scrollToId = nil as Binding? // 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? = 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])) diff --git a/Packages/Status/Sources/Status/Row/Subviews/StatusRowReplyView.swift b/Packages/Status/Sources/Status/Row/Subviews/StatusRowReplyView.swift index eab94f9b..fa06b31b 100644 --- a/Packages/Status/Sources/Status/Row/Subviews/StatusRowReplyView.swift +++ b/Packages/Status/Sources/Status/Row/Subviews/StatusRowReplyView.swift @@ -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)