filter view
all workout filter view is its own view all workout filter view is the top of all workout view
This commit is contained in:
90
iphone/Werkout_ios/subview/FilterAllView.swift
Normal file
90
iphone/Werkout_ios/subview/FilterAllView.swift
Normal file
@@ -0,0 +1,90 @@
|
||||
//
|
||||
// FilterAllView.swift
|
||||
// Werkout_ios
|
||||
//
|
||||
// Created by Trey Tartt on 11/25/24.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
|
||||
struct FilterAllView: View {
|
||||
@Binding var searchString: String
|
||||
@Binding var uniqueWorkoutUsers: [RegisteredUser]?
|
||||
@Binding var filteredRegisterdUser: RegisteredUser?
|
||||
@Binding var filteredWorkouts: [Workout]
|
||||
@Binding var workouts: [Workout]
|
||||
@Binding var currentSort: SortType?
|
||||
|
||||
var body: some View {
|
||||
HStack {
|
||||
TextField("Filter" ,text: $searchString)
|
||||
.padding(.horizontal)
|
||||
.textFieldStyle(.roundedBorder)
|
||||
|
||||
if let uniqueWorkoutUsers = uniqueWorkoutUsers {
|
||||
Menu(content: {
|
||||
ForEach(uniqueWorkoutUsers, id: \.self) { index in
|
||||
Button(action: {
|
||||
filteredRegisterdUser = index
|
||||
filteredWorkouts = workouts.filterWorkouts(searchString: searchString,
|
||||
filteredRegisterdUser: filteredRegisterdUser)
|
||||
}, label: {
|
||||
Text((index.firstName ?? "") + " -" + (index.lastName ?? ""))
|
||||
})
|
||||
}
|
||||
|
||||
Button(action: {
|
||||
filteredRegisterdUser = nil
|
||||
filteredWorkouts = workouts.filterWorkouts(searchString: searchString,filteredRegisterdUser: filteredRegisterdUser)
|
||||
}, label: {
|
||||
Text("All")
|
||||
})
|
||||
|
||||
}, label: {
|
||||
Image(systemName: filteredRegisterdUser == nil ? "person.2" : "person.2.fill")
|
||||
.padding(.trailing)
|
||||
})
|
||||
}
|
||||
|
||||
Menu(content: {
|
||||
ForEach(SortType.allCases, id: \.self) { index in
|
||||
Button(action: {
|
||||
sortWorkouts(sortType: index)
|
||||
}, label: {
|
||||
Text(index.rawValue)
|
||||
})
|
||||
}
|
||||
}, label: {
|
||||
Image(systemName: "list.number")
|
||||
.padding(.trailing)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func sortWorkouts(sortType: SortType) {
|
||||
if currentSort == sortType {
|
||||
filteredWorkouts = filteredWorkouts.reversed()
|
||||
return
|
||||
}
|
||||
switch sortType {
|
||||
case .name:
|
||||
filteredWorkouts = filteredWorkouts.sorted(by: {
|
||||
$0.name < $1.name
|
||||
})
|
||||
case .date:
|
||||
filteredWorkouts = filteredWorkouts.sorted(by: {
|
||||
$0.createdAt ?? Date() < $1.createdAt ?? Date()
|
||||
})
|
||||
}
|
||||
currentSort = sortType
|
||||
}
|
||||
}
|
||||
|
||||
#Preview {
|
||||
FilterAllView(searchString: .constant(""),
|
||||
uniqueWorkoutUsers: .constant(nil),
|
||||
filteredRegisterdUser: .constant(nil),
|
||||
filteredWorkouts: .constant(PreviewData.allWorkouts()),
|
||||
workouts: .constant(PreviewData.allWorkouts()),
|
||||
currentSort: .constant(nil))
|
||||
}
|
||||
Reference in New Issue
Block a user