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

Commit

Permalink
Ref #8270 Add SubmitReportView (#8123)
Browse files Browse the repository at this point in the history
* Add `SubmitReportView`

* Fix success dialogue on submit webcompat report view

* Hide cancel button on submit report view upon submit

* Add webcompat report button to settings

* Add email content type to webcompat report text field

* Fix navigation view

* Fix for review

* Push web-compat report success

* Updated for review

* Fix for review

* Fix for review
  • Loading branch information
cuba authored Oct 17, 2023
1 parent 0db7215 commit 283462f
Show file tree
Hide file tree
Showing 14 changed files with 371 additions and 235 deletions.
4 changes: 4 additions & 0 deletions Sources/Brave/Frontend/Browser/BrowserViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2227,6 +2227,10 @@ public class BrowserViewController: UIViewController {

activities.append(addSearchEngineActivity)
}

activities.append(ReportWebCompatibilityIssueActivity() { [weak self] in
self?.showSubmitReportView(for: url)
})

return activities
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2021 The Brave Authors. All rights reserved.
// Copyright 2023 The Brave Authors. All rights reserved.
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
// file, You can obtain one at https://mozilla.org/MPL/2.0/.

import BraveShared
import BraveUI
Expand Down Expand Up @@ -506,10 +506,45 @@ extension BrowserViewController: TopToolbarDelegate {
self.present(container, animated: true)
}
}

shields.showSubmitReportView = { [weak self] shieldsViewController in
shieldsViewController.dismiss(animated: true) {
guard let url = shieldsViewController.tab.url else { return }
self?.showSubmitReportView(for: url)
}
}

let container = PopoverNavigationController(rootViewController: shields)
let popover = PopoverController(contentController: container, contentSizeBehavior: .preferredContentSize)
popover.present(from: topToolbar.locationView.shieldsButton, on: self)
}

func showSubmitReportView(for url: URL) {
// Strip fragments and query params from url
var components = URLComponents(url: url, resolvingAgainstBaseURL: false)
components?.fragment = nil
components?.queryItems = nil
guard let cleanedURL = components?.url else { return }

let viewController = UIHostingController(rootView: SubmitReportView(
url: cleanedURL, isPrivateBrowsing: privateBrowsingManager.isPrivateBrowsing
))

viewController.modalPresentationStyle = .popover

if let popover = viewController.popoverPresentationController {
popover.sourceView = topToolbar.locationView.shieldsButton
popover.sourceRect = topToolbar.locationView.shieldsButton.bounds

let sheet = popover.adaptiveSheetPresentationController
sheet.largestUndimmedDetentIdentifier = .medium
sheet.prefersEdgeAttachedInCompactHeight = true
sheet.widthFollowsPreferredContentSizeWhenEdgeAttached = true
sheet.detents = [.medium(), .large()]
sheet.prefersGrabberVisible = true
}
navigationController?.present(viewController, animated: true)
}

// 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
42 changes: 42 additions & 0 deletions Sources/Brave/Frontend/Share/ReportWebcompatIssueActivity.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Copyright 2023 The Brave Authors. All rights reserved.
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.

import Foundation
import Strings
import UIKit
import SwiftUI

class ReportWebCompatibilityIssueActivity: UIActivity, MenuActivity {
private let callback: () -> Void

init(callback: @escaping () -> Void) {
self.callback = callback
}

override var activityTitle: String? {
Strings.Shields.reportABrokenSite
}

private var imageName: String {
"leo.warning.triangle-outline"
}

override var activityImage: UIImage? {
UIImage(braveSystemNamed: imageName)?.applyingSymbolConfiguration(.init(scale: .large))
}

var menuImage: Image {
Image(braveSystemName: imageName)
}

override func perform() {
callback()
activityDidFinish(true)
}

override func canPerform(withActivityItems activityItems: [Any]) -> Bool {
return true
}
}
86 changes: 0 additions & 86 deletions Sources/Brave/Frontend/Shields/ReportBrokenSiteView.swift

This file was deleted.

4 changes: 1 addition & 3 deletions Sources/Brave/Frontend/Shields/ShieldsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import Foundation
import Shared
import BraveShared
import UIKit
import SwiftUI

extension ShieldsViewController {
class View: UIView {
Expand Down Expand Up @@ -38,9 +39,6 @@ extension ShieldsViewController {
$0.isHidden = true
}

let reportBrokenSiteView = ReportBrokenSiteView()
let siteReportedView = SiteReportedView()

override init(frame: CGRect) {
super.init(frame: frame)

Expand Down
40 changes: 4 additions & 36 deletions Sources/Brave/Frontend/Shields/ShieldsViewController.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright 2023 The Brave Authors. All rights reserved.
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
// file, You can obtain one at https://mozilla.org/MPL/2.0/.

import Storage
import SnapKit
Expand All @@ -12,7 +13,6 @@ import BraveUI
import UIKit
import Growth
import BraveCore
import BraveVPN

/// Displays shield settings and shield stats for a given URL
class ShieldsViewController: UIViewController, PopoverContentComponent {
Expand All @@ -30,6 +30,7 @@ class ShieldsViewController: UIViewController, PopoverContentComponent {

var shieldsSettingsChanged: ((ShieldsViewController, BraveShield) -> Void)?
var showGlobalShieldsSettings: ((ShieldsViewController) -> Void)?
var showSubmitReportView: ((ShieldsViewController) -> Void)?

private var statsUpdateObservable: AnyObject?

Expand Down Expand Up @@ -239,7 +240,6 @@ class ShieldsViewController: UIViewController, PopoverContentComponent {
let normalizedDisplayHost = URLFormatter.formatURLOrigin(forDisplayOmitSchemePathAndTrivialSubdomains: url?.absoluteString ?? "")

shieldsView.simpleShieldView.hostLabel.text = normalizedDisplayHost
shieldsView.reportBrokenSiteView.urlLabel.text = url?.domainURL.absoluteString
shieldsView.simpleShieldView.shieldsSwitch.addTarget(self, action: #selector(shieldsOverrideSwitchValueChanged), for: .valueChanged)
shieldsView.advancedShieldView.siteTitle.titleLabel.text = normalizedDisplayHost.uppercased()
shieldsView.advancedShieldView.globalControlsButton.addTarget(self, action: #selector(tappedGlobalShieldsButton), for: .touchUpInside)
Expand All @@ -250,8 +250,6 @@ class ShieldsViewController: UIViewController, PopoverContentComponent {
shieldsView.simpleShieldView.blockCountView.shareButton.addTarget(self, action: #selector(tappedShareShieldsButton), for: .touchUpInside)

shieldsView.simpleShieldView.reportSiteButton.addTarget(self, action: #selector(tappedReportSiteButton), for: .touchUpInside)
shieldsView.reportBrokenSiteView.cancelButton.addTarget(self, action: #selector(tappedCancelReportingButton), for: .touchUpInside)
shieldsView.reportBrokenSiteView.submitButton.addTarget(self, action: #selector(tappedSubmitReportingButton), for: .touchUpInside)

updateShieldBlockStats()

Expand Down Expand Up @@ -317,37 +315,7 @@ class ShieldsViewController: UIViewController, PopoverContentComponent {
}

@objc private func tappedReportSiteButton() {
updateContentView(to: shieldsView.reportBrokenSiteView, animated: true)
}

@objc private func tappedCancelReportingButton() {
updateContentView(to: shieldsView.stackView, animated: true)
}

@objc private func tappedSubmitReportingButton() {
if let url = url {
Task { @MainActor in
let domain = Domain.getOrCreate(forUrl: url, persistent: !tab.isPrivate)

let report = WebcompatReporter.Report(
fullUrl: url,
areShieldsEnabled: !domain.areAllShieldsOff,
adBlockLevel: domain.blockAdsAndTrackingLevel,
fingerprintProtectionLevel: domain.finterprintProtectionLevel,
adBlockListTitles: FilterListStorage.shared.filterLists.compactMap({ filterList -> String? in
guard filterList.isEnabled else { return nil }
return filterList.entry.title
}),
isVPNEnabled: BraveVPN.isConnected
)

await WebcompatReporter.send(report: report)
try await Task.sleep(nanoseconds: NSEC_PER_SEC * 2)
guard !self.isBeingDismissed else { return }
self.dismiss(animated: true)
}
}
updateContentView(to: shieldsView.siteReportedView, animated: true)
showSubmitReportView?(self)
}

@objc private func tappedGlobalShieldsButton() {
Expand Down
56 changes: 0 additions & 56 deletions Sources/Brave/Frontend/Shields/SiteReportedView.swift

This file was deleted.

32 changes: 32 additions & 0 deletions Sources/Brave/Frontend/Shields/SubmitReportSuccessView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Copyright 2023 The Brave Authors. All rights reserved.
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.

import SwiftUI
import Strings
import BraveUI
import DesignSystem
import SnapKit

struct SubmitReportSuccessView: View {
var body: some View {
VStack(alignment: .center, spacing: 16) {
Image(braveSystemName: "leo.check.circle-outline")
.font(.system(size: 48))
.foregroundStyle(Color(braveSystemName: .systemfeedbackSuccessIcon))
Text(Strings.Shields.siteReportedTitle)
.font(.title)
Text(Strings.Shields.siteReportedBody)
}
.padding(32)
.multilineTextAlignment(.center)
.foregroundStyle(Color(braveSystemName: .textTertiary))
}
}

#if swift(>=5.9)
#Preview {
SubmitReportSuccessView()
}
#endif
Loading

0 comments on commit 283462f

Please sign in to comment.