Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import SwiftUI
- struct ContentView: View {
- @State private var showingLoginSheet = false
- @State private var login = ""
- @State private var password = ""
- @State private var showingPassword = false
- @State private var showingLoginFailedAlert = false
- @State private var loginFailedMessage = ""
- @State private var isUserLoggedIn = false
- var body: some View {
- NavigationView {
- if isUserLoggedIn {
- UserPhotoGridView(isUserLoggedIn: $isUserLoggedIn)
- } else {
- VStack {
- Spacer()
- Text("Witamy w X")
- .font(.largeTitle)
- .padding(.bottom, 10)
- Text("Wybierz sposób logowania")
- .font(.subheadline)
- .padding(.bottom, 40)
- VStack(spacing: 20) {
- NavigationLink(destination: GuestPhotoGridView()) {
- Text("Jako gość")
- .font(.headline)
- .frame(minWidth: 0, maxWidth: .infinity)
- .padding()
- .background(Color.blue)
- .foregroundColor(.white)
- .cornerRadius(10)
- }
- Button(action: {
- showingLoginSheet = true
- }) {
- Text("Zaloguj się")
- .font(.headline)
- .frame(minWidth: 0, maxWidth: .infinity)
- .padding()
- .background(Color.green)
- .foregroundColor(.white)
- .cornerRadius(10)
- }
- .sheet(isPresented: $showingLoginSheet) {
- VStack {
- Text("Logowanie")
- .font(.headline)
- .padding()
- TextField("Login", text: $login)
- .autocapitalization(.none) // Zapobiega automatycznej kapitalizacji
- .textFieldStyle(RoundedBorderTextFieldStyle())
- .padding()
- if showingPassword {
- TextField("Hasło", text: $password)
- .textFieldStyle(RoundedBorderTextFieldStyle())
- .padding()
- } else {
- SecureField("Hasło", text: $password)
- .textFieldStyle(RoundedBorderTextFieldStyle())
- .padding()
- }
- Button(action: {
- showingPassword.toggle()
- }) {
- HStack {
- Image(systemName: showingPassword ? "eye.slash.fill" : "eye.fill")
- Text(showingPassword ? "Ukryj hasło" : "Pokaż hasło")
- }
- .font(.subheadline)
- .foregroundColor(.blue)
- }
- .padding(.bottom, 20)
- if showingLoginFailedAlert {
- Text(loginFailedMessage)
- .foregroundColor(.red)
- .padding()
- }
- HStack {
- Button("Anuluj") {
- showingLoginSheet = false
- }
- .padding()
- Button("OK") {
- if login == "TestUser" && password == "TestPassword" {
- showingLoginFailedAlert = false
- login = ""
- password = ""
- showingLoginSheet = false
- isUserLoggedIn = true
- } else {
- loginFailedMessage = "Nieprawidłowy login lub hasło"
- showingLoginFailedAlert = true
- }
- }
- .padding()
- }
- }
- .padding()
- }
- }
- .padding(.horizontal, 40)
- Spacer()
- }
- .navigationBarTitle("Ekran Logowania", displayMode: .inline)
- }
- }
- }
- }
- struct GuestPhotoGridView: View {
- var body: some View {
- Text("Photo Grid View for Guest")
- }
- }
- struct UserPhotoGridView: View {
- @Binding var isUserLoggedIn: Bool
- var body: some View {
- VStack {
- Text("Photo Grid View for User")
- Button(action: {
- // Action to add a recipe (not implemented yet)
- }) {
- Text("Dodaj przepis")
- .font(.headline)
- .padding()
- .background(Color.orange)
- .foregroundColor(.white)
- .cornerRadius(10)
- }
- .padding()
- Button(action: {
- isUserLoggedIn = false
- }) {
- Text("Wyloguj się")
- .font(.headline)
- .padding()
- .background(Color.red)
- .foregroundColor(.white)
- .cornerRadius(10)
- }
- .padding()
- }
- }
- }
- struct ContentView_Previews: PreviewProvider {
- static var previews: some View {
- ContentView()
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement