Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix filter apply button being enabled with zero providers #7159

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -285,10 +285,6 @@ extension RelayFilterDataSource: UITableViewDelegate {
return nil
}

func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
return UITableView.automaticDimension
}

func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
return UIMetrics.TableView.separatorHeight
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,18 @@ class RelayFilterViewController: UIViewController {
case .any:
self?.applyButton.isEnabled = true
case let .only(providers):
self?.applyButton.isEnabled = !providers.isEmpty
switch filter.ownership {
case .any:
self?.applyButton.isEnabled = !providers.isEmpty
case .owned:
let filterHasAtLeastOneOwnedProvider = viewModel.ownedProviders
.first(where: { providers.contains($0) }) != nil
self?.applyButton.isEnabled = filterHasAtLeastOneOwnedProvider
case .rented:
let filterHasAtLeastOneRentedProvider = viewModel.rentedProviders
.first(where: { providers.contains($0) }) != nil
self?.applyButton.isEnabled = filterHasAtLeastOneRentedProvider
}
}
}
.store(in: &disposeBag)
Expand All @@ -105,7 +116,30 @@ class RelayFilterViewController: UIViewController {
}

@objc private func applyFilter() {
guard let filter = viewModel?.relayFilter else { return }
onApplyFilter?(filter)
guard let viewModel = viewModel else { return }
var relayFilter = viewModel.relayFilter

switch viewModel.relayFilter.ownership {
case .any:
break
case .owned:
switch relayFilter.providers {
case .any:
break
case let .only(providers):
let ownedProviders = viewModel.ownedProviders.filter { providers.contains($0) }
relayFilter.providers = .only(ownedProviders)
}
case .rented:
switch relayFilter.providers {
case .any:
break
case let .only(providers):
let rentedProviders = viewModel.rentedProviders.filter { providers.contains($0) }
relayFilter.providers = .only(rentedProviders)
}
}

onApplyFilter?(relayFilter)
}
}
Loading