bugger/Sources/Views/MenuBar/BugRow.swift

83 lines
2.4 KiB
Swift

import SwiftUI
struct BugRow: View {
let bug: Bug
let isUnseen: Bool
var body: some View {
HStack(spacing: 10) {
PriorityBadge(priority: bug.priority)
VStack(alignment: .leading, spacing: 2) {
HStack {
Text(bug.title)
.font(.system(size: 13))
.lineLimit(1)
if isUnseen {
Circle()
.fill(.blue)
.frame(width: 6, height: 6)
}
}
HStack(spacing: 8) {
StatusPill(status: bug.status)
Text(ageString(bug.age))
.font(.caption2)
.foregroundStyle(.secondary)
if let reporter = bug.reporter {
Text("by \(reporter)")
.font(.caption2)
.foregroundStyle(.secondary)
}
}
}
Spacer()
Image(systemName: "chevron.right")
.font(.caption2)
.foregroundStyle(.secondary)
}
.padding(.horizontal, 12)
.padding(.vertical, 8)
.background(isUnseen ? Color.blue.opacity(0.05) : Color.clear)
}
private func ageString(_ age: TimeInterval) -> String {
let days = Int(age / 86_400)
let hours = Int(age / 3_600)
if days > 0 { return "\(days)d" }
if hours > 0 { return "\(hours)h" }
return "just now"
}
}
struct PriorityBadge: View {
let priority: BugPriority
var body: some View {
Text(priority == .unknown ? "?" : priority.rawValue)
.font(.caption)
.fontWeight(.bold)
.foregroundStyle(.white)
.padding(.horizontal, 6)
.padding(.vertical, 2)
.background(priority.color)
.clipShape(RoundedRectangle(cornerRadius: 4))
}
}
struct StatusPill: View {
let status: BugStatus
var body: some View {
Text(status == .unknown ? "Unknown" : status.rawValue)
.font(.caption2)
.padding(.horizontal, 5)
.padding(.vertical, 1)
.background(status.color.opacity(0.15))
.foregroundStyle(status.color)
.clipShape(RoundedRectangle(cornerRadius: 3))
}
}