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

123 lines
3.7 KiB
Swift
Raw Normal View History

2022-12-19 11:28:55 +00:00
import DesignSystem
import EmojiText
2023-01-17 10:36:01 +00:00
import Env
import Models
import Status
import SwiftUI
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
2023-01-17 10:36:01 +00:00
2022-12-19 11:28:55 +00:00
let notification: Models.Notification
2023-01-17 10:36:01 +00:00
2022-12-19 11:28:55 +00:00
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()
}
}
2023-01-17 10:36:01 +00:00
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)
2023-01-17 10:36:01 +00:00
2022-12-24 09:14:47 +00:00
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
}
2023-01-17 10:36:01 +00:00
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) {
EmojiTextApp(notification.account.safeDisplayName.asMarkdown,
emojis: notification.account.emojis,
append: {
2023-01-17 10:36:01 +00:00
Text(" ") +
Text(type.label())
.font(.subheadline)
.fontWeight(.regular) +
Text("")
.font(.footnote)
.fontWeight(.regular)
.foregroundColor(.gray) +
Text(notification.createdAt.formatted)
.font(.footnote)
.fontWeight(.regular)
.foregroundColor(.gray)
})
.font(.subheadline)
.fontWeight(.semibold)
2022-12-24 09:14:47 +00:00
Spacer()
}
}
.contentShape(Rectangle())
.onTapGesture {
routeurPath.navigate(to: .accountDetailWithAccount(account: notification.account))
}
2022-12-24 09:14:47 +00:00
}
2023-01-17 10:36:01 +00:00
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 {
2023-01-17 06:54:59 +00:00
if type == .mention {
StatusRowView(viewModel: .init(status: status, isCompact: true, showActions: true))
} else {
StatusRowView(viewModel: .init(status: status, isCompact: true, showActions: false))
.foregroundColor(.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)
2023-01-17 10:36:01 +00:00
if type == .follow {
EmojiTextApp(notification.account.note.asMarkdown,
emojis: notification.account.emojis)
.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())
}
}