Skip to content

Commit 2e9bd68

Browse files
committed
Show filter count on booking list
1 parent a2c5367 commit 2e9bd68

File tree

2 files changed

+27
-4
lines changed

2 files changed

+27
-4
lines changed

WooCommerce/Classes/Bookings/BookingList/BookingListContainerView.swift

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ struct BookingListContainerView: View {
5757
}
5858
.sheet(isPresented: $showingFilters) {
5959
FilterListView(viewModel: viewModel.filterViewModel) { filters in
60-
// to-do
60+
viewModel.updateFilters(filters)
6161
} onClearAction: {
6262
// no-op
6363
} onDismissAction: {
@@ -84,9 +84,15 @@ private extension BookingListContainerView {
8484
Button {
8585
showingFilters = true
8686
} label: {
87-
Text(Localization.filter)
88-
.font(.body)
89-
.foregroundStyle(Color.accentColor)
87+
if viewModel.numberOfActiveFilters > 0 {
88+
Text(Localization.filterWithCount(viewModel.numberOfActiveFilters))
89+
.font(.body)
90+
.foregroundStyle(Color.accentColor)
91+
} else {
92+
Text(Localization.filter)
93+
.font(.body)
94+
.foregroundStyle(Color.accentColor)
95+
}
9096
}
9197
.renderedIf(viewModel.selectedTab == .all)
9298
}
@@ -208,6 +214,16 @@ private extension BookingListContainerView {
208214
value: "Filter",
209215
comment: "Button to filter the booking list"
210216
)
217+
static func filterWithCount(_ count: Int) -> String {
218+
String.localizedStringWithFormat(
219+
NSLocalizedString(
220+
"bookingListView.filter.withCount",
221+
value: "Filter (%d)",
222+
comment: "Button to filter the booking list with number of active filters"
223+
),
224+
count
225+
)
226+
}
211227
static let searchPrompt = NSLocalizedString(
212228
"bookingListView.search.prompt",
213229
value: "Search bookings",

WooCommerce/Classes/Bookings/BookingList/BookingListContainerViewModel.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ final class BookingListContainerViewModel: ObservableObject {
1515
@Published var selectedTab: BookingListTab = .today
1616
@Published var searchQuery: String = ""
1717
@Published var sortBy: BookingListViewModel.SortBy = .newestToOldest
18+
@Published var numberOfActiveFilters: Int = 0
1819

1920
private let searchQuerySubject = PassthroughSubject<String, Never>()
2021
private var searchQuerySubscription: AnyCancellable?
@@ -99,6 +100,12 @@ final class BookingListContainerViewModel: ObservableObject {
99100
allSearchViewModel
100101
}
101102
}
103+
104+
func updateFilters(_ filters: BookingFiltersViewModel.Filters) {
105+
self.filters = filters
106+
self.numberOfActiveFilters = filters.numberOfActiveFilters
107+
// TODO: Apply filters to list view models
108+
}
102109
}
103110

104111
enum BookingListTab: Int, CaseIterable {

0 commit comments

Comments
 (0)