chore: allow multiple report server rules selection
This commit is contained in:
parent
ca91e756ff
commit
9b4da01c48
|
@ -120,26 +120,15 @@ extension ReportViewController: ReportReasonViewControllerDelegate {
|
|||
// MARK: - ReportServerRulesViewControllerDelegate
|
||||
extension ReportViewController: ReportServerRulesViewControllerDelegate {
|
||||
func reportServerRulesViewController(_ viewController: ReportServerRulesViewController, nextButtonPressed button: UIButton) {
|
||||
if viewController.viewModel.isDislike {
|
||||
let reportResultViewModel = ReportResultViewModel(
|
||||
context: context,
|
||||
user: viewModel.user,
|
||||
isReported: false
|
||||
)
|
||||
coordinator.present(
|
||||
scene: .reportResult(viewModel: reportResultViewModel),
|
||||
from: self,
|
||||
transition: .show
|
||||
)
|
||||
} else if viewController.viewModel.selectRule != nil {
|
||||
coordinator.present(
|
||||
scene: .reportStatus(viewModel: viewModel.reportStatusViewModel),
|
||||
from: self,
|
||||
transition: .show
|
||||
)
|
||||
} else {
|
||||
assertionFailure()
|
||||
guard !viewController.viewModel.selectRules.isEmpty else {
|
||||
return
|
||||
}
|
||||
|
||||
coordinator.present(
|
||||
scene: .reportStatus(viewModel: viewModel.reportStatusViewModel),
|
||||
from: self,
|
||||
transition: .show
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -136,10 +136,9 @@ extension ReportViewModel {
|
|||
suffixes.append(reason.rawValue)
|
||||
case .violateRule:
|
||||
suffixes.append(reason.rawValue)
|
||||
if let rule = self.reportServerRulesViewModel.selectRule {
|
||||
|
||||
for rule in self.reportServerRulesViewModel.selectRules {
|
||||
suffixes.append(rule.text)
|
||||
} else {
|
||||
assertionFailure("should select valid rule")
|
||||
}
|
||||
case .dislike:
|
||||
assertionFailure("should not enter the report flow")
|
||||
|
@ -178,8 +177,8 @@ extension ReportViewModel {
|
|||
ruleIDs: {
|
||||
switch self.reportReasonViewModel.selectReason {
|
||||
case .violateRule:
|
||||
guard let rule = self.reportServerRulesViewModel.selectRule else { return nil }
|
||||
return [rule.id]
|
||||
let ruleIDs = self.reportServerRulesViewModel.selectRules.map { $0.id }.sorted()
|
||||
return ruleIDs
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -41,9 +41,7 @@ struct ReportReasonView: View {
|
|||
EmptyView()
|
||||
default:
|
||||
ReportReasonRowView(reason: reason, isSelect: reason == viewModel.selectReason)
|
||||
.background(
|
||||
Color(viewModel.backgroundColor)
|
||||
)
|
||||
.contentShape(Rectangle())
|
||||
.onTapGesture {
|
||||
viewModel.selectReason = reason
|
||||
}
|
||||
|
|
|
@ -138,14 +138,15 @@ struct ReportActionButton: View {
|
|||
ZStack {
|
||||
ProgressView()
|
||||
.opacity(isBusy ? 1 : 0)
|
||||
.progressViewStyle(CircularProgressViewStyle(tint: .gray))
|
||||
Text(title)
|
||||
.font(.headline)
|
||||
.foregroundColor(Color(Asset.Colors.Label.primary.color))
|
||||
.foregroundColor(Color(UIColor.black))
|
||||
.opacity(isBusy ? 0 : 1)
|
||||
}
|
||||
.frame(maxWidth: .infinity)
|
||||
.padding()
|
||||
.background(Color(UIColor.systemBackground))
|
||||
.background(Color(UIColor.white)) // using white for Light & Dark
|
||||
.cornerRadius(10)
|
||||
.shadow(color: .black.opacity(0.1), radius: 2, x: 0, y: 1)
|
||||
}
|
||||
|
|
|
@ -37,27 +37,19 @@ struct ReportServerRulesView: View {
|
|||
ForEach(viewModel.serverRules, id: \.self) { rule in
|
||||
ReportServerRulesRowView(
|
||||
title: rule.text,
|
||||
isSelect: rule == viewModel.selectRule
|
||||
isSelect: viewModel.selectRules.contains(rule)
|
||||
)
|
||||
.background(
|
||||
Color(viewModel.backgroundColor)
|
||||
)
|
||||
.onTapGesture {
|
||||
viewModel.selectRule = rule
|
||||
viewModel.isDislike = false
|
||||
if viewModel.selectRules.contains(rule) {
|
||||
viewModel.selectRules.remove(rule)
|
||||
} else {
|
||||
viewModel.selectRules.insert(rule)
|
||||
}
|
||||
}
|
||||
}
|
||||
ReportServerRulesRowView(
|
||||
title: L10n.Scene.Report.StepTwo.iJustDonTLikeIt,
|
||||
isSelect: viewModel.isDislike
|
||||
)
|
||||
.background(
|
||||
Color(viewModel.backgroundColor)
|
||||
)
|
||||
.onTapGesture {
|
||||
viewModel.selectRule = nil
|
||||
viewModel.isDislike = true
|
||||
}
|
||||
}
|
||||
.padding()
|
||||
.transition(.opacity)
|
||||
|
@ -80,7 +72,7 @@ struct ReportServerRulesRowView: View {
|
|||
|
||||
var body: some View {
|
||||
HStack(spacing: 14) {
|
||||
Image(systemName: isSelect ? "checkmark.circle.fill" : "circle")
|
||||
Image(systemName: isSelect ? "checkmark.square.fill" : "square")
|
||||
.resizable()
|
||||
.frame(width: 28, height: 28, alignment: .center)
|
||||
VStack(alignment: .leading, spacing: 4) {
|
||||
|
|
|
@ -88,13 +88,10 @@ extension ReportServerRulesViewController {
|
|||
}
|
||||
.store(in: &observations)
|
||||
|
||||
Publishers.CombineLatest(
|
||||
viewModel.$selectRule,
|
||||
viewModel.$isDislike
|
||||
)
|
||||
.map { $0 != nil || $1 }
|
||||
.assign(to: \.isEnabled, on: navigationActionView.nextButton)
|
||||
.store(in: &disposeBag)
|
||||
viewModel.$selectRules
|
||||
.map { !$0.isEmpty }
|
||||
.assign(to: \.isEnabled, on: navigationActionView.nextButton)
|
||||
.store(in: &disposeBag)
|
||||
|
||||
navigationActionView.nextButton.addTarget(self, action: #selector(ReportServerRulesViewController.nextButtonPressed(_:)), for: .touchUpInside)
|
||||
}
|
||||
|
|
|
@ -25,8 +25,7 @@ final class ReportServerRulesViewModel: ObservableObject {
|
|||
@Published var backgroundColor: UIColor = Asset.Scene.Report.background.color
|
||||
|
||||
// output
|
||||
@Published var selectRule: Mastodon.Entity.Instance.Rule?
|
||||
@Published var isDislike: Bool = false
|
||||
@Published var selectRules: Set<Mastodon.Entity.Instance.Rule> = Set()
|
||||
|
||||
init(context: AppContext) {
|
||||
self.context = context
|
||||
|
|
|
@ -86,15 +86,17 @@ extension ReportStatusTableViewCell {
|
|||
separatorLine.bottomAnchor.constraint(equalTo: contentView.bottomAnchor),
|
||||
separatorLine.heightAnchor.constraint(equalToConstant: UIView.separatorLineHeight(of: contentView)).priority(.required - 1),
|
||||
])
|
||||
|
||||
statusView.isUserInteractionEnabled = false
|
||||
}
|
||||
|
||||
override func setSelected(_ selected: Bool, animated: Bool) {
|
||||
super.setSelected(selected, animated: animated)
|
||||
if selected {
|
||||
checkbox.image = UIImage(systemName: "checkmark.circle.fill")
|
||||
checkbox.image = UIImage(systemName: "checkmark.square.fill")
|
||||
checkbox.tintColor = Asset.Colors.Label.primary.color
|
||||
} else {
|
||||
checkbox.image = UIImage(systemName: "circle")
|
||||
checkbox.image = UIImage(systemName: "square")
|
||||
checkbox.tintColor = Asset.Colors.Label.secondary.color
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue