This repository has been archived by the owner on May 10, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 442
/
ClearDataSectionView.swift
66 lines (59 loc) · 1.98 KB
/
ClearDataSectionView.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// Copyright 2023 The Brave Authors. All rights reserved.
// 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 SwiftUI
import DesignSystem
import BraveUI
import Strings
import Preferences
struct ClearDataSectionView: View {
@State private var showClearablesAlert = false
@ObservedObject var settings: AdvancedShieldsSettings
var body: some View {
Section {
ForEach($settings.clearableSettings) { $setting in
ShieldToggleView(
title: setting.clearable.label,
subtitle: nil,
toggle: $setting.isEnabled
)
}
clearPrivateDataButton
} header: {
Text(Strings.clearPrivateData)
}
}
private var clearPrivateDataButton: some View {
Button {
showClearablesAlert = true
} label: {
VStack(alignment: .center) {
Text(Strings.clearDataNow)
.foregroundColor(Color(.braveBlurpleTint))
}
}
.frame(maxWidth: .infinity)
.alert(isPresented: $showClearablesAlert, content: {
Alert(
title: Text(Strings.clearPrivateDataAlertTitle),
message: Text(Strings.clearPrivateDataAlertMessage),
primaryButton: .destructive(Text(Strings.clearPrivateDataAlertYesAction), action: {
clearPrivateData()
}),
secondaryButton: .cancel(Text(Strings.cancelButtonTitle))
)
})
.disabled(settings.clearableSettings.allSatisfy({ !$0.isEnabled }))
.listRowBackground(Color(.secondaryBraveGroupedBackground))
}
private func clearPrivateData() {
Preferences.Privacy.clearPrivateDataToggles.value = settings.clearableSettings.map({ $0.isEnabled })
Task { @MainActor in
await settings.clearPrivateData(settings.clearableSettings.compactMap({
guard $0.isEnabled else { return nil }
return $0.clearable
}))
}
}
}