fix issue with ios 26

add onboarding view
fix bugs
sync3
Razmig Sarkissian 2 months ago
parent f1d21b71ee
commit d45adf1937
  1. 5
      PadelClubData/Data/AppSettings.swift
  2. 16
      PadelClubData/Data/GroupStage.swift
  3. 5
      PadelClubData/Data/MatchScheduler.swift
  4. 26
      PadelClubData/Data/Tournament.swift
  5. 35
      PadelClubData/Extensions/Date+Extensions.swift

@ -29,6 +29,7 @@ final public class AppSettings: MicroStorable {
public var nationalCup: Bool public var nationalCup: Bool
public var dayDuration: Int? public var dayDuration: Int?
public var dayPeriod: DayPeriod public var dayPeriod: DayPeriod
public var weekdays: Set<Int>
public func lastDataSourceDate() -> Date? { public func lastDataSourceDate() -> Date? {
guard let lastDataSource else { return nil } guard let lastDataSource else { return nil }
@ -55,6 +56,7 @@ final public class AppSettings: MicroStorable {
nationalCup = false nationalCup = false
dayDuration = nil dayDuration = nil
dayPeriod = .all dayPeriod = .all
weekdays = Set()
} }
public required init() { public required init() {
@ -70,6 +72,7 @@ final public class AppSettings: MicroStorable {
nationalCup = false nationalCup = false
dayDuration = nil dayDuration = nil
dayPeriod = .all dayPeriod = .all
weekdays = Set()
} }
public required init(from decoder: Decoder) throws { public required init(from decoder: Decoder) throws {
@ -89,6 +92,7 @@ final public class AppSettings: MicroStorable {
nationalCup = try container.decodeIfPresent(Bool.self, forKey: ._nationalCup) ?? false nationalCup = try container.decodeIfPresent(Bool.self, forKey: ._nationalCup) ?? false
dayDuration = try container.decodeIfPresent(Int.self, forKey: ._dayDuration) dayDuration = try container.decodeIfPresent(Int.self, forKey: ._dayDuration)
dayPeriod = try container.decodeIfPresent(DayPeriod.self, forKey: ._dayPeriod) ?? .all dayPeriod = try container.decodeIfPresent(DayPeriod.self, forKey: ._dayPeriod) ?? .all
weekdays = try container.decodeIfPresent(Set<Int>.self, forKey: ._weekdays) ?? Set()
} }
enum CodingKeys: String, CodingKey { enum CodingKeys: String, CodingKey {
@ -107,5 +111,6 @@ final public class AppSettings: MicroStorable {
case _nationalCup = "nationalCup" case _nationalCup = "nationalCup"
case _dayDuration = "dayDuration" case _dayDuration = "dayDuration"
case _dayPeriod = "dayPeriod" case _dayPeriod = "dayPeriod"
case _weekdays = "weekdays"
} }
} }

@ -298,7 +298,7 @@ final public class GroupStage: BaseGroupStage, SideStorable {
return playedMatches.filter({ $0.isRunning() }).sorted(by: \.computedStartDateForSorting) return playedMatches.filter({ $0.isRunning() }).sorted(by: \.computedStartDateForSorting)
} }
public func readyMatches(playedMatches: [Match]) -> [Match] { public func readyMatches(playedMatches: [Match], runningMatches: [Match]) -> [Match] {
#if _DEBUG_TIME //DEBUGING TIME #if _DEBUG_TIME //DEBUGING TIME
let start = Date() let start = Date()
defer { defer {
@ -306,7 +306,9 @@ final public class GroupStage: BaseGroupStage, SideStorable {
print("func group stage readyMatches", id, duration.formatted(.units(allowed: [.seconds, .milliseconds]))) print("func group stage readyMatches", id, duration.formatted(.units(allowed: [.seconds, .milliseconds])))
} }
#endif #endif
return playedMatches.filter({ $0.isReady() && $0.isRunning() == false && $0.hasEnded() == false }) let playingTeams = runningMatches.flatMap({ $0.teams() }).map({ $0.id })
return playedMatches.filter({ $0.isReady() && $0.isRunning() == false && $0.hasEnded() == false && $0.containsTeamIds(playingTeams) == false })
} }
public func finishedMatches(playedMatches: [Match]) -> [Match] { public func finishedMatches(playedMatches: [Match]) -> [Match] {
@ -616,6 +618,16 @@ final public class GroupStage: BaseGroupStage, SideStorable {
public func computedStartDate() -> Date? { public func computedStartDate() -> Date? {
return _matches().sorted(by: \.computedStartDateForSorting).first?.startDate return _matches().sorted(by: \.computedStartDateForSorting).first?.startDate
} }
public func removeAllTeams() {
let teams = teams()
teams.forEach { team in
team.groupStagePosition = nil
team.groupStage = nil
self._matches().forEach({ $0.updateTeamScores() })
}
tournamentStore?.teamRegistrations.addOrUpdate(contentOfs: teams)
}
public override func deleteDependencies(store: Store, shouldBeSynchronized: Bool) { public override func deleteDependencies(store: Store, shouldBeSynchronized: Bool) {

@ -896,6 +896,11 @@ extension Match {
return teamIds().contains(id) return teamIds().contains(id)
} }
public func containsTeamIds(_ ids: [String]) -> Bool {
let teamIds = teamIds()
return !Set(ids).isDisjoint(with: teamIds)
}
public func containsTeamIndex(_ id: String) -> Bool { public func containsTeamIndex(_ id: String) -> Bool {
matchUp().contains(id) matchUp().contains(id)
} }

@ -88,6 +88,25 @@ final public class Tournament: BaseTournament {
return self.tournamentStore?.teamRegistrations.count ?? 0 return self.tournamentStore?.teamRegistrations.count ?? 0
} }
public func deleteGroupStage(_ groupStage: GroupStage) {
groupStage.removeAllTeams()
let index = groupStage.index
self.tournamentStore?.groupStages.delete(instance: groupStage)
self.groupStageCount -= 1
let groupStages = self.groupStages()
groupStages.filter({ $0.index > index }).forEach { gs in
gs.index -= 1
}
self.tournamentStore?.groupStages.addOrUpdate(contentOfs: groupStages)
}
public func addGroupStage() {
let groupStage = GroupStage(tournament: id, index: groupStageCount, size: teamsPerGroupStage, format: groupStageFormat)
self.tournamentStore?.groupStages.addOrUpdate(instance: groupStage)
groupStage.buildMatches(keepExistingMatches: false)
self.groupStageCount += 1
}
public func groupStages(atStep step: Int = 0) -> [GroupStage] { public func groupStages(atStep step: Int = 0) -> [GroupStage] {
guard let tournamentStore = self.tournamentStore else { return [] } guard let tournamentStore = self.tournamentStore else { return [] }
let groupStages: [GroupStage] = tournamentStore.groupStages.filter { $0.tournament == self.id && $0.step == step } let groupStages: [GroupStage] = tournamentStore.groupStages.filter { $0.tournament == self.id && $0.step == step }
@ -856,7 +875,7 @@ defer {
return allMatches.filter({ $0.isRunning() && $0.isReady() }).sorted(using: defaultSorting, order: .ascending) return allMatches.filter({ $0.isRunning() && $0.isReady() }).sorted(using: defaultSorting, order: .ascending)
} }
public static func readyMatches(_ allMatches: [Match]) -> [Match] { public static func readyMatches(_ allMatches: [Match], runningMatches: [Match]) -> [Match] {
#if _DEBUG_TIME //DEBUGING TIME #if _DEBUG_TIME //DEBUGING TIME
let start = Date() let start = Date()
defer { defer {
@ -864,7 +883,10 @@ defer {
print("func tournament readyMatches", id, duration.formatted(.units(allowed: [.seconds, .milliseconds]))) print("func tournament readyMatches", id, duration.formatted(.units(allowed: [.seconds, .milliseconds])))
} }
#endif #endif
return allMatches.filter({ $0.isReady() && $0.isRunning() == false && $0.hasEnded() == false }).sorted(using: defaultSorting, order: .ascending)
let playingTeams = runningMatches.flatMap({ $0.teams() }).map({ $0.id })
return allMatches.filter({ $0.isReady() && $0.isRunning() == false && $0.hasEnded() == false && $0.containsTeamIds(playingTeams) == false }).sorted(using: defaultSorting, order: .ascending)
} }
public static func matchesLeft(_ allMatches: [Match]) -> [Match] { public static func matchesLeft(_ allMatches: [Match]) -> [Match] {

@ -118,6 +118,14 @@ public extension Date {
} }
} }
var nextDay: Date {
return Calendar.current.date(byAdding: .day, value: 1, to: self)!
}
var weekDay: Int {
Calendar.current.component(.weekday, from: self)
}
func atBeginningOfDay(hourInt: Int = 9) -> Date { func atBeginningOfDay(hourInt: Int = 9) -> Date {
Calendar.current.date(byAdding: .hour, value: hourInt, to: self.startOfDay)! Calendar.current.date(byAdding: .hour, value: hourInt, to: self.startOfDay)!
} }
@ -144,6 +152,28 @@ public extension Date {
return weekdays.map { $0.capitalized } return weekdays.map { $0.capitalized }
}() }()
static var weekdays: [String] = {
let calendar = Calendar.current
// let weekdays = calendar.shortWeekdaySymbols
// return weekdays.map { weekday in
// guard let firstLetter = weekday.first else { return "" }
// return String(firstLetter).capitalized
// }
// Adjusted for the different weekday starts
var weekdays = calendar.weekdaySymbols
if firstDayOfWeek > 1 {
for _ in 1..<firstDayOfWeek {
if let first = weekdays.first {
weekdays.append(first)
weekdays.removeFirst()
}
}
}
return weekdays.map { $0.capitalized }
}()
static var fullMonthNames: [String] = { static var fullMonthNames: [String] = {
let dateFormatter = DateFormatter() let dateFormatter = DateFormatter()
dateFormatter.locale = Locale.current dateFormatter.locale = Locale.current
@ -164,6 +194,11 @@ public extension Date {
return Calendar.current.date(byAdding: .day, value: -1, to: lastDay)! return Calendar.current.date(byAdding: .day, value: -1, to: lastDay)!
} }
var endOfWeek: Date {
let lastDay = Calendar.current.dateInterval(of: .weekOfMonth, for: self)!.end
return Calendar.current.date(byAdding: .day, value: -1, to: lastDay)!
}
var startOfPreviousMonth: Date { var startOfPreviousMonth: Date {
let dayInPreviousMonth = Calendar.current.date(byAdding: .month, value: -1, to: self)! let dayInPreviousMonth = Calendar.current.date(byAdding: .month, value: -1, to: self)!
return dayInPreviousMonth.startOfMonth return dayInPreviousMonth.startOfMonth

Loading…
Cancel
Save