Advertisement
Xaniasty

Untitled

Jun 12th, 2024
38
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.87 KB | None | 0 0
  1. import SwiftUI
  2.  
  3. struct ContentView: View {
  4. @State private var showingLoginAlert = 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. showingLoginAlert = 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. .alert(isPresented: $showingLoginAlert) {
  45. Alert(title: Text("Logowanie"),
  46. message: VStack {
  47. TextField("Login", text: $login)
  48. .textFieldStyle(RoundedBorderTextFieldStyle())
  49. .padding(.bottom, 10)
  50. SecureField("Hasło", text: $password)
  51. .textFieldStyle(RoundedBorderTextFieldStyle())
  52. }.padding(),
  53. primaryButton: .default(Text("OK"), action: {
  54. if login == "TestUser" && password == "TestPassword" {
  55. showingLoginFailedAlert = false
  56. login = ""
  57. password = ""
  58. // Navigate to user photo grid view
  59. if let window = UIApplication.shared.windows.first {
  60. window.rootViewController = UIHostingController(rootView: UserPhotoGridView())
  61. window.makeKeyAndVisible()
  62. }
  63. } else {
  64. showingLoginFailedAlert = true
  65. }
  66. }),
  67. secondaryButton: .cancel(Text("Anuluj")))
  68. }
  69. .alert(isPresented: $showingLoginFailedAlert) {
  70. Alert(title: Text("Błąd"),
  71. message: Text("Nieprawidłowy login lub hasło"),
  72. primaryButton: .default(Text("OK")),
  73. secondaryButton: .default(Text("Zaloguj jako gość"), action: {
  74. // Navigate to guest photo grid view
  75. if let window = UIApplication.shared.windows.first {
  76. window.rootViewController = UIHostingController(rootView: GuestPhotoGridView())
  77. window.makeKeyAndVisible()
  78. }
  79. }))
  80. }
  81. }
  82. .padding(.horizontal, 40)
  83.  
  84. Spacer()
  85. }
  86. .navigationBarTitle("Ekran Logowania", displayMode: .inline)
  87. }
  88. }
  89. }
  90.  
  91. struct GuestPhotoGridView: View {
  92. var body: some View {
  93. Text("Photo Grid View for Guest")
  94. }
  95. }
  96.  
  97. struct UserPhotoGridView: View {
  98. var body: some View {
  99. VStack {
  100. Text("Photo Grid View for User")
  101. Button(action: {
  102. // Action to add a recipe (not implemented yet)
  103. }) {
  104. Text("Dodaj przepis")
  105. .font(.headline)
  106. .padding()
  107. .background(Color.orange)
  108. .foregroundColor(.white)
  109. .cornerRadius(10)
  110. }
  111. }
  112. }
  113. }
  114.  
  115. struct ContentView_Previews: PreviewProvider {
  116. static var previews: some View {
  117. ContentView()
  118. }
  119. }
  120.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement