Skip to content

Commit

Permalink
fix: Close stats email after sending
Browse files Browse the repository at this point in the history
  • Loading branch information
mvirgo committed Mar 12, 2024
1 parent 43ac7ab commit 60fc505
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
6 changes: 4 additions & 2 deletions foam-madness/Mail/MailHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import MessageUI

class MailHandler: NSObject, MFMailComposeViewControllerDelegate {
static let shared = MailHandler()

func sendTournamentStatsEmail(tournamentName: String, exportGames: [String: [String: String]]) {
// Export all games in the tournament to JSON
// Thanks https://stackoverflow.com/questions/28325268/convert-array-to-json-string-in-swift
Expand All @@ -19,7 +21,7 @@ class MailHandler: NSObject, MFMailComposeViewControllerDelegate {
if MFMailComposeViewController.canSendMail() {
let viewController = UIApplication.shared.windows.first!.rootViewController!
let composeVC = MFMailComposeViewController()
composeVC.mailComposeDelegate = self
composeVC.mailComposeDelegate = MailHandler.shared

// Configure the fields of the interface.
composeVC.addAttachmentData(jsonExport, mimeType: "application/json", fileName: "\(tournamentName)-export.json")
Expand All @@ -46,6 +48,6 @@ class MailHandler: NSObject, MFMailComposeViewControllerDelegate {
}

func mailComposeController(_ controller: MFMailComposeViewController, didFinishWith result: MFMailComposeResult, error: Error?) {
controller.dismiss(animated: true, completion: nil)
controller.dismiss(animated: true)
}
}
3 changes: 1 addition & 2 deletions foam-madness/View/Tournament/TournamentStatsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,7 @@ struct TournamentStatsView: View {
let key = singleGame.keys.first!
exportGames[key] = singleGame[key]
}
let mailer = MailHandler()
mailer.sendTournamentStatsEmail(
MailHandler.shared.sendTournamentStatsEmail(
tournamentName: tournament.name ?? "",
exportGames: exportGames
)
Expand Down

0 comments on commit 60fc505

Please sign in to comment.