Consider text length in endpoint rows (#336)

This commit is contained in:
Davide De Rosa 2023-07-23 15:17:28 +02:00 committed by GitHub
parent 38cca79683
commit 65d6e30469
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 26 additions and 16 deletions

View File

@ -115,12 +115,6 @@ private extension EndpointView.OpenVPNView {
} }
} }
private extension Endpoint {
var linearDescription: String {
"\(address)\(proto.rawValue)"
}
}
// MARK: - // MARK: -
private extension EndpointView.OpenVPNView { private extension EndpointView.OpenVPNView {
@ -148,7 +142,7 @@ private extension EndpointView.OpenVPNView {
var endpointsSection: some View { var endpointsSection: some View {
Section { Section {
ForEach(builder.remotes ?? []) { endpoint in ForEach(builder.remotes ?? []) { endpoint in
fullRowForEndpoint(endpoint) rowForEndpoint(endpoint)
.swipeActions(edge: .trailing, allowsFullSwipe: false) { .swipeActions(edge: .trailing, allowsFullSwipe: false) {
actions(forEndpoint: endpoint) actions(forEndpoint: endpoint)
} }
@ -157,13 +151,13 @@ private extension EndpointView.OpenVPNView {
} }
} }
func fullRowForEndpoint(_ endpoint: Endpoint) -> some View { func rowForEndpoint(_ endpoint: Endpoint) -> some View {
Button { Button {
withAnimation { withAnimation {
currentProfile.value.customEndpoint = endpoint currentProfile.value.customEndpoint = endpoint
} }
} label: { } label: {
Text(endpoint.linearDescription) labelForEndpoint(endpoint)
}.sheet(item: $editedEndpoint) { endpoint in }.sheet(item: $editedEndpoint) { endpoint in
NavigationView { NavigationView {
EndpointView.AddView(L10n.Global.Strings.edit, endpoint: endpoint, onSave: commitEndpoint) EndpointView.AddView(L10n.Global.Strings.edit, endpoint: endpoint, onSave: commitEndpoint)
@ -171,6 +165,15 @@ private extension EndpointView.OpenVPNView {
}.withTrailingCheckmark(when: currentProfile.value.customEndpoint == endpoint) }.withTrailingCheckmark(when: currentProfile.value.customEndpoint == endpoint)
} }
func labelForEndpoint(_ endpoint: Endpoint) -> some View {
VStack {
Text(endpoint.address)
.frame(maxWidth: .infinity, alignment: .leading)
Text(endpoint.proto.rawValue)
.frame(maxWidth: .infinity, alignment: .leading)
}
}
@ViewBuilder @ViewBuilder
func actions(forEndpoint endpoint: Endpoint) -> some View { func actions(forEndpoint endpoint: Endpoint) -> some View {
if !isConfigurationReadonly { if !isConfigurationReadonly {
@ -255,31 +258,38 @@ private extension EndpointView.OpenVPNView {
private extension EndpointView.OpenVPNView { private extension EndpointView.OpenVPNView {
var groupedEndpointsSections: some View { var groupedEndpointsSections: some View {
ForEach(endpointsByAddress, content: endpointsGroup(forSection:)) ForEach(endpointsByAddress, content: group(forEndpointsSection:))
.disabled(isAutomatic) .disabled(isAutomatic)
} }
func endpointsGroup(forSection section: EndpointsByAddress) -> some View { func group(forEndpointsSection section: EndpointsByAddress) -> some View {
Section { Section {
DisclosureGroup(isExpanded: isExpandedBinding(address: section.address)) { DisclosureGroup(isExpanded: isExpandedBinding(address: section.address)) {
ForEach(section.endpoints, content: groupedRowForEndpoint) ForEach(section.endpoints, content: rowForEndpointProtocol)
} label: { } label: {
Text(L10n.Global.Strings.address) labelForEndpointAddress(section.address)
.withTrailingText(section.address)
} }
} }
} }
func groupedRowForEndpoint(_ endpoint: Endpoint) -> some View { func labelForEndpointAddress(_ address: String) -> some View {
Text(address)
}
func rowForEndpointProtocol(_ endpoint: Endpoint) -> some View {
Button { Button {
withAnimation { withAnimation {
currentProfile.value.customEndpoint = endpoint currentProfile.value.customEndpoint = endpoint
} }
} label: { } label: {
Text(endpoint.proto.rawValue) labelForEndpointProtocol(endpoint.proto)
}.withTrailingCheckmark(when: currentProfile.value.customEndpoint == endpoint) }.withTrailingCheckmark(when: currentProfile.value.customEndpoint == endpoint)
} }
func labelForEndpointProtocol(_ proto: EndpointProtocol) -> some View {
Text(proto.rawValue)
}
var endpointsByAddress: [EndpointsByAddress] { var endpointsByAddress: [EndpointsByAddress] {
guard let remotes = builder.remotes, !remotes.isEmpty else { guard let remotes = builder.remotes, !remotes.isEmpty else {
return [] return []