Advertisement
Xaniasty

Untitled

Jun 12th, 2024
39
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.82 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 showingPassword = false
  8. @State private var showingLoginFailedAlert = false
  9. @State private var loginFailedMessage = ""
  10. @State private var isUserLoggedIn = false
  11.  
  12. var body: some View {
  13. NavigationView {
  14. if isUserLoggedIn {
  15. UserPhotoGridView(isUserLoggedIn: $isUserLoggedIn)
  16. } else {
  17. VStack {
  18. Spacer()
  19.  
  20. Text("Witamy w X")
  21. .font(.largeTitle)
  22. .padding(.bottom, 10)
  23.  
  24. Text("Wybierz sposób logowania")
  25. .font(.subheadline)
  26. .padding(.bottom, 40)
  27.  
  28. VStack(spacing: 20) {
  29. NavigationLink(destination: GuestPhotoGridView()) {
  30. Text("Jako gość")
  31. .font(.headline)
  32. .frame(minWidth: 0, maxWidth: .infinity)
  33. .padding()
  34. .background(Color.blue)
  35. .foregroundColor(.white)
  36. .cornerRadius(10)
  37. }
  38.  
  39. Button(action: {
  40. showingLoginSheet = true
  41. }) {
  42. Text("Zaloguj się")
  43. .font(.headline)
  44. .frame(minWidth: 0, maxWidth: .infinity)
  45. .padding()
  46. .background(Color.green)
  47. .foregroundColor(.white)
  48. .cornerRadius(10)
  49. }
  50. .sheet(isPresented: $showingLoginSheet) {
  51. VStack {
  52. Text("Logowanie")
  53. .font(.headline)
  54. .padding()
  55.  
  56. TextField("Login", text: $login)
  57. .autocapitalization(.none) // Zapobiega automatycznej kapitalizacji
  58. .textFieldStyle(RoundedBorderTextFieldStyle())
  59. .padding()
  60.  
  61. if showingPassword {
  62. TextField("Hasło", text: $password)
  63. .textFieldStyle(RoundedBorderTextFieldStyle())
  64. .padding()
  65. } else {
  66. SecureField("Hasło", text: $password)
  67. .textFieldStyle(RoundedBorderTextFieldStyle())
  68. .padding()
  69. }
  70.  
  71. Button(action: {
  72. showingPassword.toggle()
  73. }) {
  74. HStack {
  75. Image(systemName: showingPassword ? "eye.slash.fill" : "eye.fill")
  76. Text(showingPassword ? "Ukryj hasło" : "Pokaż hasło")
  77. }
  78. .font(.subheadline)
  79. .foregroundColor(.blue)
  80. }
  81. .padding(.bottom, 20)
  82.  
  83. if showingLoginFailedAlert {
  84. Text(loginFailedMessage)
  85. .foregroundColor(.red)
  86. .padding()
  87. }
  88.  
  89. HStack {
  90. Button("Anuluj") {
  91. showingLoginSheet = false
  92. }
  93. .padding()
  94.  
  95. Button("OK") {
  96. if login == "TestUser" && password == "TestPassword" {
  97. showingLoginFailedAlert = false
  98. login = ""
  99. password = ""
  100. showingLoginSheet = false
  101. isUserLoggedIn = true
  102. } else {
  103. loginFailedMessage = "Nieprawidłowy login lub hasło"
  104. showingLoginFailedAlert = true
  105. }
  106. }
  107. .padding()
  108. }
  109. }
  110. .padding()
  111. }
  112. }
  113. .padding(.horizontal, 40)
  114.  
  115. Spacer()
  116. }
  117. .navigationBarTitle("Ekran Logowania", displayMode: .inline)
  118. }
  119. }
  120. }
  121. }
  122.  
  123. struct GuestPhotoGridView: View {
  124. var body: some View {
  125. Text("Photo Grid View for Guest")
  126. }
  127. }
  128.  
  129. struct UserPhotoGridView: View {
  130. @Binding var isUserLoggedIn: Bool
  131.  
  132. var body: some View {
  133. VStack {
  134. Text("Photo Grid View for User")
  135.  
  136. Button(action: {
  137. // Action to add a recipe (not implemented yet)
  138. }) {
  139. Text("Dodaj przepis")
  140. .font(.headline)
  141. .padding()
  142. .background(Color.orange)
  143. .foregroundColor(.white)
  144. .cornerRadius(10)
  145. }
  146. .padding()
  147.  
  148. Button(action: {
  149. isUserLoggedIn = false
  150. }) {
  151. Text("Wyloguj się")
  152. .font(.headline)
  153. .padding()
  154. .background(Color.red)
  155. .foregroundColor(.white)
  156. .cornerRadius(10)
  157. }
  158. .padding()
  159. }
  160. }
  161. }
  162.  
  163. struct ContentView_Previews: PreviewProvider {
  164. static var previews: some View {
  165. ContentView()
  166. }
  167. }
  168.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement