Skip to content

Commit

Permalink
Refactor FXIOS-7301 [Swiftlint] Remove 1 closure_body_length violatio…
Browse files Browse the repository at this point in the history
…n from MainMenuDetailState.swift and decrease threshold (#24100)

* Decrease warning and error threshold
* Remove closure body violation from MainMenuDetailState.swift
  • Loading branch information
ionixjunior authored Jan 14, 2025
1 parent 54ac8d4 commit 2d8fe7b
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 56 deletions.
4 changes: 2 additions & 2 deletions .swiftlint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ line_length:
ignores_interpolated_strings: true

closure_body_length:
warning: 68
error: 68
warning: 64
error: 64

file_header:
required_string: |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,40 +82,9 @@ struct MainMenuDetailsState: ScreenState, Equatable {

switch action.actionType {
case ScreenActionType.showScreen:
guard let screenAction = action as? ScreenAction,
screenAction.screen == .mainMenuDetails,
let menuState = store.state.screenState(
MainMenuState.self,
for: .mainMenu,
window: action.windowUUID),
let currentTabInfo = menuState.currentTabInfo,
let currentSubmenu = menuState.currentSubmenuView
// let toolbarState = store.state.screenState(
// ToolbarState.self,
// for: .toolbar,
// window: action.windowUUID),
// let readerModeState = toolbarState.addressToolbar.readerModeState
else { return defaultState(from: state) }

return MainMenuDetailsState(
windowUUID: state.windowUUID,
menuElements: state.menuConfigurator.generateMenuElements(
with: currentTabInfo,
for: currentSubmenu,
and: action.windowUUID,
readerState: nil
),
submenuType: currentSubmenu,
isHomepage: state.isHomepage
)
return handleShowScreenAction(action: action, state: state)
case MainMenuDetailsActionType.tapBackToMainMenu:
return MainMenuDetailsState(
windowUUID: state.windowUUID,
menuElements: state.menuElements,
submenuType: state.submenuType,
isHomepage: state.isHomepage,
shouldGoBackToMenu: true
)
return handleTapBackToMainMenuAction(state: state)
case MainMenuDetailsActionType.tapDismissView,
MainMenuDetailsActionType.tapAddToBookmarks,
MainMenuDetailsActionType.tapAddToShortcuts,
Expand All @@ -124,34 +93,85 @@ struct MainMenuDetailsState: ScreenState, Equatable {
MainMenuDetailsActionType.tapRemoveFromReadingList,
MainMenuDetailsActionType.tapToggleNightMode,
GeneralBrowserActionType.showReaderMode:
return MainMenuDetailsState(
windowUUID: state.windowUUID,
menuElements: state.menuElements,
submenuType: state.submenuType,
isHomepage: state.isHomepage,
shouldDismiss: true
)
return handleDismissableAction(state: state)
case MainMenuDetailsActionType.tapEditBookmark:
return MainMenuDetailsState(
windowUUID: state.windowUUID,
menuElements: state.menuElements,
submenuType: state.submenuType,
isHomepage: state.isHomepage,
navigationDestination: MenuNavigationDestination(.editBookmark)
)
return handleTapEditBookmarkAction(state: state)
case MainMenuDetailsActionType.tapZoom:
return MainMenuDetailsState(
windowUUID: state.windowUUID,
menuElements: state.menuElements,
submenuType: state.submenuType,
isHomepage: state.isHomepage,
navigationDestination: MenuNavigationDestination(.zoom)
)
return handleTapZoomAction(state: state)
default:
return defaultState(from: state)
}
}

private static func handleShowScreenAction(action: Action, state: Self) -> MainMenuDetailsState {
guard let screenAction = action as? ScreenAction,
screenAction.screen == .mainMenuDetails,
let menuState = store.state.screenState(
MainMenuState.self,
for: .mainMenu,
window: action.windowUUID),
let currentTabInfo = menuState.currentTabInfo,
let currentSubmenu = menuState.currentSubmenuView
// let toolbarState = store.state.screenState(
// ToolbarState.self,
// for: .toolbar,
// window: action.windowUUID),
// let readerModeState = toolbarState.addressToolbar.readerModeState
else { return defaultState(from: state) }

return MainMenuDetailsState(
windowUUID: state.windowUUID,
menuElements: state.menuConfigurator.generateMenuElements(
with: currentTabInfo,
for: currentSubmenu,
and: action.windowUUID,
readerState: nil
),
submenuType: currentSubmenu,
isHomepage: state.isHomepage
)
}

private static func handleTapBackToMainMenuAction(state: Self) -> MainMenuDetailsState {
return MainMenuDetailsState(
windowUUID: state.windowUUID,
menuElements: state.menuElements,
submenuType: state.submenuType,
isHomepage: state.isHomepage,
shouldGoBackToMenu: true
)
}

private static func handleDismissableAction(state: Self) -> MainMenuDetailsState {
return MainMenuDetailsState(
windowUUID: state.windowUUID,
menuElements: state.menuElements,
submenuType: state.submenuType,
isHomepage: state.isHomepage,
shouldDismiss: true
)
}

private static func handleTapEditBookmarkAction(state: Self) -> MainMenuDetailsState {
return MainMenuDetailsState(
windowUUID: state.windowUUID,
menuElements: state.menuElements,
submenuType: state.submenuType,
isHomepage: state.isHomepage,
navigationDestination: MenuNavigationDestination(.editBookmark)
)
}

private static func handleTapZoomAction(state: Self) -> MainMenuDetailsState {
return MainMenuDetailsState(
windowUUID: state.windowUUID,
menuElements: state.menuElements,
submenuType: state.submenuType,
isHomepage: state.isHomepage,
navigationDestination: MenuNavigationDestination(.zoom)
)
}

static func defaultState(from state: MainMenuDetailsState) -> MainMenuDetailsState {
return MainMenuDetailsState(
windowUUID: state.windowUUID,
Expand Down

0 comments on commit 2d8fe7b

Please sign in to comment.