From 46032d767b66efbad251d8e5917b0c64e46efe06 Mon Sep 17 00:00:00 2001 From: Raz Date: Thu, 26 Sep 2024 09:41:49 +0200 Subject: [PATCH] fix finishing tournament when only groupstages --- PadelClub/Data/GroupStage.swift | 9 +++++++ PadelClub/Data/Tournament.swift | 7 +++++ PadelClub/Views/Club/ClubSearchView.swift | 2 +- .../Navigation/Toolbox/ToolboxView.swift | 27 ++++++++++++++++++- 4 files changed, 43 insertions(+), 2 deletions(-) diff --git a/PadelClub/Data/GroupStage.swift b/PadelClub/Data/GroupStage.swift index 32e07b2..f99aa95 100644 --- a/PadelClub/Data/GroupStage.swift +++ b/PadelClub/Data/GroupStage.swift @@ -145,6 +145,15 @@ final class GroupStage: ModelObject, Storable { } catch { Logger.error(error) } + + if tournament.groupStagesAreOver(), tournament.groupStageLoserBracketAreOver(), tournament.rounds().isEmpty { + tournament.endDate = Date() + do { + try DataStore.shared.tournaments.addOrUpdate(instance: tournament) + } catch { + Logger.error(error) + } + } } } diff --git a/PadelClub/Data/Tournament.swift b/PadelClub/Data/Tournament.swift index bff7b30..7ef451e 100644 --- a/PadelClub/Data/Tournament.swift +++ b/PadelClub/Data/Tournament.swift @@ -1484,6 +1484,13 @@ defer { //return qualifiedTeams().count == qualifiedFromGroupStage() + groupStageAdditionalQualified } + func groupStageLoserBracketAreOver() -> Bool { + guard let groupStageLoserBracket = groupStageLoserBracket() else { + return true + } + return groupStageLoserBracket.hasEnded() + } + fileprivate func _paymentMethodMessage() -> String? { return DataStore.shared.user.summonsAvailablePaymentMethods ?? ContactType.defaultAvailablePaymentMethods } diff --git a/PadelClub/Views/Club/ClubSearchView.swift b/PadelClub/Views/Club/ClubSearchView.swift index fc022f1..9c5378c 100644 --- a/PadelClub/Views/Club/ClubSearchView.swift +++ b/PadelClub/Views/Club/ClubSearchView.swift @@ -385,7 +385,7 @@ struct ClubSearchView: View { LabeledContent { Text(club.distance(from: locationManager.location)) } label: { - Text(club.nom) + Text(club.nom).lineLimit(1) Text(club.ville).font(.caption) } } diff --git a/PadelClub/Views/Navigation/Toolbox/ToolboxView.swift b/PadelClub/Views/Navigation/Toolbox/ToolboxView.swift index f0d9198..0a19da3 100644 --- a/PadelClub/Views/Navigation/Toolbox/ToolboxView.swift +++ b/PadelClub/Views/Navigation/Toolbox/ToolboxView.swift @@ -7,6 +7,7 @@ import SwiftUI import LeStorage +import Zip struct ToolboxView: View { @EnvironmentObject var dataStore: DataStore @@ -210,14 +211,38 @@ struct ToolboxView: View { } .navigationTitle(TabDestination.toolbox.title) .toolbar { - ToolbarItem(placement: .topBarTrailing) { + ToolbarItem(placement: .topBarLeading) { Link(destination: URLs.appStore.url) { Text("v\(PadelClubApp.appVersion)") } } + ToolbarItem(placement: .topBarTrailing) { + Menu { + ShareLink(item: URLs.appStore.url) { + Label("Lien AppStore", systemImage: "link") + } + if let zip = _getZip() { + ShareLink(item: zip) { + Label("Mes données", systemImage: "server.rack") + } + } + } label: { + Label("Partagez", systemImage: "square.and.arrow.up").labelStyle(.iconOnly) + } + } } } } + + private func _getZip() -> URL? { + do { + let filePath = try Club.storageDirectoryPath() + return try Zip.quickZipFiles([filePath], fileName: "backup") // Zip + } catch { + Logger.error(error) + return nil + } + } } //#Preview {