Advertisement
Xaniasty

Untitled

Jun 12th, 2024
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.10 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. @State private var isUserLoggedIn = false
  9.  
  10. var body: some View {
  11. NavigationView {
  12. if isUserLoggedIn {
  13. UserPhotoGridView(isUserLoggedIn: $isUserLoggedIn)
  14. } else {
  15. VStack {
  16. Spacer()
  17.  
  18. Text("Witamy w X")
  19. .font(.largeTitle)
  20. .padding(.bottom, 10)
  21.  
  22. Text("Wybierz sposób logowania")
  23. .font(.subheadline)
  24. .padding(.bottom, 40)
  25.  
  26. VStack(spacing: 20) {
  27. NavigationLink(destination: GuestPhotoGridView()) {
  28. Text("Jako gość")
  29. .font(.headline)
  30. .frame(minWidth: 0, maxWidth: .infinity)
  31. .padding()
  32. .background(Color.blue)
  33. .foregroundColor(.white)
  34. .cornerRadius(10)
  35. }
  36.  
  37. Button(action: {
  38. showingLoginSheet = true
  39. }) {
  40. Text("Zaloguj się")
  41. .font(.headline)
  42. .frame(minWidth: 0, maxWidth: .infinity)
  43. .padding()
  44. .background(Color.green)
  45. .foregroundColor(.white)
  46. .cornerRadius(10)
  47. }
  48. .sheet(isPresented: $showingLoginSheet) {
  49. VStack {
  50. Text("Logowanie")
  51. .font(.headline)
  52. .padding()
  53.  
  54. TextField("Login", text: $login)
  55. .textFieldStyle(RoundedBorderTextFieldStyle())
  56. .padding()
  57.  
  58. SecureField("Hasło", text: $password)
  59. .textFieldStyle(RoundedBorderTextFieldStyle())
  60. .padding()
  61.  
  62. HStack {
  63. Button("Anuluj") {
  64. showingLoginSheet = false
  65. }
  66. .padding()
  67.  
  68. Button("OK") {
  69. if login == "TestUser" && password == "TestPassword" {
  70. showingLoginFailedAlert = false
  71. login = ""
  72. password = ""
  73. showingLoginSheet = false
  74. isUserLoggedIn = true
  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.  
  108. struct GuestPhotoGridView: View {
  109. var body: some View {
  110. Text("Photo Grid View for Guest")
  111. }
  112. }
  113.  
  114. struct UserPhotoGridView: View {
  115. @Binding var isUserLoggedIn: Bool
  116.  
  117. var body: some View {
  118. VStack {
  119. Text("Photo Grid View for User")
  120.  
  121. Button(action: {
  122. // Action to add a recipe (not implemented yet)
  123. }) {
  124. Text("Dodaj przepis")
  125. .font(.headline)
  126. .padding()
  127. .background(Color.orange)
  128. .foregroundColor(.white)
  129. .cornerRadius(10)
  130. }
  131. .padding()
  132.  
  133. Button(action: {
  134. isUserLoggedIn = false
  135. }) {
  136. Text("Wyloguj się")
  137. .font(.headline)
  138. .padding()
  139. .background(Color.red)
  140. .foregroundColor(.white)
  141. .cornerRadius(10)
  142. }
  143. .padding()
  144. }
  145. }
  146. }
  147.  
  148. struct ContentView_Previews: PreviewProvider {
  149. static var previews: some View {
  150. ContentView()
  151. }
  152. }
  153.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement