Advertisement
Xaniasty

Untitled

Jun 12th, 2024
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 5.49 KB | None | 0 0
  1. import SwiftUI
  2.  
  3. struct ContentView: View {
  4.     @State private var showingLoginSheet = false
  5.     @State private var login = ""
  6.     @State private var password = ""
  7.     @State private var showingLoginFailedAlert = false
  8.  
  9.     var body: some View {
  10.         NavigationView {
  11.             VStack {
  12.                 Spacer()
  13.                
  14.                 Text("Witamy w X")
  15.                     .font(.largeTitle)
  16.                     .padding(.bottom, 10)
  17.                
  18.                 Text("Wybierz sposób logowania")
  19.                     .font(.subheadline)
  20.                     .padding(.bottom, 40)
  21.                
  22.                 VStack(spacing: 20) {
  23.                     NavigationLink(destination: GuestPhotoGridView()) {
  24.                         Text("Jako gość")
  25.                             .font(.headline)
  26.                             .frame(minWidth: 0, maxWidth: .infinity)
  27.                             .padding()
  28.                             .background(Color.blue)
  29.                             .foregroundColor(.white)
  30.                             .cornerRadius(10)
  31.                     }
  32.                    
  33.                     Button(action: {
  34.                         showingLoginSheet = true
  35.                     }) {
  36.                         Text("Zaloguj się")
  37.                             .font(.headline)
  38.                             .frame(minWidth: 0, maxWidth: .infinity)
  39.                             .padding()
  40.                             .background(Color.green)
  41.                             .foregroundColor(.white)
  42.                             .cornerRadius(10)
  43.                     }
  44.                     .sheet(isPresented: $showingLoginSheet) {
  45.                         VStack {
  46.                             Text("Logowanie")
  47.                                 .font(.headline)
  48.                                 .padding()
  49.                            
  50.                             TextField("Login", text: $login)
  51.                                 .textFieldStyle(RoundedBorderTextFieldStyle())
  52.                                 .padding()
  53.                            
  54.                             SecureField("Hasło", text: $password)
  55.                                 .textFieldStyle(RoundedBorderTextFieldStyle())
  56.                                 .padding()
  57.                            
  58.                             HStack {
  59.                                 Button("Anuluj") {
  60.                                     showingLoginSheet = false
  61.                                 }
  62.                                 .padding()
  63.                                
  64.                                 Button("OK") {
  65.                                     if login == "TestUser" && password == "TestPassword" {
  66.                                         showingLoginFailedAlert = false
  67.                                         login = ""
  68.                                         password = ""
  69.                                         showingLoginSheet = false
  70.                                         // Navigate to user photo grid view
  71.                                         if let window = UIApplication.shared.windows.first {
  72.                                             window.rootViewController = UIHostingController(rootView: UserPhotoGridView())
  73.                                             window.makeKeyAndVisible()
  74.                                         }
  75.                                     } else {
  76.                                         showingLoginFailedAlert = true
  77.                                         showingLoginSheet = false
  78.                                     }
  79.                                 }
  80.                                 .padding()
  81.                             }
  82.                         }
  83.                         .padding()
  84.                     }
  85.                     .alert(isPresented: $showingLoginFailedAlert) {
  86.                         Alert(title: Text("Błąd"),
  87.                               message: Text("Nieprawidłowy login lub hasło"),
  88.                               primaryButton: .default(Text("OK")),
  89.                               secondaryButton: .default(Text("Zaloguj jako gość"), action: {
  90.                                 // Navigate to guest photo grid view
  91.                                 if let window = UIApplication.shared.windows.first {
  92.                                     window.rootViewController = UIHostingController(rootView: GuestPhotoGridView())
  93.                                     window.makeKeyAndVisible()
  94.                                 }
  95.                               }))
  96.                     }
  97.                 }
  98.                 .padding(.horizontal, 40)
  99.                
  100.                 Spacer()
  101.             }
  102.             .navigationBarTitle("Ekran Logowania", displayMode: .inline)
  103.         }
  104.     }
  105. }
  106.  
  107. struct GuestPhotoGridView: View {
  108.     var body: some View {
  109.         Text("Photo Grid View for Guest")
  110.     }
  111. }
  112.  
  113. struct UserPhotoGridView: View {
  114.     var body: some View {
  115.         VStack {
  116.             Text("Photo Grid View for User")
  117.             Button(action: {
  118.                 // Action to add a recipe (not implemented yet)
  119.             }) {
  120.                 Text("Dodaj przepis")
  121.                     .font(.headline)
  122.                     .padding()
  123.                     .background(Color.orange)
  124.                     .foregroundColor(.white)
  125.                     .cornerRadius(10)
  126.             }
  127.         }
  128.         .padding()
  129.     }
  130. }
  131.  
  132. struct ContentView_Previews: PreviewProvider {
  133.     static var previews: some View {
  134.         ContentView()
  135.     }
  136. }
  137.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement