Fix filtering

pull/28/head
Emre KARTAL 8 months ago
parent e7d8908970
commit c9fb2ca2ed

@ -51,12 +51,12 @@ struct ChoiceCapsule: View {
}
}
.onTapGesture() {
if(!pressed) {
pressed.toggle()
if(pressed) {
viewModel.filters.insert(filter)
} else {
viewModel.filters.remove(filter)
}
pressed.toggle()
}
}

@ -18,23 +18,14 @@ class BetViewModel: ObservableObject {
@Published var betsOver: [BetDetail] = []
@Published var showingSheet: Bool = false
@Published var filters: Set<BetFilter> = [] {
didSet {
getItems()
}
}
private var cancellables = Set<AnyCancellable>()
init() {
getItems()
// Observer for changes in filters
$filters
.sink { [weak self] _ in
self?.getItems()
}
.store(in: &cancellables)
}
didSet {
getItems()
}
}
init() {
getItems()
}
func getItems() {
manager.getBets(withIndex: 0, withCount: 20, filters: Array(filters)) { bets in

@ -26,6 +26,7 @@ public struct BetApiManager: BetDataManager {
let filterStrings = filters.map { $0.rawValue }
let jsonDictionary: [String: Any] = ["filters": filterStrings]
do {
let jsonData = try JSONSerialization.data(withJSONObject: jsonDictionary, options: [])
request.httpBody = jsonData

Loading…
Cancel
Save