Add developer option for clearing the application cache (#852)

* Add developer option for clearing the application cache

* Tweaks following code review
This commit is contained in:
Stefan Ceriu
2023-05-05 19:41:21 +03:00
committed by GitHub
parent f679c0ca2a
commit 574424024c
10 changed files with 93 additions and 7 deletions
@@ -16,11 +16,23 @@
import SwiftUI
enum DeveloperOptionsScreenCoordinatorAction {
case clearCache
}
final class DeveloperOptionsScreenCoordinator: CoordinatorProtocol {
private let viewModel: DeveloperOptionsScreenViewModelProtocol
private var viewModel: DeveloperOptionsScreenViewModelProtocol
var callback: ((DeveloperOptionsScreenCoordinatorAction) -> Void)?
init() {
viewModel = DeveloperOptionsScreenViewModel()
viewModel.callback = { [weak self] action in
switch action {
case .clearCache:
self?.callback?(.clearCache)
}
}
}
func toPresentable() -> AnyView {
@@ -16,7 +16,9 @@
import Foundation
enum DeveloperOptionsScreenViewModelAction { }
enum DeveloperOptionsScreenViewModelAction {
case clearCache
}
struct DeveloperOptionsScreenViewState: BindableState {
var bindings: DeveloperOptionsScreenViewStateBindings
@@ -34,4 +36,5 @@ enum DeveloperOptionsScreenViewAction {
case changedStartChatFlowEnabled
case changedStartChatUserSuggestionsEnabled
case changedInvitesFlowEnabled
case clearCache
}
@@ -45,6 +45,8 @@ class DeveloperOptionsScreenViewModel: DeveloperOptionsScreenViewModelType, Deve
ServiceLocator.shared.settings.startChatUserSuggestionsEnabled = state.bindings.startChatUserSuggestionsEnabled
case .changedInvitesFlowEnabled:
ServiceLocator.shared.settings.invitesFlowEnabled = state.bindings.invitesFlowEnabled
case .clearCache:
callback?(.clearCache)
}
}
}
@@ -59,9 +59,16 @@ struct DeveloperOptionsScreen: View {
Text("🥳")
.frame(maxWidth: .infinity)
}
.buttonStyle(FormButtonStyle())
}
.formSectionStyle()
Section {
Button(role: .destructive) {
context.send(viewAction: .clearCache)
} label: {
Text("Clear cache")
.frame(maxWidth: .infinity)
}
}
}
.overlay(effectsView)
.scrollContentBackground(.hidden)
@@ -26,6 +26,7 @@ struct SettingsScreenCoordinatorParameters {
enum SettingsScreenCoordinatorAction {
case dismiss
case logout
case clearCache
}
final class SettingsScreenCoordinator: CoordinatorProtocol {
@@ -114,6 +115,14 @@ final class SettingsScreenCoordinator: CoordinatorProtocol {
private func presentDeveloperOptions() {
let coordinator = DeveloperOptionsScreenCoordinator()
coordinator.callback = { [weak self] action in
switch action {
case .clearCache:
self?.callback?(.clearCache)
}
}
parameters.navigationStackCoordinator?.push(coordinator)
}