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-10 11:30:30 +01:00
|
|
|
private let contentWidth = Int(UIScreen.main.bounds.width) - 50
|
|
|
|
|
|
|
|
var body: some View {
|
|
|
|
HStack (alignment: .top) {
|
|
|
|
|
2023-01-10 20:38:02 +01:00
|
|
|
NavigationLink(destination: UserProfileView(
|
|
|
|
accountId: self.statusViewModel.account.id,
|
|
|
|
accountDisplayName: self.statusViewModel.account.displayName,
|
|
|
|
accountUserName: self.statusViewModel.account.acct)
|
|
|
|
.environmentObject(applicationState)) {
|
|
|
|
AsyncImage(url: self.statusViewModel.account.avatar) { image in
|
|
|
|
image
|
|
|
|
.resizable()
|
|
|
|
.clipShape(Circle())
|
|
|
|
.aspectRatio(contentMode: .fit)
|
|
|
|
} placeholder: {
|
|
|
|
Image(systemName: "person.circle")
|
|
|
|
.resizable()
|
|
|
|
.foregroundColor(.mainTextColor)
|
2023-01-10 11:30:30 +01:00
|
|
|
}
|
2023-01-10 20:38:02 +01:00
|
|
|
.frame(width: 32.0, height: 32.0)
|
|
|
|
}
|
2023-01-10 11:30:30 +01:00
|
|
|
|
|
|
|
VStack (alignment: .leading, spacing: 0) {
|
|
|
|
HStack (alignment: .top) {
|
2023-01-10 20:38:02 +01:00
|
|
|
Text(self.getUserName(statusViewModel: statusViewModel))
|
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-10 20:38:02 +01:00
|
|
|
HTMLFormattedText(self.statusViewModel.content, withFontSize: 14, andWidth: contentWidth)
|
2023-01-10 11:30:30 +01:00
|
|
|
.padding(.top, -4)
|
|
|
|
.padding(.leading, -4)
|
|
|
|
|
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-10 11:30:30 +01:00
|
|
|
self.applicationState.showInteractionStatusId = ""
|
|
|
|
} 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 getUserName(statusViewModel: StatusViewModel) -> String {
|
|
|
|
return statusViewModel.account.displayName ?? statusViewModel.account.acct
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
struct CommentBody_Previews: PreviewProvider {
|
|
|
|
static var previews: some View {
|
2023-01-10 20:38:02 +01:00
|
|
|
Text("")
|
|
|
|
// CommentBody(status: Status(id: "", content: "", application: Application(name: "")))
|
2023-01-10 11:30:30 +01:00
|
|
|
}
|
|
|
|
}
|