-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Refactor FXIOS-15120 [Translations] Make leading page actions generic and decouple from ToolbarActions #33859
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -157,11 +157,11 @@ struct ToolbarState: ScreenState, Sendable { | |
| ToolbarActionType.animationStateChanged, ToolbarActionType.translucencyDidChange, | ||
| ToolbarActionType.scrollAlphaNeedsUpdate, ToolbarActionType.readerModeStateChanged, | ||
| ToolbarActionType.navigationMiddleButtonDidChange, | ||
| ToolbarActionType.didStartTranslatingPage, | ||
| ToolbarActionType.translationCompleted, | ||
| ToolbarActionType.receivedTranslationLanguage, | ||
| ToolbarActionType.didReceiveErrorTranslating, | ||
| ToolbarActionType.didTranslationSettingsChange, | ||
| TranslationsActionType.didStartTranslatingPage, | ||
| TranslationsActionType.translationCompleted, | ||
| TranslationsActionType.receivedTranslationLanguage, | ||
| TranslationsActionType.didReceiveErrorTranslating, | ||
| TranslationsActionType.didTranslationSettingsChange, | ||
| ToolbarActionType.didSummarizeSettingsChange: | ||
| return handleToolbarUpdates(state: state, action: action) | ||
|
|
||
|
|
@@ -234,27 +234,32 @@ struct ToolbarState: ScreenState, Sendable { | |
|
|
||
| @MainActor | ||
| private static func handleToolbarUpdates(state: Self, action: Action) -> ToolbarState { | ||
| guard let toolbarAction = action as? ToolbarAction else { return defaultState(from: state) } | ||
| // Both `ToolbarAction` (lifecycle) and `TranslationsAction` (translation events) reach this | ||
| // handler — translation actions carry only `isTranslationsEnabled` + payload, so every other | ||
| // ToolbarAction-only field falls back to state when the action is not a `ToolbarAction`. | ||
| let toolbarAction = action as? ToolbarAction | ||
|
Comment on lines
+237
to
+240
Collaborator
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. Thanks for context 👍 |
||
| let translationsAction = action as? TranslationsAction | ||
| let actionIsTranslationsEnabled = toolbarAction?.isTranslationsEnabled ?? translationsAction?.isTranslationsEnabled | ||
|
|
||
| return ToolbarState( | ||
| windowUUID: state.windowUUID, | ||
| toolbarPosition: state.toolbarPosition, | ||
| toolbarLayout: state.toolbarLayout, | ||
| tabTrayButtonStyle: state.tabTrayButtonStyle, | ||
| isPrivateMode: toolbarAction.isPrivate ?? state.isPrivateMode, | ||
| addressToolbar: AddressBarState.reducer(state.addressToolbar, toolbarAction), | ||
| navigationToolbar: NavigationBarState.reducer(state.navigationToolbar, toolbarAction), | ||
| isShowingNavigationToolbar: toolbarAction.isShowingNavigationToolbar ?? state.isShowingNavigationToolbar, | ||
| isShowingTopTabs: toolbarAction.isShowingTopTabs ?? state.isShowingTopTabs, | ||
| canGoBack: toolbarAction.canGoBack ?? state.canGoBack, | ||
| canGoForward: toolbarAction.canGoForward ?? state.canGoForward, | ||
| isPrivateMode: toolbarAction?.isPrivate ?? state.isPrivateMode, | ||
| addressToolbar: AddressBarState.reducer(state.addressToolbar, action), | ||
| navigationToolbar: NavigationBarState.reducer(state.navigationToolbar, action), | ||
| isShowingNavigationToolbar: toolbarAction?.isShowingNavigationToolbar ?? state.isShowingNavigationToolbar, | ||
| isShowingTopTabs: toolbarAction?.isShowingTopTabs ?? state.isShowingTopTabs, | ||
| canGoBack: toolbarAction?.canGoBack ?? state.canGoBack, | ||
| canGoForward: toolbarAction?.canGoForward ?? state.canGoForward, | ||
| numberOfTabs: state.numberOfTabs, | ||
| scrollAlpha: toolbarAction.scrollAlpha ?? state.scrollAlpha, | ||
| scrollAlpha: toolbarAction?.scrollAlpha ?? state.scrollAlpha, | ||
| showMenuWarningBadge: state.showMenuWarningBadge, | ||
| canShowNavigationHint: state.canShowNavigationHint, | ||
| shouldAnimate: toolbarAction.shouldAnimate ?? state.shouldAnimate, | ||
| isTranslucent: toolbarAction.isTranslucent ?? state.isTranslucent, | ||
| isTranslationsEnabled: toolbarAction.isTranslationsEnabled ?? state.isTranslationsEnabled, | ||
| shouldAnimate: toolbarAction?.shouldAnimate ?? state.shouldAnimate, | ||
| isTranslucent: toolbarAction?.isTranslucent ?? state.isTranslucent, | ||
| isTranslationsEnabled: actionIsTranslationsEnabled ?? state.isTranslationsEnabled, | ||
| previousTabScreenshot: state.previousTabScreenshot, | ||
| nextTabScreenshot: state.nextTabScreenshot | ||
| ) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -87,13 +87,23 @@ struct TranslationSettingsState: ScreenState, Equatable { | |
| guard action.windowUUID == .unavailable || action.windowUUID == state.windowUUID else { | ||
| return defaultState(from: state) | ||
| } | ||
| if let action = action as? TranslationSettingsMiddlewareAction { | ||
|
|
||
| switch action { | ||
| case let action as TranslationSettingsMiddlewareAction: | ||
| return reduceMiddlewareAction(state: state, action: action) | ||
| } | ||
| if let action = action as? TranslationSettingsViewAction { | ||
|
|
||
| case let action as TranslationSettingsViewAction: | ||
| return reduceViewAction(state: state, action: action) | ||
|
|
||
| case let action as TranslationsAction | ||
| where action.actionType as? TranslationsActionType == .didTranslationSettingsChange: | ||
| return state.copyWithUpdates( | ||
| isTranslationsEnabled: action.isTranslationsEnabled ?? state.isTranslationsEnabled | ||
| ) | ||
|
|
||
| default: | ||
| return defaultState(from: state) | ||
| } | ||
|
Collaborator
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. Now that this reducer is supporting so many different action types, what do you think about writing it like this? 🤔 Alternatively, we could switch over the actionType instead, like the ToolbarAction reducer. Just a thought...!
Collaborator
Author
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. Restructured the logic from chained |
||
| return defaultState(from: state) | ||
| } | ||
|
|
||
| private static func reduceMiddlewareAction( | ||
|
|
||
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.
Should this be specialized to a
ToolbarAction? Or does this method really handle other action types? If it's the latter, in my opinion we should have a guard at the top of the method that clarifies the valid action types.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.
Added
guard action is ToolbarAction || action is TranslationsAction else { return actions }at the top to explicitly document and enforce the valid action types handled by this path.