IceCubesApp/Packages/Conversations/Sources/Conversations/List/ConversationsListRow.swift

94 lines
2.5 KiB
Swift
Raw Normal View History

2023-01-05 11:39:25 +00:00
import Accounts
import DesignSystem
import Env
2023-01-17 10:36:01 +00:00
import Models
import Network
2023-01-17 10:36:01 +00:00
import SwiftUI
struct ConversationsListRow: View {
@EnvironmentObject private var client: Client
@EnvironmentObject private var routerPath: RouterPath
@EnvironmentObject private var theme: Theme
2023-01-17 10:36:01 +00:00
let conversation: Conversation
@ObservedObject var viewModel: ConversationsListViewModel
2023-01-17 10:36:01 +00:00
var body: some View {
VStack(alignment: .leading) {
HStack(alignment: .top, spacing: 8) {
AvatarView(url: conversation.accounts.first!.avatar)
VStack(alignment: .leading, spacing: 4) {
HStack {
2023-01-17 10:36:01 +00:00
Text(conversation.accounts.map { $0.safeDisplayName }.joined(separator: ", "))
.font(.headline)
.foregroundColor(theme.labelColor)
.multilineTextAlignment(.leading)
Spacer()
if conversation.unread {
Circle()
.foregroundColor(theme.tintColor)
.frame(width: 10, height: 10)
}
Text(conversation.lastStatus.createdAt.formatted)
.font(.footnote)
}
Text(conversation.lastStatus.content.asRawText)
.multilineTextAlignment(.leading)
}
Spacer()
}
.contentShape(Rectangle())
.onTapGesture {
Task {
await viewModel.markAsRead(conversation: conversation)
}
routerPath.navigate(to: .statusDetail(id: conversation.lastStatus.id))
}
.padding(.top, 4)
actionsView
.padding(.bottom, 4)
}
.contextMenu {
contextMenu
}
}
2023-01-17 10:36:01 +00:00
private var actionsView: some View {
HStack(spacing: 12) {
Button {
routerPath.presentedSheet = .replyToStatusEditor(status: conversation.lastStatus)
} label: {
Image(systemName: "arrowshape.turn.up.left.fill")
}
Menu {
contextMenu
} label: {
Image(systemName: "ellipsis")
.frame(width: 30, height: 30)
.contentShape(Rectangle())
}
}
.padding(.leading, 48)
.foregroundColor(.gray)
}
2023-01-17 10:36:01 +00:00
@ViewBuilder
private var contextMenu: some View {
Button {
Task {
await viewModel.markAsRead(conversation: conversation)
}
} label: {
Label("Mark as read", systemImage: "eye")
}
2023-01-17 10:36:01 +00:00
Button(role: .destructive) {
Task {
await viewModel.delete(conversation: conversation)
}
} label: {
Label("Delete", systemImage: "trash")
}
}
}