Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions AirCasting/SessionViews/SessionHeaderView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,15 @@ struct SessionHeaderView: View {
@Environment(\.colorScheme) var colorScheme
@ObservedObject var session: SessionEntity
@State private var showingNoConnectionAlert = false
@State private var alert: AlertInfo?
@InjectedObject private var featureFlagsViewModel: FeatureFlagsViewModel
@State var showDeleteModal = false
@State var showAddNoteModal = false
@State var showShareModal = false
@State var showEditView = false
@State var detectEmailSent = false
@State var showThresholdAlertModal = false
@State private var isShowingFinishSessionAlert = false
@State private var isShowingEmailSentAlert = false

var body: some View {
if #available(iOS 15, *) {
Expand All @@ -50,7 +51,7 @@ struct SessionHeaderView: View {
}
})).onDisappear(perform: {
if detectEmailSent {
alert = InAppAlerts.shareFileRequestSent()
isShowingEmailSentAlert = true
}
})
}
Expand Down Expand Up @@ -81,7 +82,7 @@ struct SessionHeaderView: View {
ShareSessionView(viewModel: DefaultShareSessionViewModel(session: session, apiClient: ShareSessionApi(), exitRoute: { result in
showShareModal.toggle()
if result == .fileShared {
alert = InAppAlerts.shareFileRequestSent()
isShowingEmailSentAlert = true
}
}))
}
Expand Down Expand Up @@ -132,7 +133,14 @@ private extension SessionHeaderView {
}
nameLabelAndExpandButton
}
.alert(item: $alert, content: { $0.makeAlert() })
.alert(
InAppAlerts.finishSessionAlert(
sessionName: session.name,
action: { self.finishSessionAlertAction() }
),
$isShowingFinishSessionAlert
)
.alert(InAppAlerts.shareFileRequestSent(), $isShowingEmailSentAlert)
.foregroundColor(.aircastingGray)
}

Expand Down Expand Up @@ -193,9 +201,7 @@ private extension SessionHeaderView {

var actionsMenuStopButton: some View {
Button {
alert = InAppAlerts.finishSessionAlert(sessionName: session.name, action: {
self.finishSessionAlertAction()
})
isShowingFinishSessionAlert = true
} label: {
Label(Strings.SessionHeaderView.stopRecordingButton, systemImage: "stop.circle")
}
Expand Down
16 changes: 16 additions & 0 deletions AirCasting/Utils/InAppAlerts.swift
Original file line number Diff line number Diff line change
Expand Up @@ -474,3 +474,19 @@ extension AlertInfo {
}
}
}

extension View {
nonisolated func alert(_ alertInfo: AlertInfo, _ isPresented: Binding<Bool>) -> some View {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fancy 💅

self.alert(alertInfo.title, isPresented: isPresented) {
ForEach(Array(alertInfo.buttons.enumerated()), id: \.offset) { index, type in
switch type {
case .cancel(let title): Button(title, role: .cancel, action: { isPresented.wrappedValue = false })
case .default(let title, nil): Button(title, action: { isPresented.wrappedValue = false })
case .default(let title, let action): Button(title, action: action!)
}
}
} message: {
Text(alertInfo.message)
}
}
}
Loading