-
Notifications
You must be signed in to change notification settings - Fork 1
add-to-calendar and the ticketing #54
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
durualayli
wants to merge
2
commits into
main
Choose a base branch
from
Duru/calendar-and-ticketing
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+154
−54
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| // | ||
| // CalendarViewModel.swift | ||
| // score-ios | ||
| // | ||
| // Created by Duru Alayli on 2/11/26. | ||
| // | ||
|
|
||
| import EventKit | ||
| import Foundation | ||
| import UIKit | ||
|
|
||
| final class CalendarViewModel: ObservableObject{ | ||
| static let shared = CalendarViewModel() | ||
| private let eventStore = EKEventStore() | ||
| @Published var showAlert: Bool = false | ||
| @Published var openSettings: Bool = false | ||
| @Published var alertTitle: String = "" | ||
| @Published var alertMessage: String = "" | ||
|
|
||
| private init() {} | ||
|
|
||
| func requestAccessandAdd(event: Game) { | ||
| eventStore.requestFullAccessToEvents{ [weak self] (granted, error) in | ||
| guard let self = self else { return } | ||
| if granted && error == nil { | ||
|
|
||
| let title = "Cornell vs. \(event.opponent.name) \(event.sex) \(event.sport)" | ||
| let existing = self.eventStore.predicateForEvents( | ||
| withStart: event.date, | ||
| end: event.date.addingTimeInterval(7200), | ||
| calendars: [self.eventStore.defaultCalendarForNewEvents].compactMap { $0 } | ||
| ) | ||
| let existingEvents = self.eventStore.events(matching: existing) | ||
|
|
||
| if existingEvents.contains(where: { $0.title == title && $0.startDate == event.date }) { | ||
| DispatchQueue.main.async { | ||
| self.alertTitle = "Game already added." | ||
| self.alertMessage = "This game is already added to your calendar." | ||
| self.showAlert = true | ||
| } | ||
| return | ||
| } | ||
|
|
||
| let calendarEvent = EKEvent(eventStore: self.eventStore) | ||
| calendarEvent.title = title | ||
| calendarEvent.startDate = event.date | ||
| calendarEvent.endDate = event.date.addingTimeInterval(7200) | ||
| calendarEvent.location = event.address | ||
| calendarEvent.calendar = self.eventStore.defaultCalendarForNewEvents | ||
|
|
||
| do { | ||
| try eventStore.save(calendarEvent, span: .thisEvent) | ||
| DispatchQueue.main.async { | ||
| if let url = URL(string: "calshow:\(event.date.timeIntervalSinceReferenceDate)") { | ||
| UIApplication.shared.open(url) | ||
| } | ||
| } | ||
| } catch { | ||
| DispatchQueue.main.async { | ||
| self.alertTitle = "Game can't be added." | ||
| self.alertMessage = "There was an error adding Cornell vs. \(event.opponent.name) to your calendar." | ||
| self.showAlert = true | ||
| } | ||
| } | ||
| } else { | ||
| DispatchQueue.main.async { | ||
| self.alertTitle = "Game can't be added." | ||
| self.alertMessage = "Calendar access denied. Please enable full calendar access in Settings." | ||
| self.showAlert = true | ||
| self.openSettings = true | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,6 +10,7 @@ import SwiftUI | |
| struct GameView : View { | ||
| var game : Game | ||
| @ObservedObject var viewModel: PastGameViewModel | ||
| @ObservedObject var calendarViewModel = CalendarViewModel.shared | ||
| @State var viewState: Int = 0 | ||
| @State var dayFromNow: Int = 0 | ||
| @State var hourFromNow: Int = 0 | ||
|
|
@@ -119,14 +120,14 @@ extension GameView { | |
| Text("\(game.sex.description) \(game.sport.description)") | ||
| .font(Constants.Fonts.subheader) | ||
| .foregroundStyle(Constants.Colors.black) | ||
|
|
||
| ScrollView(.horizontal, showsIndicators: false){ | ||
| Text("Cornell vs. " + game.opponent.name.removingUniversityPrefix()) | ||
| .font(Constants.Fonts.header) | ||
| .foregroundStyle(Constants.Colors.black) | ||
| } | ||
| .withTrailingFadeGradient() | ||
|
|
||
| HStack(spacing: 10) { | ||
| HStack { | ||
| Image("Location-g") | ||
|
|
@@ -176,25 +177,50 @@ extension GameView { | |
| .padding(.top, 8) | ||
| } | ||
| .padding(.top, 20) | ||
|
|
||
| // Ticketing Link Button | ||
| if let link = game.ticketLink, | ||
| let url = URL(string: link) { | ||
| HStack (spacing: 16){ | ||
| // Ticketing Link Button | ||
| if let link = game.ticketLink, | ||
| let url = URL(string: link) { | ||
| Button(action: { | ||
| UIApplication.shared.open(url) | ||
| }) { | ||
| HStack (spacing: 9){ | ||
| Image("Ticket") | ||
| .resizable() | ||
| .frame(width: 22, height: 22) | ||
| Text("Buy Tickets") | ||
| .foregroundStyle(Constants.Colors.white) | ||
| .font(.system(size: 16, weight: .medium)) | ||
| .font(Constants.Fonts.buttonLabel) | ||
| } | ||
| .foregroundColor(.white) | ||
| .padding(12) | ||
| .background( | ||
| Constants.Colors.primary_red | ||
| ) | ||
| .overlay( | ||
| RoundedRectangle(cornerRadius: 30) | ||
| .stroke(Color.black.opacity(0.1), lineWidth: 1) | ||
| .shadow(color: Color.black.opacity(0.25), radius: 5, x: 0, y: 2) | ||
| ) | ||
| .clipShape(RoundedRectangle(cornerRadius: 30)) | ||
| } | ||
| } | ||
|
|
||
| // Calendar Button | ||
| Button(action: { | ||
| UIApplication.shared.open(url) | ||
| calendarViewModel.requestAccessandAdd(event:game) | ||
| }) { | ||
| HStack { | ||
| Image("Ticket") | ||
| HStack (spacing: 8){ | ||
| Image("Calendar") | ||
| .resizable() | ||
| .frame(width: 25, height: 25) | ||
| Text("Buy Tickets") | ||
| .foregroundStyle(Constants.Colors.white) | ||
| .font(.system(size: 16, weight: .medium)) | ||
| .frame(width: 24, height: 24) | ||
| Text("Add to Calendar") | ||
| .font(Constants.Fonts.buttonLabel) | ||
| .foregroundStyle(Constants.Colors.white) | ||
| } | ||
| .foregroundColor(.white) | ||
| .padding(.horizontal, 20) | ||
| .padding(.vertical, 15) | ||
| .padding(12) | ||
| .background( | ||
| Constants.Colors.primary_red | ||
| ) | ||
|
|
@@ -203,41 +229,34 @@ extension GameView { | |
| .stroke(Color.black.opacity(0.1), lineWidth: 1) | ||
| .shadow(color: Color.black.opacity(0.25), radius: 5, x: 0, y: 2) | ||
| ) | ||
| .clipShape(RoundedRectangle(cornerRadius: 30)) // Clip to shape to ensure rounded corners | ||
| .clipShape(RoundedRectangle(cornerRadius: 30)) | ||
| } | ||
| .alert(isPresented: $calendarViewModel.showAlert) { | ||
| if calendarViewModel.openSettings { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You should abstract this large block away into a function, rather than directly attaching it to the view. |
||
| Alert( | ||
| title: Text(calendarViewModel.alertTitle), | ||
| message: Text(calendarViewModel.alertMessage), | ||
| primaryButton: .default(Text("Go to settings")) { | ||
| if let url = URL(string: UIApplication.openSettingsURLString) { | ||
| UIApplication.shared.open(url) | ||
| } | ||
| }, | ||
| secondaryButton: .cancel() | ||
| ) | ||
| } | ||
| else { | ||
| Alert( | ||
| title: Text(calendarViewModel.alertTitle), | ||
| message: Text(calendarViewModel.alertMessage) | ||
| ) | ||
| } | ||
| } | ||
| .padding(.top, 80) | ||
| } | ||
|
|
||
| // Calendar Button | ||
| // TODO: make this back when we have login | ||
| // Button(action: { | ||
| // // TODO: action | ||
| // }) { | ||
| // HStack { | ||
| // Image("Calendar") | ||
| // .resizable() | ||
| // .frame(width: 24, height: 24) | ||
| // Text("Add to Calendar") | ||
| // .font(Constants.Fonts.buttonLabel) | ||
| // .foregroundStyle(Constants.Colors.white) | ||
| // } | ||
| // .foregroundColor(.white) | ||
| // .padding(.horizontal, 16) | ||
| // .padding(.vertical, 10) | ||
| // .background( | ||
| // Constants.Colors.primary_red | ||
| // ) | ||
| // .overlay( | ||
| // RoundedRectangle(cornerRadius: 30) | ||
| // .stroke(Color.black.opacity(0.1), lineWidth: 1) | ||
| // .shadow(color: Color.black.opacity(0.25), radius: 5, x: 0, y: 2) | ||
| // ) | ||
| // .clipShape(RoundedRectangle(cornerRadius: 30)) // Clip to shape to ensure rounded corners | ||
| // } | ||
| // .padding(.top, 68) | ||
| // } | ||
| .padding(.top, 80) | ||
| } | ||
|
|
||
| } | ||
|
|
||
|
|
||
| private var summaryTab: some View { | ||
| NavigationLink(destination: ScoringSummary(game: game)) { | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
weird diff lol
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no action needed though as far as I can tell