wip
This commit is contained in:
@@ -63,31 +63,51 @@ struct Workout: Codable, Identifiable, Equatable {
|
||||
}
|
||||
|
||||
extension Array where Element == Workout {
|
||||
func filterWorkouts(searchString: String, filteredRegisterdUser: RegisteredUser?) -> [Workout] {
|
||||
func filterWorkouts(nameSearchString: String,
|
||||
musclesSearchString: Set<String>,
|
||||
equipmentSearchString: Set<String>,
|
||||
filteredRegisterdUser: RegisteredUser?) -> [Workout] {
|
||||
var matchingWorkouts = [Workout]()
|
||||
|
||||
if (!searchString.isEmpty && searchString.count > 0) {
|
||||
if matchingWorkouts.isEmpty {
|
||||
matchingWorkouts.append(contentsOf: self)
|
||||
}
|
||||
|
||||
if (!nameSearchString.isEmpty && nameSearchString.count > 0) {
|
||||
matchingWorkouts = self.filter({
|
||||
if $0.name.lowercased().contains(searchString.lowercased()) {
|
||||
if $0.name.lowercased().contains(nameSearchString.lowercased()) {
|
||||
return true
|
||||
}
|
||||
|
||||
if let equipment = $0.equipment?.joined(separator: "").lowercased(),
|
||||
equipment.contains(searchString.lowercased()) {
|
||||
return true
|
||||
}
|
||||
|
||||
if let muscles = $0.muscles?.joined(separator: "").lowercased(),
|
||||
muscles.contains(searchString.lowercased()) {
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
})
|
||||
}
|
||||
|
||||
if matchingWorkouts.isEmpty {
|
||||
matchingWorkouts.append(contentsOf: self)
|
||||
if (!equipmentSearchString.isEmpty && equipmentSearchString.count > 0) {
|
||||
matchingWorkouts = matchingWorkouts.filter({
|
||||
if let equipment = $0.equipment?.joined(separator: "").lowercased() {
|
||||
for word in equipmentSearchString {
|
||||
if equipment.contains(word.lowercased()) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
return false
|
||||
})
|
||||
}
|
||||
|
||||
if (!musclesSearchString.isEmpty && musclesSearchString.count > 0) {
|
||||
matchingWorkouts = matchingWorkouts.filter({
|
||||
if let muscles = $0.muscles?.joined(separator: "").lowercased() {
|
||||
for word in musclesSearchString {
|
||||
if muscles.contains(word.lowercased()) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
return false
|
||||
})
|
||||
}
|
||||
|
||||
if let filteredRegisterdUser = filteredRegisterdUser {
|
||||
|
||||
Reference in New Issue
Block a user