IceCubesApp/Packages/Notifications/Sources/Notifications/NotificationRowView.swift

111 lines
3.1 KiB
Swift
Raw Normal View History

2022-12-19 11:28:55 +00:00
import SwiftUI
import Models
import DesignSystem
import Status
2022-12-22 09:53:36 +00:00
import Env
2022-12-19 11:28:55 +00:00
struct NotificationRowView: View {
2022-12-24 14:09:17 +00:00
@EnvironmentObject private var theme: Theme
2022-12-19 11:28:55 +00:00
@EnvironmentObject private var routeurPath: RouterPath
@Environment(\.redactionReasons) private var reasons
let notification: Models.Notification
var body: some View {
if let type = notification.supportedType {
HStack(alignment: .top, spacing: 8) {
2022-12-24 09:14:47 +00:00
makeAvatarView(type: type)
2022-12-24 12:41:25 +00:00
VStack(alignment: .leading, spacing: 2) {
2022-12-24 09:14:47 +00:00
makeMainLabel(type: type)
makeContent(type: type)
2022-12-19 11:28:55 +00:00
}
}
} else {
EmptyView()
}
}
2022-12-24 09:14:47 +00:00
private func makeAvatarView(type: Models.Notification.NotificationType) -> some View {
ZStack(alignment: .topLeading) {
AvatarView(url: notification.account.avatar)
ZStack(alignment: .center) {
Circle()
.strokeBorder(Color.white, lineWidth: 1)
2022-12-24 14:09:17 +00:00
.background(Circle().foregroundColor(theme.tintColor))
2022-12-24 09:14:47 +00:00
.frame(width: 24, height: 24)
Image(systemName: type.iconName())
.resizable()
.frame(width: 12, height: 12)
.foregroundColor(.white)
}
.offset(x: -14, y: -4)
}
.contentShape(Rectangle())
.onTapGesture {
routeurPath.navigate(to: .accountDetailWithAccount(account: notification.account))
}
2022-12-24 09:14:47 +00:00
}
private func makeMainLabel(type: Models.Notification.NotificationType) -> some View {
VStack(alignment: .leading, spacing: 0) {
HStack(spacing: 0) {
2023-01-03 07:17:47 +00:00
Text(notification.account.safeDisplayName)
2022-12-24 09:14:47 +00:00
.font(.subheadline)
.fontWeight(.semibold) +
Text(" ") +
Text(type.label())
.font(.subheadline) +
Text("")
.font(.footnote)
.foregroundColor(.gray) +
Text(notification.createdAt.formatted)
.font(.footnote)
.foregroundColor(.gray)
Spacer()
}
}
.contentShape(Rectangle())
.onTapGesture {
routeurPath.navigate(to: .accountDetailWithAccount(account: notification.account))
}
2022-12-24 09:14:47 +00:00
}
@ViewBuilder
private func makeContent(type: Models.Notification.NotificationType) -> some View {
if let status = notification.status {
2022-12-29 16:22:07 +00:00
HStack {
StatusRowView(viewModel: .init(status: status, isCompact: true))
2023-01-04 07:14:37 +00:00
.foregroundColor(type == .mention ? theme.labelColor : .gray)
2022-12-29 16:22:07 +00:00
Spacer()
}
2022-12-24 09:14:47 +00:00
} else {
Group {
Text("@\(notification.account.acct)")
2022-12-24 12:41:25 +00:00
.font(.callout)
2022-12-24 09:14:47 +00:00
.foregroundColor(.gray)
if type == .follow {
Text(notification.account.note.asSafeAttributedString)
.lineLimit(3)
.font(.callout)
.foregroundColor(.gray)
.environment(\.openURL, OpenURLAction { url in
routeurPath.handle(url: url)
})
}
}
.contentShape(Rectangle())
.onTapGesture {
routeurPath.navigate(to: .accountDetailWithAccount(account: notification.account))
2022-12-24 09:14:47 +00:00
}
}
}
2022-12-19 11:28:55 +00:00
}
struct NotificationRowView_Previews: PreviewProvider {
static var previews: some View {
NotificationRowView(notification: .placeholder())
}
}