Skip to content
This repository has been archived by the owner on May 10, 2024. It is now read-only.

Commit

Permalink
Fix success dialogue on submit webcompat report view
Browse files Browse the repository at this point in the history
  • Loading branch information
cuba committed Oct 3, 2023
1 parent 9a54de7 commit eb11432
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 89 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ import BraveWallet
import Preferences
import CertificateUtilities
import AVFoundation
import BraveVPN
import BraveShields

// MARK: - TopToolbarDelegate

Expand Down Expand Up @@ -528,34 +526,7 @@ extension BrowserViewController: TopToolbarDelegate {
guard let cleanedURL = components?.url else { return }

let viewController = UIHostingController(rootView: SubmitReportView(
url: cleanedURL,
submit: { [weak self] url, additionalDetails, contactInfo in
guard let self = self else { return }
let popover = PopoverController(
contentController: SubmitReportSuccessViewController(),
contentSizeBehavior: .preferredContentSize
)

let domain = Domain.getOrCreate(forUrl: url, persistent: !privateBrowsingManager.isPrivateBrowsing)

let report = WebcompatReporter.Report(
cleanedURL: url,
additionalDetails: additionalDetails,
contactInfo: contactInfo,
areShieldsEnabled: !domain.areAllShieldsOff,
adBlockLevel: domain.blockAdsAndTrackingLevel,
fingerprintProtectionLevel: domain.finterprintProtectionLevel,
adBlockListTitles: FilterListStorage.shared.filterLists.compactMap({ return $0.isEnabled ? $0.entry.title : nil }),
isVPNEnabled: BraveVPN.isConnected
)

popover.present(from: topToolbar.locationView.shieldsButton, on: self)

Task { [weak self] in
await WebcompatReporter.send(report: report)
self?.delayDismiss(popover: popover)
}
}
url: cleanedURL, isPrivateBrowsing: privateBrowsingManager.isPrivateBrowsing
))

viewController.modalPresentationStyle = .popover
Expand All @@ -574,13 +545,6 @@ extension BrowserViewController: TopToolbarDelegate {
}
navigationController?.present(viewController, animated: true)
}

private func delayDismiss(popover: PopoverController) {
Timer.scheduledTimer(withTimeInterval: 4, repeats: false) { _ in
guard !popover.isBeingDismissed else { return }
popover.dismissPopover()
}
}

// TODO: This logic should be fully abstracted away and share logic from current MenuViewController
// See: https://github.com/brave/brave-ios/issues/1452
Expand Down
50 changes: 8 additions & 42 deletions Sources/Brave/Frontend/Shields/SubmitReportSuccessView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,23 @@ import SnapKit

struct SubmitReportSuccessView: View {
var body: some View {
VStack(alignment: .leading) {
VStack(alignment: .center, spacing: 16) {
Image(braveSystemName: "leo.check.circle-outline")
.font(.title)
.foregroundStyle(Color(braveSystemName: .textTertiary))

Text(Strings.Shields.siteReportedTitle)
.multilineTextAlignment(.leading)
.multilineTextAlignment(.center)
.lineLimit(1)
.font(.title)
.foregroundStyle(Color(braveSystemName: .textTertiary))

Text(Strings.Shields.siteReportedBody)
.multilineTextAlignment(.leading)
.multilineTextAlignment(.center)
.lineLimit(3)
.foregroundStyle(Color(braveSystemName: .textTertiary))
}
.padding()
.background(Color(.braveBackground))
}
}

Expand All @@ -32,41 +36,3 @@ struct SubmitReportSuccessView: View {
SubmitReportSuccessView()
}
#endif

class SubmitReportSuccessViewController: UIViewController, PopoverContentComponent {
private lazy var hostingController: UIHostingController<SubmitReportSuccessView> = {
return UIHostingController(rootView: SubmitReportSuccessView())
}()

override func viewDidLoad() {
super.viewDidLoad()

if let swiftUIView = hostingController.view {
swiftUIView.translatesAutoresizingMaskIntoConstraints = false
addChild(hostingController)
view.addSubview(swiftUIView)

swiftUIView.snp.makeConstraints { make in
make.edges.equalToSuperview()
}

hostingController.didMove(toParent: self)
updatePreferredContentSize()
}
}

private func updatePreferredContentSize() {
let targetWidth = min(360, UIScreen.main.bounds.width - 20)

let height = self.view.systemLayoutSizeFitting(
CGSize(width: targetWidth, height: 0),
withHorizontalFittingPriority: .required,
verticalFittingPriority: .fittingSizeLevel
).height

preferredContentSize = CGSize(
width: targetWidth,
height: height
)
}
}
76 changes: 66 additions & 10 deletions Sources/Brave/Frontend/Shields/SubmitReportView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,19 @@ import SwiftUI
import Strings
import BraveUI
import DesignSystem
import BraveShields
import BraveVPN
import Data

struct SubmitReportView: View {
@Environment(\.dismiss) private var dismiss: DismissAction
let url: URL
let submit: (URL, String, String) -> Void
let isPrivateBrowsing: Bool

@State private var additionalDetails = ""
@State private var contactDetails = ""
@State private var isSubmittingReport = false
@State private var isSubmitted = false

private var scrollContent: some View {
ScrollView {
Expand Down Expand Up @@ -51,12 +56,50 @@ struct SubmitReportView: View {
Button(Strings.cancelButtonTitle) {
dismiss()
}
.disabled(isSubmittingReport)
}

ToolbarItem(placement: .confirmationAction) {
Button(Strings.Shields.reportBrokenSubmitButtonTitle, action: {
dismiss()
didTapSubmit()
})
if isSubmitted {
Button(Strings.close, action: {
dismiss()
})
} else {
Button(Strings.Shields.reportBrokenSubmitButtonTitle, action: {
withAnimation {
isSubmittingReport = true
}

Task { @MainActor in
await createAndSubmitReport()

withAnimation {
isSubmitted = true
}

try await Task.sleep(seconds: 4)
dismiss()
}
}).disabled(isSubmittingReport)
}
}
}
.overlay {
if isSubmittingReport {
ProgressView()
.progressViewStyle(.braveCircular(size: .normal, tint: .braveBlurpleTint))
.frame(maxWidth: .infinity, maxHeight: .infinity)
.background(Color(.braveBackground).opacity(0.5).ignoresSafeArea())
.animation(.easeInOut, value: isSubmittingReport)
}
}
.overlay {
if isSubmitted {
SubmitReportSuccessView()
.progressViewStyle(.braveCircular(size: .normal, tint: .braveBlurpleTint))
.frame(maxWidth: .infinity, maxHeight: .infinity)
.background(Color(.braveBackground).ignoresSafeArea())
.animation(.easeIn, value: isSubmitted)
}
}
}
Expand All @@ -82,16 +125,29 @@ struct SubmitReportView: View {
}
}

func didTapSubmit() {
submit(url, additionalDetails, contactDetails)
@MainActor func createAndSubmitReport() async {
let domain = Domain.getOrCreate(forUrl: url, persistent: !isPrivateBrowsing)

let report = WebcompatReporter.Report(
cleanedURL: url,
additionalDetails: additionalDetails,
contactInfo: contactDetails,
areShieldsEnabled: !domain.areAllShieldsOff,
adBlockLevel: domain.blockAdsAndTrackingLevel,
fingerprintProtectionLevel: domain.finterprintProtectionLevel,
adBlockListTitles: FilterListStorage.shared.filterLists.compactMap({ return $0.isEnabled ? $0.entry.title : nil }),
isVPNEnabled: BraveVPN.isConnected
)

await WebcompatReporter.send(report: report)
}
}

#if swift(>=5.9)
#Preview {
SubmitReportView(
url: URL(string: "https://brave.com/privacy-features")!) { _, _, _ in
// Do nothing
}
url: URL(string: "https://brave.com/privacy-features")!,
isPrivateBrowsing: false
)
}
#endif

0 comments on commit eb11432

Please sign in to comment.