Round Details Implementation Guide

Phase: 2e Estimated Effort: 10-12 hours Prerequisites: Phases 2b-2d complete


Overview

Display completed rounds with comprehensive statistics, end-by-end breakdown, and performance metrics.


Components

RoundDetailsView

struct RoundDetailsView: View {
    @StateObject private var viewModel: RoundDetailsViewModel
 
    init(roundId: Int, roundRepository: RoundRepository) {
        _viewModel = StateObject(wrappedValue: RoundDetailsViewModel(
            roundId: roundId,
            roundRepository: roundRepository
        ))
    }
 
    var body: some View {
        ScrollView {
            VStack(spacing: 20) {
                // Summary card
                RoundSummaryCard(round: viewModel.round)
 
                // Statistics
                StatisticsSection(statistics: viewModel.statistics)
 
                // End-by-end breakdown
                EndBreakdownSection(ends: viewModel.ends)
            }
            .padding()
        }
        .navigationTitle("Round Details")
    }
}

RoundDetailsViewModel

class RoundDetailsViewModel: ObservableObject {
    @Published var round: Round?
    @Published var statistics: RoundStatistics?
    @Published var ends: [EndScoreWithArrows] = []
 
    private let roundRepository: RoundRepository
 
    init(roundId: Int, roundRepository: RoundRepository) {
        self.roundRepository = roundRepository
        loadRoundDetails(roundId: roundId)
    }
 
    private func loadRoundDetails(roundId: Int) {
        Task {
            do {
                let details = try await roundRepository.getRoundWithDetails(roundId: Int32(roundId))
                self.round = details?.round
                self.ends = details?.ends ?? []
 
                let stats = try await roundRepository.calculateRoundStatistics(roundId: Int32(roundId))
                self.statistics = stats
            } catch {
                // Handle error
            }
        }
    }
}

Statistics Card

struct StatisticsSection: View {
    let statistics: RoundStatistics?
 
    var body: some View {
        VStack(alignment: .leading, spacing: 12) {
            Text("Statistics")
                .font(.headline)
 
            if let stats = statistics {
                StatRow(label: "Average per Arrow", value: String(format: "%.2f", stats.averagePerArrow))
                StatRow(label: "Average per End", value: String(format: "%.2f", stats.averagePerEnd))
                StatRow(label: "Accuracy", value: String(format: "%.1f%%", stats.accuracy))
                StatRow(label: "X Count", value: "\(stats.xCount)")
                StatRow(label: "10 Count", value: "\(stats.tenCount)")
            }
        }
        .padding()
        .background(Color(.secondarySystemBackground))
        .cornerRadius(12)
    }
}
 
struct StatRow: View {
    let label: String
    let value: String
 
    var body: some View {
        HStack {
            Text(label)
                .foregroundColor(.secondary)
            Spacer()
            Text(value)
                .fontWeight(.semibold)
        }
    }
}

Success Criteria

  • ✅ Round details display all information
  • ✅ Statistics calculate correctly
  • ✅ End-by-end breakdown clear
  • ✅ Navigation flows smoothly

Last Updated: 2025-11-21 Status: Phase 2e planned