From 2d8fe7b072f31ecbfe22edceb63cb42e4e2f1afb Mon Sep 17 00:00:00 2001 From: Ione Souza Junior Date: Tue, 14 Jan 2025 11:13:20 -0300 Subject: [PATCH] Refactor FXIOS-7301 [Swiftlint] Remove 1 closure_body_length violation from MainMenuDetailState.swift and decrease threshold (#24100) * Decrease warning and error threshold * Remove closure body violation from MainMenuDetailState.swift --- .swiftlint.yml | 4 +- .../MainMenu/Redux/MainMenuDetailState.swift | 128 ++++++++++-------- 2 files changed, 76 insertions(+), 56 deletions(-) diff --git a/.swiftlint.yml b/.swiftlint.yml index 7bdcc4d32d91..92e874d0e960 100644 --- a/.swiftlint.yml +++ b/.swiftlint.yml @@ -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: | diff --git a/firefox-ios/Client/Frontend/Browser/MainMenu/Redux/MainMenuDetailState.swift b/firefox-ios/Client/Frontend/Browser/MainMenu/Redux/MainMenuDetailState.swift index cdfc3c906fdf..c867f7773d55 100644 --- a/firefox-ios/Client/Frontend/Browser/MainMenu/Redux/MainMenuDetailState.swift +++ b/firefox-ios/Client/Frontend/Browser/MainMenu/Redux/MainMenuDetailState.swift @@ -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, @@ -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,