diff --git a/Passepartout/Library/Sources/AppUIMain/Views/Provider/VPNProviderServerView.swift b/Passepartout/Library/Sources/AppUIMain/Views/Provider/VPNProviderServerView.swift index 2e93a874..aa8d1b38 100644 --- a/Passepartout/Library/Sources/AppUIMain/Views/Provider/VPNProviderServerView.swift +++ b/Passepartout/Library/Sources/AppUIMain/Views/Provider/VPNProviderServerView.swift @@ -75,7 +75,7 @@ extension VPNProviderServerView { apis: apis, moduleId: moduleId, providerId: providerId, - selectedServerId: selectedEntity?.server.id, + selectedServer: selectedEntity?.server, initialFilters: { guard let selectedEntity, filtersWithSelection else { return nil @@ -117,7 +117,7 @@ extension VPNProviderServerView { let providerId: ProviderID - let selectedServerId: String? + let selectedServer: VPNServer? let initialFilters: VPNFilters? @@ -144,7 +144,7 @@ extension VPNProviderServerView { debugChanges() return ServersSubview( servers: filteredServers, - selectedServerId: selectedServerId, + selectedServer: selectedServer, isFiltering: isFiltering, filtersViewModel: filtersViewModel, favoritesManager: favoritesManager, diff --git a/Passepartout/Library/Sources/AppUIMain/Views/Provider/iOS/VPNProviderServerView+iOS.swift b/Passepartout/Library/Sources/AppUIMain/Views/Provider/iOS/VPNProviderServerView+iOS.swift index 03839d51..96d22717 100644 --- a/Passepartout/Library/Sources/AppUIMain/Views/Provider/iOS/VPNProviderServerView+iOS.swift +++ b/Passepartout/Library/Sources/AppUIMain/Views/Provider/iOS/VPNProviderServerView+iOS.swift @@ -95,7 +95,7 @@ extension VPNProviderServerView { struct ServersSubview: View { let servers: [VPNServer] - let selectedServerId: String? + let selectedServer: VPNServer? let isFiltering: Bool @@ -109,6 +109,9 @@ extension VPNProviderServerView { let onSelect: (VPNServer) -> Void + @State + private var expandedCodes: Set = [] + var body: some View { debugChanges() return listView @@ -138,6 +141,11 @@ private extension VPNProviderServerView.ServersSubview { .themeSection( header: filtersViewModel.filters.categoryName ?? Strings.Providers.Vpn.Category.any ) + .onLoad { + if let selectedServer { + expandedCodes.insert(selectedServer.provider.countryCode) + } + } } } @@ -153,6 +161,18 @@ private extension VPNProviderServerView.ServersSubview { .map(\.code) } + func isExpandedCountry(_ code: String) -> Binding { + Binding { + expandedCodes.contains(code) + } set: { + if $0 { + expandedCodes.insert(code) + } else { + expandedCodes.remove(code) + } + } + } + func countryServers(for code: String) -> [VPNServer]? { servers .filter { @@ -164,7 +184,7 @@ private extension VPNProviderServerView.ServersSubview { func countryView(for code: String) -> some View { countryServers(for: code) .map { servers in - DisclosureGroup { + DisclosureGroup(isExpanded: isExpandedCountry(code)) { ForEach(servers, id: \.id, content: serverView) } label: { ThemeCountryText(code) @@ -178,7 +198,7 @@ private extension VPNProviderServerView.ServersSubview { } label: { HStack { ThemeImage(.marked) - .opaque(server.id == selectedServerId) + .opaque(server.id == selectedServer?.id) VStack(alignment: .leading) { if let area = server.provider.area { Text(area) diff --git a/Passepartout/Library/Sources/AppUIMain/Views/Provider/macOS/VPNProviderServerView+macOS.swift b/Passepartout/Library/Sources/AppUIMain/Views/Provider/macOS/VPNProviderServerView+macOS.swift index e793f7aa..2cd5e917 100644 --- a/Passepartout/Library/Sources/AppUIMain/Views/Provider/macOS/VPNProviderServerView+macOS.swift +++ b/Passepartout/Library/Sources/AppUIMain/Views/Provider/macOS/VPNProviderServerView+macOS.swift @@ -46,7 +46,7 @@ extension VPNProviderServerView { struct ServersSubview: View { let servers: [VPNServer] - let selectedServerId: String? + let selectedServer: VPNServer? let isFiltering: Bool @@ -68,7 +68,7 @@ extension VPNProviderServerView { return Table(servers) { TableColumn("") { server in ThemeImage(.marked) - .opaque(server.id == selectedServerId) + .opaque(server.id == selectedServer?.id) } .width(10.0)