Skip to content
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

Refactor FXIOS-10613 [Homepage] Navigation Actions for BVCState #23964

Merged
merged 1 commit into from
Dec 30, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,12 @@ import Redux

/// Actions that are related to navigation from the user perspective
class NavigationBrowserAction: Action {
let url: URL?
let isGoogleTopSite: Bool?
let contextMenuConfiguration: ContextMenuConfiguration?
let navigationDestination: NavigationDestination

init(url: URL? = nil,
isGoogleTopSite: Bool? = nil,
contextMenuConfiguration: ContextMenuConfiguration? = nil,
init(navigationDestination: NavigationDestination,
windowUUID: WindowUUID,
actionType: ActionType) {
self.url = url
self.isGoogleTopSite = isGoogleTopSite
self.contextMenuConfiguration = contextMenuConfiguration
self.navigationDestination = navigationDestination
super.init(windowUUID: windowUUID,
actionType: actionType)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,54 +156,19 @@ struct BrowserViewControllerState: ScreenState, Equatable {
state: BrowserViewControllerState
) -> BrowserViewControllerState {
switch action.actionType {
case NavigationBrowserActionType.tapOnCustomizeHomepage:
case NavigationBrowserActionType.tapOnCustomizeHomepage,
NavigationBrowserActionType.tapOnTrackingProtection,
NavigationBrowserActionType.tapOnCell,
NavigationBrowserActionType.tapOnLink,
NavigationBrowserActionType.longPressOnCell:
return BrowserViewControllerState(
searchScreenState: state.searchScreenState,
showDataClearanceFlow: state.showDataClearanceFlow,
fakespotState: FakespotState.reducer(state.fakespotState, action),
windowUUID: state.windowUUID,
browserViewType: state.browserViewType,
microsurveyState: MicrosurveyPromptState.reducer(state.microsurveyState, action),
navigationDestination: NavigationDestination(.customizeHomepage)
)

case NavigationBrowserActionType.tapOnTrackingProtection:
return BrowserViewControllerState(
searchScreenState: state.searchScreenState,
showDataClearanceFlow: state.showDataClearanceFlow,
fakespotState: FakespotState.reducer(state.fakespotState, action),
windowUUID: state.windowUUID,
browserViewType: state.browserViewType,
microsurveyState: MicrosurveyPromptState.reducer(state.microsurveyState, action),
navigationDestination: NavigationDestination(.trackingProtectionSettings)
)

case NavigationBrowserActionType.tapOnCell,
NavigationBrowserActionType.tapOnLink:
return BrowserViewControllerState(
searchScreenState: state.searchScreenState,
showDataClearanceFlow: state.showDataClearanceFlow,
fakespotState: FakespotState.reducer(state.fakespotState, action),
windowUUID: state.windowUUID,
browserViewType: state.browserViewType,
microsurveyState: MicrosurveyPromptState.reducer(state.microsurveyState, action),
navigationDestination: NavigationDestination(
.link,
url: action.url,
isGoogleTopSite: action.isGoogleTopSite
)
)

case NavigationBrowserActionType.longPressOnCell:
return BrowserViewControllerState(
searchScreenState: state.searchScreenState,
showDataClearanceFlow: state.showDataClearanceFlow,
fakespotState: FakespotState.reducer(state.fakespotState, action),
windowUUID: state.windowUUID,
browserViewType: state.browserViewType,
microsurveyState: MicrosurveyPromptState.reducer(state.microsurveyState, action),
navigationDestination: NavigationDestination(.contextMenu,
contextMenuConfiguration: action.contextMenuConfiguration)
navigationDestination: action.navigationDestination
)

default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,7 @@ final class HomepageViewController: UIViewController,
private func navigateToHomepageSettings() {
store.dispatch(
NavigationBrowserAction(
navigationDestination: NavigationDestination(.customizeHomepage),
windowUUID: self.windowUUID,
actionType: NavigationBrowserActionType.tapOnCustomizeHomepage
)
Expand All @@ -499,7 +500,7 @@ final class HomepageViewController: UIViewController,
private func navigateToPocketLearnMore() {
store.dispatch(
NavigationBrowserAction(
url: homepageState.pocketState.footerURL,
navigationDestination: NavigationDestination(.link, url: homepageState.pocketState.footerURL),
windowUUID: self.windowUUID,
actionType: NavigationBrowserActionType.tapOnLink
)
Expand All @@ -510,7 +511,7 @@ final class HomepageViewController: UIViewController,
let configuration = ContextMenuConfiguration(homepageSection: section, item: item, sourceView: sourceView)
store.dispatch(
NavigationBrowserAction(
contextMenuConfiguration: configuration,
navigationDestination: NavigationDestination(.contextMenu, contextMenuConfiguration: configuration),
windowUUID: windowUUID,
actionType: NavigationBrowserActionType.longPressOnCell
)
Expand All @@ -531,24 +532,30 @@ final class HomepageViewController: UIViewController,
case .topSite(let state, _):
store.dispatch(
NavigationBrowserAction(
url: state.site.url.asURL,
isGoogleTopSite: state.isGoogleURL,
navigationDestination: NavigationDestination(
.link,
url: state.site.url.asURL,
isGoogleTopSite: state.isGoogleURL
),
windowUUID: self.windowUUID,
actionType: NavigationBrowserActionType.tapOnCell
)
)
case .pocket(let story):
store.dispatch(
NavigationBrowserAction(
url: story.url,
navigationDestination: NavigationDestination(.link, url: story.url),
windowUUID: self.windowUUID,
actionType: NavigationBrowserActionType.tapOnCell
)
)
case .pocketDiscover(let item):
store.dispatch(
NavigationBrowserAction(
url: item.url,
navigationDestination: NavigationDestination(
.link,
url: item.url
),
windowUUID: self.windowUUID,
actionType: NavigationBrowserActionType.tapOnCell
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,7 @@ class TrackingProtectionViewController: UIViewController,
private func showSettings() {
store.dispatch(
NavigationBrowserAction(
navigationDestination: NavigationDestination(.trackingProtectionSettings),
windowUUID: self.windowUUID,
actionType: NavigationBrowserActionType.tapOnTrackingProtection
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ final class BrowserViewControllerStateTests: XCTestCase {

XCTAssertNil(initialState.navigationDestination)

let action = getNavigationBrowserAction(for: .tapOnCustomizeHomepage)
let action = getNavigationBrowserAction(for: .tapOnCustomizeHomepage, destination: .customizeHomepage)
let newState = reducer(initialState, action)

XCTAssertEqual(newState.navigationDestination?.destination, .customizeHomepage)
Expand All @@ -108,7 +108,7 @@ final class BrowserViewControllerStateTests: XCTestCase {
XCTAssertNil(initialState.navigationDestination)

let url = try XCTUnwrap(URL(string: "www.example.com"))
let action = getNavigationBrowserAction(for: .tapOnCell, url: url)
let action = getNavigationBrowserAction(for: .tapOnCell, destination: .link, url: url)
let newState = reducer(initialState, action)

XCTAssertEqual(newState.navigationDestination?.destination, .link)
Expand All @@ -122,7 +122,7 @@ final class BrowserViewControllerStateTests: XCTestCase {
XCTAssertNil(initialState.navigationDestination)

let url = try XCTUnwrap(URL(string: "www.example.com"))
let action = getNavigationBrowserAction(for: .tapOnLink, url: url)
let action = getNavigationBrowserAction(for: .tapOnLink, destination: .link, url: url)
let newState = reducer(initialState, action)

XCTAssertEqual(newState.navigationDestination?.destination, .link)
Expand All @@ -144,10 +144,11 @@ final class BrowserViewControllerStateTests: XCTestCase {

private func getNavigationBrowserAction(
for actionType: NavigationBrowserActionType,
destination: BrowserNavigationDestination,
url: URL? = nil
) -> NavigationBrowserAction {
return NavigationBrowserAction(
url: url,
navigationDestination: NavigationDestination(destination, url: url),
windowUUID: .XCTestDefaultUUID,
actionType: actionType
)
Expand Down
Loading