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:
parent
81ba1e9bee
commit
e4df8a8b69
|
@ -112,7 +112,8 @@ public struct StatusDetailView: View {
|
||||||
let (indentationLevel, extraInsets) = viewModel.getIndentationLevel(id: status.id)
|
let (indentationLevel, extraInsets) = viewModel.getIndentationLevel(id: status.id)
|
||||||
let viewModel: StatusRowViewModel = .init(status: status,
|
let viewModel: StatusRowViewModel = .init(status: status,
|
||||||
client: client,
|
client: client,
|
||||||
routerPath: routerPath)
|
routerPath: routerPath,
|
||||||
|
scrollToId: $viewModel.scrollToId)
|
||||||
let isFocused = self.viewModel.statusId == status.id
|
let isFocused = self.viewModel.statusId == status.id
|
||||||
|
|
||||||
StatusRowView(viewModel: viewModel)
|
StatusRowView(viewModel: viewModel)
|
||||||
|
|
|
@ -40,6 +40,8 @@ import SwiftUI
|
||||||
var localStatusId: String?
|
var localStatusId: String?
|
||||||
var localStatus: Status?
|
var localStatus: Status?
|
||||||
|
|
||||||
|
private var scrollToId = nil as Binding<String?>?
|
||||||
|
|
||||||
// The relationship our user has to the author of this post, if available
|
// The relationship our user has to the author of this post, if available
|
||||||
var authorRelationship: Relationship? {
|
var authorRelationship: Relationship? {
|
||||||
didSet {
|
didSet {
|
||||||
|
@ -108,7 +110,8 @@ import SwiftUI
|
||||||
routerPath: RouterPath,
|
routerPath: RouterPath,
|
||||||
isRemote: Bool = false,
|
isRemote: Bool = false,
|
||||||
showActions: Bool = true,
|
showActions: Bool = true,
|
||||||
textDisabled: Bool = false)
|
textDisabled: Bool = false,
|
||||||
|
scrollToId: Binding<String?>? = nil)
|
||||||
{
|
{
|
||||||
self.status = status
|
self.status = status
|
||||||
finalStatus = status.reblog ?? status
|
finalStatus = status.reblog ?? status
|
||||||
|
@ -117,6 +120,7 @@ import SwiftUI
|
||||||
self.isRemote = isRemote
|
self.isRemote = isRemote
|
||||||
self.showActions = showActions
|
self.showActions = showActions
|
||||||
self.textDisabled = textDisabled
|
self.textDisabled = textDisabled
|
||||||
|
self.scrollToId = scrollToId
|
||||||
if let reblog = status.reblog {
|
if let reblog = status.reblog {
|
||||||
isPinned = reblog.pinned == true
|
isPinned = reblog.pinned == true
|
||||||
} else {
|
} else {
|
||||||
|
@ -196,6 +200,15 @@ import SwiftUI
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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 {
|
func loadAuthorRelationship() async {
|
||||||
let relationships: [Relationship]? = try? await client.get(endpoint: Accounts.relationships(ids: [status.reblog?.account.id ?? status.account.id]))
|
let relationships: [Relationship]? = try? await client.get(endpoint: Accounts.relationships(ids: [status.reblog?.account.id ?? status.account.id]))
|
||||||
authorRelationship = relationships?.first
|
authorRelationship = relationships?.first
|
||||||
|
|
|
@ -7,6 +7,7 @@ struct StatusRowReplyView: View {
|
||||||
var body: some View {
|
var body: some View {
|
||||||
Group {
|
Group {
|
||||||
if let accountId = viewModel.status.inReplyToAccountId {
|
if let accountId = viewModel.status.inReplyToAccountId {
|
||||||
|
Group {
|
||||||
if let mention = viewModel.status.mentions.first(where: { $0.id == accountId }) {
|
if let mention = viewModel.status.mentions.first(where: { $0.id == accountId }) {
|
||||||
HStack(spacing: 2) {
|
HStack(spacing: 2) {
|
||||||
Image(systemName: "arrowshape.turn.up.left.fill")
|
Image(systemName: "arrowshape.turn.up.left.fill")
|
||||||
|
@ -16,9 +17,6 @@ struct StatusRowReplyView: View {
|
||||||
.accessibilityLabel(
|
.accessibilityLabel(
|
||||||
Text("status.row.was-reply \(mention.username)")
|
Text("status.row.was-reply \(mention.username)")
|
||||||
)
|
)
|
||||||
.onTapGesture {
|
|
||||||
viewModel.navigateToMention(mention: mention)
|
|
||||||
}
|
|
||||||
} else if viewModel.isThread && accountId == viewModel.status.account.id {
|
} else if viewModel.isThread && accountId == viewModel.status.account.id {
|
||||||
HStack(spacing: 2) {
|
HStack(spacing: 2) {
|
||||||
Image(systemName: "quote.opening")
|
Image(systemName: "quote.opening")
|
||||||
|
@ -30,6 +28,10 @@ struct StatusRowReplyView: View {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
.onTapGesture {
|
||||||
|
viewModel.goToParent()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
.font(.scaledFootnote)
|
.font(.scaledFootnote)
|
||||||
.foregroundStyle(.secondary)
|
.foregroundStyle(.secondary)
|
||||||
|
|
Loading…
Reference in New Issue