From 354ae4c527b476023eb6ebd03f1c7dd94546102f Mon Sep 17 00:00:00 2001 From: Raz Date: Mon, 30 Dec 2024 08:22:08 +0100 Subject: [PATCH] wip --- .../Screen/InscriptionManagerView.swift | 31 ++++++++++++++++--- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/PadelClub/Views/Tournament/Screen/InscriptionManagerView.swift b/PadelClub/Views/Tournament/Screen/InscriptionManagerView.swift index cce49ef..02ac5fd 100644 --- a/PadelClub/Views/Tournament/Screen/InscriptionManagerView.swift +++ b/PadelClub/Views/Tournament/Screen/InscriptionManagerView.swift @@ -483,9 +483,9 @@ struct InscriptionManagerView: View { // } // if let teamPaste = teamPaste(.championship) { -// ShareLink(item: teamPaste) { -// Text("En csv pour la ligue") -// } + ShareLink(item: teamPaste(.championship)) { + Text("En csv pour la ligue") + } // } } label: { Label("Exporter les paires", systemImage: "square.and.arrow.up") @@ -500,8 +500,8 @@ struct InscriptionManagerView: View { tournament.unsortedTeamsWithoutWO() } - func teamPaste(_ exportFormat: ExportFormat = .rawText) -> URL? { - tournament.pasteDataForImporting(exportFormat).createFile(self.tournament.tournamentTitle(.short), exportFormat) + func teamPaste(_ exportFormat: ExportFormat = .rawText) -> TournamentShareFile { + TournamentShareFile(tournament: tournament, exportFormat: exportFormat) } var unsortedPlayers: [PlayerRegistration] { @@ -1208,3 +1208,24 @@ struct InscriptionManagerView: View { // .environment(Tournament.mock()) // } //} + + +struct TournamentShareFile: Transferable { + let tournament: Tournament + let exportFormat: ExportFormat + + func shareFile() -> URL { + print("Generating URL...") + return tournament.pasteDataForImporting(exportFormat).createFile(self.tournament.tournamentTitle()+"-inscriptions", exportFormat) + } + + static var transferRepresentation: some TransferRepresentation { + FileRepresentation(exportedContentType: .utf8PlainText) { transferable in + return SentTransferredFile(transferable.shareFile()) + } + + ProxyRepresentation { transferable in + return transferable.shareFile() + } + } +}