Files
iOS/Sources/App/WebView/ConnectionErrorDetailsView.swift
Bruno Pantaleão Gonçalves b3aa00a406 Add URL to error screen and improve UI in dark mode (#3349)
<!-- Thank you for submitting a Pull Request and helping to improve Home
Assistant. Please complete the following sections to help the processing
and review of your changes. Please do not delete anything from this
template. -->

## Summary
<!-- Provide a brief summary of the changes you have made and most
importantly what they aim to achieve -->

## Screenshots
<!-- If this is a user-facing change not in the frontend, please include
screenshots in light and dark mode. -->
![CleanShot 2025-01-21 at 21 32
22@2x](https://github.com/user-attachments/assets/a42b28fe-2125-429c-88fb-7453f41773f2)

## Link to pull request in Documentation repository
<!-- Pull requests that add, change or remove functionality must have a
corresponding pull request in the Companion App Documentation repository
(https://github.com/home-assistant/companion.home-assistant). Please add
the number of this pull request after the "#" -->
Documentation: home-assistant/companion.home-assistant#

## Any other notes
<!-- If there is any other information of note, like if this Pull
Request is part of a bigger change, please include it here. -->
2025-01-21 21:16:10 +00:00

93 lines
3.1 KiB
Swift

import SFSafeSymbols
import Shared
import SwiftUI
struct ConnectionErrorDetailsView: View {
@Environment(\.dismiss) private var dismiss
let error: Error
var body: some View {
ScrollView {
VStack(alignment: .leading) {
HStack {
SheetCloseButton {
dismiss()
}
.frame(maxWidth: .infinity, alignment: .trailing)
}
Text(L10n.Connection.Error.Details.title)
.font(.title.bold())
VStack(alignment: .leading, spacing: Spaces.two) {
makeRow(title: L10n.Connection.Error.Details.Label.description, body: error.localizedDescription)
makeRow(title: L10n.Connection.Error.Details.Label.domain, body: (error as NSError).domain)
makeRow(title: L10n.Connection.Error.Details.Label.code, body: "\((error as NSError).code)")
if let urlError = error as? URLError {
makeRow(title: L10n.urlLabel, body: urlError.failingURL?.absoluteString ?? "")
}
}
.padding(.vertical)
documentationLink
discordLink
githubLink
}
.padding()
}
}
private func makeRow(title: String, body: String) -> some View {
VStack(alignment: .leading) {
Text(title)
.font(.headline.bold())
Text(body)
.textSelection(.enabled)
}
}
private var documentationLink: some View {
ExternalLinkButton(
icon: Image(systemSymbol: .docTextFill),
title: L10n.Connection.Error.Details.Button.doc,
url: ExternalLink.companionAppDocs,
tint: .init(uiColor: Asset.Colors.haPrimary.color)
)
}
private var discordLink: some View {
ExternalLinkButton(
icon: Image("discord.fill"),
title: L10n.Connection.Error.Details.Button.discord,
url: ExternalLink.discord,
tint: .purple
)
}
@ViewBuilder
private var githubLink: some View {
ExternalLinkButton(
icon: Image("github.fill"),
title: L10n.Connection.Error.Details.Button.github,
url: ExternalLink.githubReportIssue,
tint: .init(uiColor: .init(dynamicProvider: { trait in
trait.userInterfaceStyle == .dark ? .white : .black
}))
)
if let searchURL = ExternalLink.githubSearchIssue(domain: (error as NSError).domain) {
ExternalLinkButton(
icon: Image("github.fill"),
title: L10n.Connection.Error.Details.Button.searchGithub,
url: searchURL,
tint: .init(uiColor: .init(dynamicProvider: { trait in
trait.userInterfaceStyle == .dark ? .white : .black
}))
)
}
}
}
#Preview {
ConnectionErrorDetailsView(error: SomeError.some)
}
enum SomeError: Error {
case some
}