2023-01-10 11:30:30 +01:00
|
|
|
//
|
|
|
|
// https://mczachurski.dev
|
|
|
|
// Copyright © 2023 Marcin Czachurski and the repository contributors.
|
|
|
|
// Licensed under the MIT License.
|
|
|
|
//
|
|
|
|
|
|
|
|
import SwiftUI
|
|
|
|
import MastodonKit
|
|
|
|
|
|
|
|
struct CommentBody: View {
|
|
|
|
@EnvironmentObject var applicationState: ApplicationState
|
|
|
|
|
2023-01-10 20:38:02 +01:00
|
|
|
@State var statusViewModel: StatusViewModel
|
2023-01-20 13:47:38 +01:00
|
|
|
private let contentWidth = Int(UIScreen.main.bounds.width) - 60
|
2023-01-10 11:30:30 +01:00
|
|
|
|
|
|
|
var body: some View {
|
|
|
|
HStack (alignment: .top) {
|
|
|
|
|
2023-01-23 18:01:27 +01:00
|
|
|
NavigationLink(value: RouteurDestinations.userProfile(
|
2023-01-10 20:38:02 +01:00
|
|
|
accountId: self.statusViewModel.account.id,
|
|
|
|
accountDisplayName: self.statusViewModel.account.displayName,
|
|
|
|
accountUserName: self.statusViewModel.account.acct)
|
2023-01-23 18:01:27 +01:00
|
|
|
) {
|
2023-01-24 20:38:21 +01:00
|
|
|
UserAvatar(accountAvatar: self.statusViewModel.account.avatar, size: .comment)
|
2023-01-23 18:01:27 +01:00
|
|
|
}
|
2023-01-10 11:30:30 +01:00
|
|
|
|
|
|
|
VStack (alignment: .leading, spacing: 0) {
|
|
|
|
HStack (alignment: .top) {
|
2023-01-18 18:41:42 +01:00
|
|
|
Text(statusViewModel.account.displayNameWithoutEmojis)
|
2023-01-10 11:30:30 +01:00
|
|
|
.foregroundColor(.mainTextColor)
|
|
|
|
.font(.footnote)
|
|
|
|
.fontWeight(.bold)
|
|
|
|
|
|
|
|
Spacer()
|
|
|
|
|
2023-01-10 20:38:02 +01:00
|
|
|
Text(self.statusViewModel.createdAt.toRelative(.isoDateTimeMilliSec))
|
2023-01-10 11:30:30 +01:00
|
|
|
.foregroundColor(.lightGrayColor)
|
|
|
|
.font(.footnote)
|
|
|
|
}
|
|
|
|
|
2023-01-23 18:01:27 +01:00
|
|
|
MarkdownFormattedText(self.statusViewModel.content.asMarkdown, withFontSize: 14, andWidth: contentWidth)
|
|
|
|
.environment(\.openURL, OpenURLAction { url in .handled })
|
|
|
|
.padding(.top, 4)
|
2023-01-10 11:30:30 +01:00
|
|
|
|
2023-01-10 20:38:02 +01:00
|
|
|
if self.statusViewModel.mediaAttachments.count > 0 {
|
2023-01-10 11:30:30 +01:00
|
|
|
LazyVGrid(
|
2023-01-10 20:38:02 +01:00
|
|
|
columns: self.statusViewModel.mediaAttachments.count == 1 ? [GridItem(.flexible())]: [GridItem(.flexible()), GridItem(.flexible())],
|
2023-01-10 11:30:30 +01:00
|
|
|
alignment: .center,
|
|
|
|
spacing: 4
|
|
|
|
) {
|
2023-01-10 20:38:02 +01:00
|
|
|
ForEach(self.statusViewModel.mediaAttachments, id: \.id) { attachment in
|
2023-01-10 11:30:30 +01:00
|
|
|
AsyncImage(url: attachment.url) { image in
|
|
|
|
image
|
|
|
|
.resizable()
|
|
|
|
.scaledToFill()
|
|
|
|
.frame(minWidth: 0, maxWidth: .infinity)
|
2023-01-10 20:38:02 +01:00
|
|
|
.frame(height: self.statusViewModel.mediaAttachments.count == 1 ? 200 : 100)
|
2023-01-10 11:30:30 +01:00
|
|
|
.cornerRadius(10)
|
|
|
|
.shadow(color: .mainTextColor.opacity(0.3), radius: 2)
|
|
|
|
} placeholder: {
|
|
|
|
Image(systemName: "photo")
|
|
|
|
.resizable()
|
|
|
|
.scaledToFit()
|
|
|
|
.frame(minWidth: 0, maxWidth: .infinity)
|
2023-01-10 20:38:02 +01:00
|
|
|
.frame(height: self.statusViewModel.mediaAttachments.count == 1 ? 200 : 100)
|
2023-01-10 11:30:30 +01:00
|
|
|
.foregroundColor(.mainTextColor)
|
|
|
|
.opacity(0.05)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
.padding(.bottom, 8)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
.onTapGesture {
|
|
|
|
withAnimation(.linear(duration: 0.3)) {
|
2023-01-10 20:38:02 +01:00
|
|
|
if self.statusViewModel.id == self.applicationState.showInteractionStatusId {
|
2023-01-14 08:52:51 +01:00
|
|
|
self.applicationState.showInteractionStatusId = String.empty()
|
2023-01-10 11:30:30 +01:00
|
|
|
} else {
|
2023-01-10 20:38:02 +01:00
|
|
|
self.applicationState.showInteractionStatusId = self.statusViewModel.id
|
2023-01-10 11:30:30 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
.padding(8)
|
2023-01-10 20:38:02 +01:00
|
|
|
.background(self.getSelectedRowColor(statusViewModel: statusViewModel))
|
2023-01-10 11:30:30 +01:00
|
|
|
}
|
|
|
|
|
2023-01-10 20:38:02 +01:00
|
|
|
private func getSelectedRowColor(statusViewModel: StatusViewModel) -> Color {
|
|
|
|
return self.applicationState.showInteractionStatusId == statusViewModel.id ? Color.selectedRowColor : Color.systemBackground
|
2023-01-10 11:30:30 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|