-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor FXIOS-7817 [v122] Add BrowserViewControllerState (#17565)
* Lots of learning * Updates & cleanup * Remove things * Minor refactor lolololololol * Language and big brain fixes * PR comments --------- Co-authored-by: roux g. buciu <github@fringe.foundation> (cherry picked from commit 723d77f) # Conflicts: # Client.xcodeproj/project.pbxproj # Client/Frontend/FeltPrivacy/FeltPrivacyAction.swift # Client/Frontend/Home/HomepageViewController.swift # Client/Redux/GlobalState/ActiveScreenState.swift # Client/Redux/GlobalState/AppState.swift # Client/TabManagement/TabManager.swift
- Loading branch information
1 parent
c6265ac
commit e540032
Showing
13 changed files
with
245 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
Client/Frontend/FeltPrivacy/BrowserViewControllerState.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this | ||
// file, You can obtain one at http://mozilla.org/MPL/2.0/ | ||
|
||
import Foundation | ||
import Redux | ||
|
||
struct BrowserViewControllerState: ScreenState, Equatable { | ||
var feltPrivacyState: FeltPrivacyState | ||
var fakespotState: FakespotState | ||
|
||
init(_ appState: AppState) { | ||
guard let bvcState = store.state.screenState( | ||
BrowserViewControllerState.self, | ||
for: .browserViewController) | ||
else { | ||
self.init() | ||
return | ||
} | ||
|
||
self.init(feltPrivacyState: bvcState.feltPrivacyState, | ||
fakespotState: bvcState.fakespotState) | ||
} | ||
|
||
init() { | ||
self.init( | ||
feltPrivacyState: FeltPrivacyState(), | ||
fakespotState: FakespotState()) | ||
} | ||
|
||
init( | ||
feltPrivacyState: FeltPrivacyState, | ||
fakespotState: FakespotState | ||
) { | ||
self.feltPrivacyState = feltPrivacyState | ||
self.fakespotState = fakespotState | ||
} | ||
|
||
static let reducer: Reducer<Self> = { state, action in | ||
switch action { | ||
case FeltPrivacyAction.privateModeUpdated(let privacyState): | ||
return BrowserViewControllerState( | ||
feltPrivacyState: FeltPrivacyState.reducer(state.feltPrivacyState, action), | ||
fakespotState: state.fakespotState) | ||
case FakespotAction.toggleAppearance(let isEnabled): | ||
return BrowserViewControllerState( | ||
feltPrivacyState: state.feltPrivacyState, | ||
fakespotState: FakespotState.reducer(state.fakespotState, action)) | ||
default: | ||
return state | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this | ||
// file, You can obtain one at http://mozilla.org/MPL/2.0/ | ||
|
||
import Foundation | ||
import Redux | ||
|
||
enum FeltPrivacyAction: Action { | ||
// middleware actions | ||
case privateModeUpdated(Bool) | ||
|
||
// user actions | ||
case setPrivateModeTo(Bool) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this | ||
// file, You can obtain one at http://mozilla.org/MPL/2.0/ | ||
|
||
import Foundation | ||
|
||
protocol FeltPrivacyProtocol { | ||
func getPrivateModeState() -> Bool | ||
func setPrivateModeState(to state: Bool) | ||
} | ||
|
||
class FeltPrivacyManager { | ||
private var isInPrivateMode: Bool | ||
|
||
init(isInPrivateMode: Bool) { | ||
self.isInPrivateMode = isInPrivateMode | ||
} | ||
|
||
func getPrivateModeState() -> Bool { | ||
return isInPrivateMode | ||
} | ||
|
||
func setPrivateModeState(to newState: Bool) { | ||
isInPrivateMode = newState | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this | ||
// file, You can obtain one at http://mozilla.org/MPL/2.0/ | ||
|
||
import Foundation | ||
import Redux | ||
|
||
class FeltPrivacyMiddleware { | ||
var privacyManager: FeltPrivacyManager | ||
|
||
init(privacyManager: FeltPrivacyManager = FeltPrivacyManager(isInPrivateMode: false)) { | ||
self.privacyManager = privacyManager | ||
} | ||
|
||
lazy var privacyManagerProvider: Middleware<AppState> = { state, action in | ||
switch action { | ||
case FeltPrivacyAction.setPrivateModeTo(let privateState): | ||
self.updateManagerWith(newState: privateState) | ||
store.dispatch(FeltPrivacyAction.privateModeUpdated(self.privacyManager.getPrivateModeState())) | ||
default: | ||
break | ||
} | ||
} | ||
|
||
// MARK: - Helper Functions | ||
private func updateManagerWith(newState: Bool) { | ||
privacyManager.setPrivateModeState(to: newState) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this | ||
// file, You can obtain one at http://mozilla.org/MPL/2.0/ | ||
|
||
import Foundation | ||
import Redux | ||
|
||
struct FeltPrivacyState: ScreenState, Equatable { | ||
var shouldHideSearchSuggestionView: Bool | ||
|
||
init(_ appState: BrowserViewControllerState) { | ||
self.init(shouldHideSearchSuggestionView: appState.feltPrivacyState.shouldHideSearchSuggestionView) | ||
} | ||
|
||
init() { | ||
self.init(shouldHideSearchSuggestionView: false) | ||
} | ||
|
||
init(shouldHideSearchSuggestionView: Bool) { | ||
self.shouldHideSearchSuggestionView = shouldHideSearchSuggestionView | ||
} | ||
|
||
static let reducer: Reducer<Self> = { state, action in | ||
switch action { | ||
case FeltPrivacyAction.privateModeUpdated(let privacyState): | ||
return FeltPrivacyState(shouldHideSearchSuggestionView: privacyState) | ||
default: | ||
return state | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.