Refactor data sources and feed model
This commit is contained in:
@@ -75,7 +75,7 @@ struct CandidatesView: View {
|
||||
}
|
||||
|
||||
private struct CandidateRow: View {
|
||||
let candidate: Candidate
|
||||
let candidate: FeedItem
|
||||
|
||||
var body: some View {
|
||||
VStack(alignment: .leading, spacing: 6) {
|
||||
@@ -88,29 +88,22 @@ private struct CandidateRow: View {
|
||||
.font(.caption)
|
||||
.foregroundStyle(.secondary)
|
||||
}
|
||||
Text(candidate.subtitle)
|
||||
.font(.subheadline)
|
||||
.foregroundStyle(.secondary)
|
||||
.lineLimit(1)
|
||||
if !candidate.subtitle.isEmpty {
|
||||
Text(candidate.subtitle)
|
||||
.font(.subheadline)
|
||||
.foregroundStyle(.secondary)
|
||||
.lineLimit(1)
|
||||
}
|
||||
|
||||
HStack(spacing: 12) {
|
||||
Text(String(format: "conf %.2f", candidate.confidence))
|
||||
Text(String(format: "prio %.2f", candidate.priority))
|
||||
Text("ttl \(candidate.ttlSec)s")
|
||||
Text(expiresText(now: Int(Date().timeIntervalSince1970)))
|
||||
}
|
||||
.font(.caption)
|
||||
.foregroundStyle(.secondary)
|
||||
}
|
||||
.padding(.vertical, 4)
|
||||
}
|
||||
|
||||
private func expiresText(now: Int) -> String {
|
||||
let expiresAt = candidate.createdAt + candidate.ttlSec
|
||||
let remaining = expiresAt - now
|
||||
if remaining <= 0 { return "expired" }
|
||||
if remaining < 60 { return "in \(remaining)s" }
|
||||
return "in \(remaining / 60)m"
|
||||
}
|
||||
}
|
||||
|
||||
struct CandidatesView_Previews: PreviewProvider {
|
||||
|
||||
@@ -45,18 +45,48 @@ struct OrchestratorView: View {
|
||||
Button("Recompute Now") { orchestrator.recomputeNow() }
|
||||
}
|
||||
|
||||
Section("Winner") {
|
||||
if let env = orchestrator.lastWinner {
|
||||
Text(env.winner.title)
|
||||
Section("Feed") {
|
||||
if let feed = orchestrator.lastFeed, let winner = feed.winnerItem() {
|
||||
Text(winner.title)
|
||||
.font(.headline)
|
||||
Text(env.winner.subtitle)
|
||||
.font(.subheadline)
|
||||
.foregroundStyle(.secondary)
|
||||
Text("type \(env.winner.type.rawValue) • prio \(String(format: "%.2f", env.winner.priority)) • ttl \(env.winner.ttlSec)s")
|
||||
if !winner.subtitle.isEmpty {
|
||||
Text(winner.subtitle)
|
||||
.font(.subheadline)
|
||||
.foregroundStyle(.secondary)
|
||||
}
|
||||
Text("type \(winner.type.rawValue) • prio \(String(format: "%.2f", winner.priority)) • ttl \(winner.ttlSec)s")
|
||||
.font(.caption)
|
||||
.foregroundStyle(.secondary)
|
||||
|
||||
if feed.feed.count > 1 {
|
||||
Divider()
|
||||
}
|
||||
|
||||
ForEach(feed.feed, id: \.id) { item in
|
||||
VStack(alignment: .leading, spacing: 6) {
|
||||
HStack {
|
||||
Text(item.title)
|
||||
.font(.headline)
|
||||
.lineLimit(1)
|
||||
Spacer()
|
||||
Text(item.type.rawValue)
|
||||
.font(.caption)
|
||||
.foregroundStyle(.secondary)
|
||||
}
|
||||
if !item.subtitle.isEmpty {
|
||||
Text(item.subtitle)
|
||||
.font(.subheadline)
|
||||
.foregroundStyle(.secondary)
|
||||
.lineLimit(1)
|
||||
}
|
||||
Text("bucket \(item.bucket.rawValue) • prio \(String(format: "%.2f", item.priority)) • ttl \(item.ttlSec)s")
|
||||
.font(.caption)
|
||||
.foregroundStyle(.secondary)
|
||||
}
|
||||
.padding(.vertical, 4)
|
||||
}
|
||||
} else {
|
||||
Text("No winner yet")
|
||||
Text("No feed yet")
|
||||
.foregroundStyle(.secondary)
|
||||
}
|
||||
}
|
||||
@@ -80,35 +110,6 @@ struct OrchestratorView: View {
|
||||
}
|
||||
}
|
||||
|
||||
Section("Candidates (\(orchestrator.lastCandidates.count))") {
|
||||
if orchestrator.lastCandidates.isEmpty {
|
||||
Text("No candidates")
|
||||
.foregroundStyle(.secondary)
|
||||
} else {
|
||||
ForEach(orchestrator.lastCandidates, id: \.id) { c in
|
||||
VStack(alignment: .leading, spacing: 6) {
|
||||
HStack {
|
||||
Text(c.title)
|
||||
.font(.headline)
|
||||
.lineLimit(1)
|
||||
Spacer()
|
||||
Text(c.type.rawValue)
|
||||
.font(.caption)
|
||||
.foregroundStyle(.secondary)
|
||||
}
|
||||
Text(c.subtitle)
|
||||
.font(.subheadline)
|
||||
.foregroundStyle(.secondary)
|
||||
.lineLimit(1)
|
||||
Text("conf \(String(format: "%.2f", c.confidence)) • ttl \(c.ttlSec)s")
|
||||
.font(.caption)
|
||||
.foregroundStyle(.secondary)
|
||||
}
|
||||
.padding(.vertical, 4)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if !orchestrator.lastWeatherDiagnostics.isEmpty {
|
||||
Section("Weather Diagnostics") {
|
||||
ForEach(orchestrator.lastWeatherDiagnostics.keys.sorted(), id: \.self) { key in
|
||||
@@ -122,6 +123,19 @@ struct OrchestratorView: View {
|
||||
}
|
||||
}
|
||||
|
||||
if !orchestrator.lastCalendarDiagnostics.isEmpty {
|
||||
Section("Calendar Diagnostics") {
|
||||
ForEach(orchestrator.lastCalendarDiagnostics.keys.sorted(), id: \.self) { key in
|
||||
LabeledContent(key) {
|
||||
Text(orchestrator.lastCalendarDiagnostics[key] ?? "")
|
||||
.font(.caption)
|
||||
.foregroundStyle(.secondary)
|
||||
.textSelection(.enabled)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Section("Test") {
|
||||
Button("Send Fixture Feed Now") { orchestrator.sendFixtureFeedNow() }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user