fix: multiple bug fixes and improvements
- Fix suggested trips showing wrong sports for cross-country trips - Remove quick start sections from home variants (Classic, Spotify) - Remove dead quickActions code from HomeView - Fix pace capsule animation in TripCreationView - Add text wrapping to achievement descriptions - Improve poll parsing with better error handling - Various sharing system improvements Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -510,17 +510,49 @@ struct CKTripPoll {
|
||||
}
|
||||
|
||||
func toPoll() -> TripPoll? {
|
||||
// Required fields with explicit guards for better debugging
|
||||
guard let pollIdString = record[CKTripPoll.pollIdKey] as? String,
|
||||
let pollId = UUID(uuidString: pollIdString),
|
||||
let title = record[CKTripPoll.titleKey] as? String,
|
||||
let ownerId = record[CKTripPoll.ownerIdKey] as? String,
|
||||
let shareCode = record[CKTripPoll.shareCodeKey] as? String,
|
||||
let tripsData = record[CKTripPoll.tripSnapshotsKey] as? Data,
|
||||
let tripSnapshots = try? JSONDecoder().decode([Trip].self, from: tripsData),
|
||||
let tripVersions = record[CKTripPoll.tripVersionsKey] as? [String],
|
||||
let createdAt = record[CKTripPoll.createdAtKey] as? Date,
|
||||
let modifiedAt = record[CKTripPoll.modifiedAtKey] as? Date
|
||||
else { return nil }
|
||||
let pollId = UUID(uuidString: pollIdString)
|
||||
else {
|
||||
print("CKTripPoll.toPoll: Failed to parse pollId")
|
||||
return nil
|
||||
}
|
||||
|
||||
guard let title = record[CKTripPoll.titleKey] as? String else {
|
||||
print("CKTripPoll.toPoll: Missing title for poll \(pollId)")
|
||||
return nil
|
||||
}
|
||||
|
||||
guard let ownerId = record[CKTripPoll.ownerIdKey] as? String else {
|
||||
print("CKTripPoll.toPoll: Missing ownerId for poll \(pollId)")
|
||||
return nil
|
||||
}
|
||||
|
||||
guard let shareCode = record[CKTripPoll.shareCodeKey] as? String else {
|
||||
print("CKTripPoll.toPoll: Missing shareCode for poll \(pollId)")
|
||||
return nil
|
||||
}
|
||||
|
||||
guard let createdAt = record[CKTripPoll.createdAtKey] as? Date else {
|
||||
print("CKTripPoll.toPoll: Missing createdAt for poll \(pollId)")
|
||||
return nil
|
||||
}
|
||||
|
||||
// modifiedAt defaults to createdAt if missing
|
||||
let modifiedAt = record[CKTripPoll.modifiedAtKey] as? Date ?? createdAt
|
||||
|
||||
// Decode trip snapshots - this is the most likely failure point
|
||||
var tripSnapshots: [Trip] = []
|
||||
if let tripsData = record[CKTripPoll.tripSnapshotsKey] as? Data {
|
||||
do {
|
||||
tripSnapshots = try JSONDecoder().decode([Trip].self, from: tripsData)
|
||||
} catch {
|
||||
print("CKTripPoll.toPoll: Failed to decode tripSnapshots for poll \(pollId): \(error)")
|
||||
// Return poll with empty trips rather than failing completely
|
||||
}
|
||||
} else {
|
||||
print("CKTripPoll.toPoll: Missing tripSnapshots data for poll \(pollId)")
|
||||
}
|
||||
|
||||
var poll = TripPoll(
|
||||
id: pollId,
|
||||
@@ -531,8 +563,13 @@ struct CKTripPoll {
|
||||
createdAt: createdAt,
|
||||
modifiedAt: modifiedAt
|
||||
)
|
||||
// Preserve the actual stored versions (not recomputed)
|
||||
poll.tripVersions = tripVersions
|
||||
|
||||
// tripVersions is optional - it's recomputed if missing
|
||||
if let storedVersions = record[CKTripPoll.tripVersionsKey] as? [String] {
|
||||
poll.tripVersions = storedVersions
|
||||
}
|
||||
// Otherwise, keep the computed versions from init
|
||||
|
||||
return poll
|
||||
}
|
||||
}
|
||||
|
||||
@@ -184,6 +184,13 @@ actor PollService {
|
||||
}
|
||||
|
||||
func deletePoll(_ pollId: UUID) async throws {
|
||||
// Verify ownership before deleting
|
||||
let poll = try await fetchPoll(byId: pollId)
|
||||
let userId = try await getCurrentUserRecordID()
|
||||
guard poll.ownerId == userId else {
|
||||
throw PollError.notPollOwner
|
||||
}
|
||||
|
||||
let recordID = CKRecord.ID(recordName: pollId.uuidString)
|
||||
|
||||
do {
|
||||
@@ -193,6 +200,8 @@ actor PollService {
|
||||
try await publicDatabase.deleteRecord(withID: recordID)
|
||||
} catch let error as CKError {
|
||||
throw mapCloudKitError(error)
|
||||
} catch let error as PollError {
|
||||
throw error
|
||||
} catch {
|
||||
throw PollError.unknown(error)
|
||||
}
|
||||
|
||||
@@ -484,13 +484,17 @@ final class SuggestedTripsGenerator {
|
||||
// Build richGames dictionary
|
||||
let richGames = buildRichGames(from: selectedGames, teams: teams, stadiums: stadiums)
|
||||
|
||||
// Compute sports from games actually in the trip (not all selectedGames)
|
||||
let gameIdsInTrip = Set(trip.stops.flatMap { $0.games })
|
||||
let actualSports = Set(gameIdsInTrip.compactMap { richGames[$0]?.game.sport })
|
||||
|
||||
return SuggestedTrip(
|
||||
id: UUID(),
|
||||
region: .crossCountry,
|
||||
isSingleSport: sports.count == 1,
|
||||
isSingleSport: actualSports.count == 1,
|
||||
trip: trip,
|
||||
richGames: richGames,
|
||||
sports: sports
|
||||
sports: actualSports.isEmpty ? sports : actualSports
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user