feat(polls): implement group trip polling MVP
Add complete group trip polling feature allowing users to share trips
with friends for voting using Borda count scoring.
New components:
- TripPoll and PollVote domain models with share codes and rankings
- LocalTripPoll and LocalPollVote SwiftData models for persistence
- CKTripPoll and CKPollVote CloudKit record wrappers
- PollService actor for CloudKit CRUD operations and subscriptions
- PollCreation/Detail/Voting views and view models
- Deep link handling for sportstime://poll/{code} URLs
- Debug Pro status override toggle in Settings
Integration:
- HomeView shows polls section in My Trips
- SportsTimeApp registers SwiftData models and handles deep links
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
133
SportsTime/Features/Polls/Views/PollCreationView.swift
Normal file
133
SportsTime/Features/Polls/Views/PollCreationView.swift
Normal file
@@ -0,0 +1,133 @@
|
||||
//
|
||||
// PollCreationView.swift
|
||||
// SportsTime
|
||||
//
|
||||
// View for creating a new trip poll
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
|
||||
struct PollCreationView: View {
|
||||
@Environment(\.dismiss) private var dismiss
|
||||
@Environment(\.colorScheme) private var colorScheme
|
||||
@State private var viewModel = PollCreationViewModel()
|
||||
|
||||
let trips: [Trip]
|
||||
var onPollCreated: ((TripPoll) -> Void)?
|
||||
|
||||
var body: some View {
|
||||
NavigationStack {
|
||||
Form {
|
||||
Section {
|
||||
TextField("Poll Title", text: $viewModel.title)
|
||||
.textInputAutocapitalization(.words)
|
||||
} header: {
|
||||
Text("Title")
|
||||
} footer: {
|
||||
Text("Give your poll a name, like \"Summer Road Trip Options\"")
|
||||
}
|
||||
|
||||
Section {
|
||||
ForEach(trips) { trip in
|
||||
TripSelectionRow(
|
||||
trip: trip,
|
||||
isSelected: viewModel.selectedTripIds.contains(trip.id)
|
||||
) {
|
||||
viewModel.toggleTrip(trip.id)
|
||||
}
|
||||
}
|
||||
} header: {
|
||||
Text("Select Trips (\(viewModel.selectedTripIds.count) selected)")
|
||||
} footer: {
|
||||
if let message = viewModel.validationMessage {
|
||||
Text(message)
|
||||
.foregroundStyle(.secondary)
|
||||
}
|
||||
}
|
||||
}
|
||||
.navigationTitle("Create Poll")
|
||||
.navigationBarTitleDisplayMode(.inline)
|
||||
.toolbar {
|
||||
ToolbarItem(placement: .cancellationAction) {
|
||||
Button("Cancel") {
|
||||
dismiss()
|
||||
}
|
||||
}
|
||||
|
||||
ToolbarItem(placement: .confirmationAction) {
|
||||
Button("Create") {
|
||||
Task {
|
||||
await viewModel.createPoll(trips: trips)
|
||||
}
|
||||
}
|
||||
.disabled(!viewModel.canCreate || viewModel.isLoading)
|
||||
}
|
||||
}
|
||||
.overlay {
|
||||
if viewModel.isLoading {
|
||||
ProgressView()
|
||||
.scaleEffect(1.2)
|
||||
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
||||
.background(.ultraThinMaterial)
|
||||
}
|
||||
}
|
||||
.alert("Error", isPresented: .constant(viewModel.error != nil)) {
|
||||
Button("OK") {
|
||||
viewModel.error = nil
|
||||
}
|
||||
} message: {
|
||||
if let error = viewModel.error {
|
||||
Text(error.localizedDescription)
|
||||
}
|
||||
}
|
||||
.onChange(of: viewModel.createdPoll) { _, newPoll in
|
||||
if let poll = newPoll {
|
||||
onPollCreated?(poll)
|
||||
dismiss()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Trip Selection Row
|
||||
|
||||
private struct TripSelectionRow: View {
|
||||
let trip: Trip
|
||||
let isSelected: Bool
|
||||
let onTap: () -> Void
|
||||
|
||||
var body: some View {
|
||||
Button(action: onTap) {
|
||||
HStack {
|
||||
VStack(alignment: .leading, spacing: 4) {
|
||||
Text(trip.name)
|
||||
.font(.headline)
|
||||
.foregroundStyle(.primary)
|
||||
|
||||
Text(tripSummary)
|
||||
.font(.subheadline)
|
||||
.foregroundStyle(.secondary)
|
||||
}
|
||||
|
||||
Spacer()
|
||||
|
||||
Image(systemName: isSelected ? "checkmark.circle.fill" : "circle")
|
||||
.font(.title2)
|
||||
.foregroundStyle(isSelected ? Theme.warmOrange : .secondary)
|
||||
}
|
||||
.contentShape(Rectangle())
|
||||
}
|
||||
.buttonStyle(.plain)
|
||||
}
|
||||
|
||||
private var tripSummary: String {
|
||||
let stopCount = trip.stops.count
|
||||
let gameCount = trip.stops.flatMap { $0.games }.count
|
||||
return "\(stopCount) stops, \(gameCount) games"
|
||||
}
|
||||
}
|
||||
|
||||
#Preview {
|
||||
PollCreationView(trips: [])
|
||||
}
|
||||
Reference in New Issue
Block a user