Skip to content

Commit

Permalink
review(brandon): nit fix
Browse files Browse the repository at this point in the history
  • Loading branch information
nuo-xu committed Dec 20, 2024
1 parent 896577f commit a8d8569
Showing 1 changed file with 8 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import SwiftUI
public struct BraveVPNRegionListView: View {

@State
private var isAutomatic: Bool
private var isAutomaticRegion: Bool = false

@State
private var isLoading = false
Expand All @@ -21,7 +21,7 @@ public struct BraveVPNRegionListView: View {

@State
private var isShowingChangeRegionAlert = false

@State
private var allRegions: [GRDRegion] = []

Expand All @@ -42,7 +42,6 @@ public struct BraveVPNRegionListView: View {
public init(
onServerRegionSet: ((_ region: GRDRegion?) -> Void)?
) {
self.isAutomatic = BraveVPN.isAutomaticRegion
self.onServerRegionSet = onServerRegionSet
}

Expand All @@ -56,7 +55,7 @@ public struct BraveVPNRegionListView: View {
automaticRegionToggle
}

if !isAutomatic {
if !isAutomaticRegion {
Section {
ForEach(Array(allRegions.enumerated()), id: \.offset) {
index,
Expand Down Expand Up @@ -84,7 +83,7 @@ public struct BraveVPNRegionListView: View {
}
.onAppear {
Task { @MainActor in
isAutomatic = BraveVPN.isAutomaticRegion
isAutomaticRegion = BraveVPN.isAutomaticRegion
allRegions = await BraveVPN.fetchRegionData() ?? []
}
}
Expand Down Expand Up @@ -169,14 +168,14 @@ public struct BraveVPNRegionListView: View {
private var automaticRegionToggle: some View {
Toggle(
isOn: Binding(
get: { isAutomatic },
get: { isAutomaticRegion },
set: { enableAutomaticServer($0) }
)
) {
VStack(alignment: .leading) {
Text(Strings.VPN.automaticServerSelectionToggleTitle)
.font(.body)
if isAutomatic, let regionAutomaticName = BraveVPN.lastKnownRegion?.displayName {
if isAutomaticRegion, let regionAutomaticName = BraveVPN.lastKnownRegion?.displayName {
Text(regionAutomaticName)
.font(.footnote)
.foregroundStyle(Color(braveSystemName: .textSecondary))
Expand Down Expand Up @@ -207,9 +206,9 @@ public struct BraveVPNRegionListView: View {
}

private func enableAutomaticServer(_ enabled: Bool) {
isAutomatic = enabled
isAutomaticRegion = enabled

guard isAutomatic else {
guard isAutomaticRegion else {
let autoRegion = BraveVPN.allRegions.first(where: {
$0.countryISOCode == BraveVPN.lastKnownRegion?.countryISOCode
})
Expand Down

0 comments on commit a8d8569

Please sign in to comment.