Untitled

mail@pastecode.io avatar
unknown
swift
2 years ago
3.2 kB
4
Indexable
Never
//
//  FilterView.swift
//  uhub
//
//  Created by Truong Nhat Anh on 01/09/2022.
//

import SwiftUI

struct FilterView: View {
    var majors = ["iOS Development", "Web Development", "Data Science", "Cloud Engineering", "Android Development", "Tester", "Embedded Developer", "Data Engineering", "Algorithm Analysis"]
    @State var minimumGPA: String
    @State var semesterLearned: String
    @State var selectedMajor: String
    @State private var canShowPicker = false
    @State var scale = 1.0
    
    var body: some View {
        ZStack {
            VStack {
                VStack(alignment: .leading) {
                    VStack(alignment: .leading) {
                        Text("Major")
                            .padding(.leading)
                        Button {
                            withAnimation {
                                canShowPicker.toggle();
                            }

                        } label: {
                            HStack {
                                Text("\(selectedMajor)")
                                Spacer()
                                Image(systemName: "arrowtriangle.down.circle")
                            }
                                .modifier(InputModifier())
                        }
                    }
                    .padding(.bottom, 8)
                    VStack(alignment: .leading) {
                        Text("Minimum GPA")
                            .padding(.leading)
                        TextField("Minimum GPA", text: $minimumGPA)
                            .modifier(InputModifier())
                    }
                    .padding(.bottom, 8)
                    VStack(alignment: .leading) {
                        Text("Semester Learn")
                            .padding(.leading)
                        TextField("Minimum GPA", text: $semesterLearned)
                            .modifier(InputModifier())
                    }
                    
                    
                }
                
                Spacer()
                Button {
                    
                } label: {
                    Text("Save changes")
                        .modifier(ButtonModifier())
                }
                if canShowPicker {
                    VStack {
                        Picker("Major", selection: $selectedMajor) {
                            ForEach(majors, id: \.self) { major in
                                Text(major)
                            }
                        }
                        .pickerStyle(.wheel)
                        Button {
                            withAnimation {
                                canShowPicker = false
                            }
                        } label: {
                            Text("Done")
                                .foregroundColor(Color("primary"))
                        }
                    }
                }
                    
            }
            
        }

        .padding()
    }
}

struct FilterView_Previews: PreviewProvider {
    static var previews: some View {
        FilterView(minimumGPA: "3.2", semesterLearned: "6", selectedMajor: "iOS")
    }
}