Search user database within a specific group of users with Swiftui/Firebase

Viewed 14

In my search page, I want to search my database by first name, last name, and username. I have three scenarios:

  1. Search all users by first name, last name, and username. (I'm good here.)
  2. Search users by first name, last name, and username but only search those within a specific location based on signup choice. (I'm good on the backend function, and it all works.)
  3. Search users by first name, last name, and username but only search those that play a certain sport based on signup choice. (I'm good on the backend function, and it all works.)

What I need help with is how to present that view on screen.

Example:

Search all users in my database based on their location in the United States. This view should show a list of all 50 US States, with each item opening to its own Search page.

Do I have to create a view and viewmodel for each State?

How can I make each navigation link in the list go to that specific Search page for the State?

I just want a simple list where the user can pick a location, and then search for users from that location.

Thank you!

let locationOptions: [String] = [
        "Alaska","Alabama","Arkansas","American Somoa","Arizona","California","Colorado","Connecticut","Delaware","District of Columbia","Dominican Republic","Florida","Georgia","Guam","Hawaii","Iowa","Idaho","Illinois","Indiana","Kansas","Kentucky","Louisiana","Massachusetts","Maryland","Maine","Mexico","Michigan","Minnesota","Missouri","Mississippi","Montana","North Carolina","North Dakota","Nebraska","New Hampshire","New Jersey","New Mexico","Nevada","New York","Ohio","Oklahoma","Oregon","Pennsylvania","Puerto Rico","Rhode Island","South Carolina","South Dakota","Tennessee","Texas","Utah","Virginia","Virgin Islands","Vermont","Washington","Wisconsin","West Virginia","Wyoming",
    ]

                 ScrollView {
                    LazyVStack(alignment: .leading, spacing: 16) {
                        ForEach(locationOptions, id: \.self) { location in
                            Text(location)
                                .font(.title)
                        }
                    }
                }
0 Answers
Related