2022-11-21 08:31:32 +00:00
|
|
|
import SwiftUI
|
2022-11-29 08:28:17 +00:00
|
|
|
import Models
|
2022-12-22 09:53:36 +00:00
|
|
|
import Env
|
2022-12-19 11:28:55 +00:00
|
|
|
import DesignSystem
|
2022-12-19 14:51:25 +00:00
|
|
|
import Network
|
2022-11-21 08:31:32 +00:00
|
|
|
|
2022-12-18 19:30:19 +00:00
|
|
|
public struct StatusRowView: View {
|
2022-12-17 12:37:46 +00:00
|
|
|
@Environment(\.redactionReasons) private var reasons
|
2022-12-19 14:51:25 +00:00
|
|
|
@EnvironmentObject private var client: Client
|
2022-11-29 10:46:02 +00:00
|
|
|
@EnvironmentObject private var routeurPath: RouterPath
|
2022-12-20 19:33:45 +00:00
|
|
|
@StateObject var viewModel: StatusRowViewModel
|
2022-11-29 10:46:02 +00:00
|
|
|
|
2022-12-20 19:33:45 +00:00
|
|
|
public init(viewModel: StatusRowViewModel) {
|
|
|
|
_viewModel = StateObject(wrappedValue: viewModel)
|
2022-12-18 19:30:19 +00:00
|
|
|
}
|
2022-12-20 19:33:45 +00:00
|
|
|
|
2022-12-18 19:30:19 +00:00
|
|
|
public var body: some View {
|
2022-11-21 08:31:32 +00:00
|
|
|
VStack(alignment: .leading) {
|
2022-12-16 12:16:48 +00:00
|
|
|
reblogView
|
|
|
|
statusView
|
2022-12-23 16:50:51 +00:00
|
|
|
if !viewModel.isEmbed {
|
|
|
|
StatusActionsView(viewModel: viewModel)
|
|
|
|
.padding(.vertical, 8)
|
|
|
|
}
|
2022-12-16 12:16:48 +00:00
|
|
|
}
|
2022-12-20 19:33:45 +00:00
|
|
|
.onAppear {
|
|
|
|
viewModel.client = client
|
|
|
|
}
|
2022-12-16 12:16:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@ViewBuilder
|
|
|
|
private var reblogView: some View {
|
2022-12-20 19:33:45 +00:00
|
|
|
if viewModel.status.reblog != nil {
|
2022-12-16 12:16:48 +00:00
|
|
|
HStack(spacing: 2) {
|
|
|
|
Image(systemName:"arrow.left.arrow.right.circle")
|
2022-12-21 16:39:48 +00:00
|
|
|
viewModel.status.account.displayNameWithEmojis
|
|
|
|
Text("boosted")
|
2022-11-29 10:46:02 +00:00
|
|
|
}
|
2022-12-16 12:16:48 +00:00
|
|
|
.font(.footnote)
|
|
|
|
.foregroundColor(.gray)
|
|
|
|
.fontWeight(.semibold)
|
2022-12-21 16:39:48 +00:00
|
|
|
.onTapGesture {
|
|
|
|
routeurPath.navigate(to: .accountDetailWithAccount(account: viewModel.status.account))
|
|
|
|
}
|
2022-11-29 10:46:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-16 12:16:48 +00:00
|
|
|
private var statusView: some View {
|
2022-12-20 08:37:07 +00:00
|
|
|
VStack(alignment: .leading, spacing: 8) {
|
2022-12-20 19:33:45 +00:00
|
|
|
if let status: AnyStatus = viewModel.status.reblog ?? viewModel.status {
|
|
|
|
if !viewModel.isEmbed {
|
2022-12-20 08:37:07 +00:00
|
|
|
Button {
|
|
|
|
routeurPath.navigate(to: .accountDetailWithAccount(account: status.account))
|
|
|
|
} label: {
|
|
|
|
makeAccountView(status: status)
|
|
|
|
}.buttonStyle(.plain)
|
|
|
|
}
|
|
|
|
|
|
|
|
Text(status.content.asSafeAttributedString)
|
|
|
|
.font(.body)
|
|
|
|
.onTapGesture {
|
|
|
|
routeurPath.navigate(to: .statusDetail(id: status.id))
|
|
|
|
}
|
|
|
|
.environment(\.openURL, OpenURLAction { url in
|
|
|
|
routeurPath.handleStatus(status: status, url: url)
|
|
|
|
})
|
|
|
|
|
|
|
|
if !status.mediaAttachments.isEmpty {
|
2022-12-23 16:50:51 +00:00
|
|
|
if viewModel.isEmbed {
|
|
|
|
Image(systemName: "paperclip")
|
|
|
|
} else {
|
|
|
|
StatusMediaPreviewView(attachements: status.mediaAttachments)
|
|
|
|
.padding(.vertical, 4)
|
|
|
|
}
|
2022-12-16 12:16:48 +00:00
|
|
|
}
|
2022-12-23 16:50:51 +00:00
|
|
|
if let card = status.card, !viewModel.isEmbed {
|
2022-12-23 09:41:55 +00:00
|
|
|
StatusCardView(card: card)
|
|
|
|
}
|
2022-12-17 12:37:46 +00:00
|
|
|
}
|
2022-12-16 12:16:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@ViewBuilder
|
|
|
|
private func makeAccountView(status: AnyStatus) -> some View {
|
2022-12-23 09:41:55 +00:00
|
|
|
AvatarView(url: status.account.avatar, size: .status)
|
2022-12-21 16:39:48 +00:00
|
|
|
VStack(alignment: .leading, spacing: 0) {
|
|
|
|
status.account.displayNameWithEmojis
|
2022-12-20 08:37:07 +00:00
|
|
|
.font(.subheadline)
|
|
|
|
.fontWeight(.semibold)
|
|
|
|
Group {
|
|
|
|
Text("@\(status.account.acct)") +
|
|
|
|
Text(" ⸱ ") +
|
2022-12-17 12:37:46 +00:00
|
|
|
Text(status.createdAt.formatted)
|
2022-12-16 12:16:48 +00:00
|
|
|
}
|
2022-12-20 08:37:07 +00:00
|
|
|
.font(.footnote)
|
|
|
|
.foregroundColor(.gray)
|
2022-11-21 08:31:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|