Files
iOS/Sources/App/WebView/ConnectionErrorDetailsView.swift
Bruno Pantaleão Gonçalves bc5b9a4b83 Remove option to report error in github and add option to copy error to clipboard (#3351)
<!-- 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. -->

## 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-22 10:49:04 +01:00

109 lines
3.7 KiB
Swift

import SFSafeSymbols
import Shared
import SwiftUI
struct ConnectionErrorDetailsView: View {
@Environment(\.dismiss) private var dismiss
private let feedbackGenerator = UINotificationFeedbackGenerator()
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)
copyToClipboardButton
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 copyToClipboardButton: some View {
ActionLinkButton(
icon: Image(systemSymbol: .docOnDoc),
title: L10n.Connection.Error.Details.Button.clipboard,
tint: .init(uiColor: Asset.Colors.haPrimary.color)
) {
UIPasteboard.general
.string =
"""
\(L10n.Connection.Error.Details.Label.description): \n
\(error.localizedDescription) \n
\(L10n.Connection.Error.Details.Label.domain): \n
\((error as NSError).domain) \n
\(L10n.Connection.Error.Details.Label.code): \n
\((error as NSError).code) \n
\(L10n.urlLabel): \n
\((error as? URLError)?.failingURL?.absoluteString ?? "")
"""
feedbackGenerator.notificationOccurred(.success)
}
}
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 {
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
}