Advertisement
Xaniasty

Untitled

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