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
|
2023-01-12 05:58:04 +00:00
|
|
|
import EmojiText
|
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)
|
|
|
|
}
|
2022-12-26 07:47:41 +00:00
|
|
|
.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-12 20:12:47 +00:00
|
|
|
EmojiTextApp(notification.account.safeDisplayName.asMarkdown,
|
|
|
|
emojis: notification.account.emojis,
|
|
|
|
append: {
|
2023-01-12 05:58:04 +00:00
|
|
|
Text(" ") +
|
|
|
|
Text(type.label())
|
2023-01-12 17:17:03 +00:00
|
|
|
.font(.subheadline)
|
|
|
|
.fontWeight(.regular) +
|
2023-01-12 05:58:04 +00:00
|
|
|
Text(" ⸱ ")
|
|
|
|
.font(.footnote)
|
2023-01-12 17:17:03 +00:00
|
|
|
.fontWeight(.regular)
|
2023-01-12 05:58:04 +00:00
|
|
|
.foregroundColor(.gray) +
|
|
|
|
Text(notification.createdAt.formatted)
|
|
|
|
.font(.footnote)
|
2023-01-12 17:17:03 +00:00
|
|
|
.fontWeight(.regular)
|
2023-01-12 05:58:04 +00:00
|
|
|
.foregroundColor(.gray)
|
2023-01-12 20:12:47 +00:00
|
|
|
})
|
2023-01-12 17:17:03 +00:00
|
|
|
.font(.subheadline)
|
|
|
|
.fontWeight(.semibold)
|
2022-12-24 09:14:47 +00:00
|
|
|
Spacer()
|
|
|
|
}
|
|
|
|
}
|
2022-12-26 07:47:41 +00:00
|
|
|
.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 {
|
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 {
|
2022-12-26 07:47:41 +00:00
|
|
|
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)
|
2022-12-26 07:47:41 +00:00
|
|
|
|
|
|
|
if type == .follow {
|
2023-01-12 20:12:47 +00:00
|
|
|
EmojiTextApp(notification.account.note.asMarkdown,
|
|
|
|
emojis: notification.account.emojis)
|
2022-12-26 07:47:41 +00:00
|
|
|
.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())
|
|
|
|
}
|
|
|
|
}
|