Skip to content

Commit

Permalink
Bugfix FXIOS-8364 [v123] Add confirmation dialog (#18581)
Browse files Browse the repository at this point in the history
* Add confirmation dialog

* Fix swiftlint
  • Loading branch information
OrlaM authored Feb 7, 2024
1 parent 0fbe36c commit e7dae22
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ enum TabPanelAction: Action {
case closeTab(TabUUIDContext)
case undoClose(ActionContext)
case closeAllTabs(ActionContext)
case confirmCloseAllTabs(ActionContext)
case undoCloseAllTabs(ActionContext)
case moveTab(MoveTabContext)
case toggleInactiveTabs(ActionContext)
Expand All @@ -122,6 +123,7 @@ enum TabPanelAction: Action {
.closeTab(let context as ActionContext),
.undoClose(let context),
.closeAllTabs(let context),
.confirmCloseAllTabs(let context),
.undoCloseAllTabs(let context),
.moveTab(let context as ActionContext),
.toggleInactiveTabs(let context),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class TabManagerMiddleware {
case TabPanelAction.undoClose:
self.undoCloseTab(state: state, uuid: uuid)

case TabPanelAction.closeAllTabs:
case TabPanelAction.confirmCloseAllTabs:
self.closeAllTabs(state: state, uuid: uuid)

case TabPanelAction.undoCloseAllTabs:
Expand Down
23 changes: 19 additions & 4 deletions firefox-ios/Client/Frontend/Browser/Tabs/State/TabTrayState.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ struct TabTrayState: ScreenState, Equatable {
var shouldDismiss: Bool
var shareURL: URL?
var windowUUID: WindowUUID
var showCloseConfirmation: Bool

var navigationTitle: String {
return selectedPanel.navTitle
Expand All @@ -42,7 +43,8 @@ struct TabTrayState: ScreenState, Equatable {
normalTabsCount: panelState.normalTabsCount,
hasSyncableAccount: panelState.hasSyncableAccount,
shouldDismiss: panelState.shouldDismiss,
shareURL: panelState.shareURL)
shareURL: panelState.shareURL,
showCloseConfirmation: panelState.showCloseConfirmation)
}

init(windowUUID: WindowUUID) {
Expand All @@ -68,14 +70,16 @@ struct TabTrayState: ScreenState, Equatable {
normalTabsCount: String,
hasSyncableAccount: Bool,
shouldDismiss: Bool = false,
shareURL: URL? = nil) {
shareURL: URL? = nil,
showCloseConfirmation: Bool = false) {
self.windowUUID = windowUUID
self.isPrivateMode = isPrivateMode
self.selectedPanel = selectedPanel
self.normalTabsCount = normalTabsCount
self.hasSyncableAccount = hasSyncableAccount
self.shouldDismiss = shouldDismiss
self.shareURL = shareURL
self.showCloseConfirmation = showCloseConfirmation
}

static let reducer: Reducer<Self> = { state, action in
Expand Down Expand Up @@ -134,14 +138,25 @@ struct TabTrayState: ScreenState, Equatable {
// Only update the nomal tab count if the tabs being refreshed are not private
let tabModel = context.tabDisplayModel
let isPrivate = tabModel.tabs.first?.isPrivate ?? false
let tabCount = tabModel.normalTabsCount
let tabCount = isPrivate ? state.normalTabsCount : tabModel.normalTabsCount
return TabTrayState(windowUUID: state.windowUUID,
isPrivateMode: state.isPrivateMode,
selectedPanel: state.selectedPanel,
normalTabsCount: tabCount,
hasSyncableAccount: state.hasSyncableAccount)
case TabPanelAction.closeAllTabs(let context):
return TabTrayState(windowUUID: state.windowUUID,
isPrivateMode: state.isPrivateMode,
selectedPanel: state.selectedPanel,
normalTabsCount: state.normalTabsCount,
hasSyncableAccount: state.hasSyncableAccount,
showCloseConfirmation: true)
default:
return state
return TabTrayState(windowUUID: state.windowUUID,
isPrivateMode: state.isPrivateMode,
selectedPanel: state.selectedPanel,
normalTabsCount: state.normalTabsCount,
hasSyncableAccount: state.hasSyncableAccount)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,12 @@ struct TabsPanelState: ScreenState, Equatable {
tabs: state.tabs,
inactiveTabs: state.inactiveTabs,
isInactiveTabsExpanded: state.isInactiveTabsExpanded)
default: return TabsPanelState(windowUUID: state.windowUUID,
isPrivateMode: state.isPrivateMode,
tabs: state.tabs,
inactiveTabs: state.inactiveTabs,
isInactiveTabsExpanded: state.isInactiveTabsExpanded)
default:
return TabsPanelState(windowUUID: state.windowUUID,
isPrivateMode: state.isPrivateMode,
tabs: state.tabs,
inactiveTabs: state.inactiveTabs,
isInactiveTabsExpanded: state.isInactiveTabsExpanded)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,9 @@ class TabTrayViewController: UIViewController,
if let url = tabTrayState.shareURL {
navigationHandler?.shareTab(url: url, sourceView: self.view)
}
if tabTrayState.showCloseConfirmation {
showCloseAllConfirmation()
}
}

func updateTabCountImage(count: String) {
Expand Down Expand Up @@ -460,6 +463,24 @@ class TabTrayViewController: UIViewController,
store.dispatch(TabPanelAction.closeAllTabs(windowUUID.context))
}

private func showCloseAllConfirmation() {
let controller = AlertController(title: nil, message: nil, preferredStyle: .actionSheet)
controller.addAction(UIAlertAction(title: .AppMenu.AppMenuCloseAllTabsTitleString,
style: .default,
handler: { _ in self.confirmCloseAll() }),
accessibilityIdentifier: AccessibilityIdentifiers.TabTray.deleteCloseAllButton)
controller.addAction(UIAlertAction(title: .TabTrayCloseAllTabsPromptCancel,
style: .cancel,
handler: nil),
accessibilityIdentifier: AccessibilityIdentifiers.TabTray.deleteCancelButton)
controller.popoverPresentationController?.barButtonItem = deleteButton
present(controller, animated: true, completion: nil)
}

private func confirmCloseAll() {
store.dispatch(TabPanelAction.confirmCloseAllTabs(windowUUID.context))
}

@objc
private func newTabButtonTapped() {
let context = AddNewTabContext(urlRequest: nil, isPrivate: tabTrayState.isPrivateMode, windowUUID: windowUUID)
Expand Down

0 comments on commit e7dae22

Please sign in to comment.