Skip to content

Commit

Permalink
Fix filter apply button being enabled with zero providers
Browse files Browse the repository at this point in the history
  • Loading branch information
rablador authored and pinkisemils committed Nov 18, 2024
1 parent 244d006 commit aa56e46
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 7 deletions.
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)
}
}

0 comments on commit aa56e46

Please sign in to comment.