Hi guys, I have recently developed in swift, I am trying to create an app and use as a database firebase firestore, so far everything is okay, I have a problem at the moment that I cannot understand how to solve, that is, I would like to know how to do it since the logout does not work and how should I enter the user's name in the menu by taking it from the viewmodel because I can't, same thing for the int role, because I have conditions that, based on the role, make me appear the message and the menu , a thousand thanks.
Greetings :)
import SwiftUI
import Firebase
import FirebaseFirestore
struct SideMenu: View {
@Binding var selectedTab: String
@Namespace var animation
@State private var Ruolo = 3
@State private var userEmail = ""
@ObservedObject private var viewModel = userViewModel()
var body: some View {
VStack(alignment: .leading, spacing: 15, content: {
// Profile Pic...
Image(systemName: "person.fill")
.resizable()
.aspectRatio(contentMode: .fill)
.frame(width: 45, height: 50)
.cornerRadius(0)
// Padding top for Top Close Button...
.padding(.top,50)
VStack(alignment: .leading, spacing: 6, content: {
Text(viewModel.user.name)
.font(.title)
.fontWeight(.heavy)
.foregroundColor(.white)
Text("Ruolo: ") //Aggiungere il ruolo
.fontWeight(.semibold)
.foregroundColor(.white)
.opacity(0.7)
Spacer()
.frame(height:(2))
if(Ruolo)==0{
Text("Utente") //Aggiungere il ruolo
.fontWeight(.semibold)
.foregroundColor(.white)
.opacity(0.7)
}
if(Ruolo)==1{
Text("PR") //Aggiungere il ruolo
.fontWeight(.semibold)
.foregroundColor(.purple)
.opacity(0.7)
}
if(Ruolo)==2{
Text("Responsabile") //Aggiungere il ruolo
.fontWeight(.semibold)
.foregroundColor(.orange)
.opacity(0.7)
}
if(Ruolo)==3{
Text("Gestore") //Aggiungere il ruolo
.fontWeight(.semibold)
.foregroundColor(.red)
.opacity(0.7)
}
})
// tab Buttons...
VStack(alignment: .leading,spacing: 10){
TabButton(image: "house", title: "Home", selectedTab: $selectedTab, animation: animation)
TabButton(image: "list.bullet", title: "Prenotazione Lista", selectedTab: $selectedTab, animation: animation)
TabButton(image: "square.grid.3x3.bottomright.filled", title: "Prenotazione Tavoli", selectedTab: $selectedTab, animation: animation)
if Ruolo == 2 || Ruolo == 3{
TabButton(image: "checklist", title: "Lista PR Omaggio", selectedTab: $selectedTab, animation: animation)
TabButton(image: "gear", title: "Pannello Amministrativo", selectedTab: $selectedTab, animation: animation)
}
}
.padding(.leading,-15)
.padding(.top,50)
Spacer()
// Sign Out Button...
VStack(alignment: .leading, spacing: 6, content: {
TabButton(image: "rectangle.righthalf.inset.fill.arrow.right", title: "Log out", selectedTab: .constant(""), animation: animation)
.padding(.leading,-15)
})
})
.padding()
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .topLeading)
}
//Metodo Logout
func logout(){
let firebaseAuth = Auth.auth()
do {
try firebaseAuth.signOut()
} catch let signOutError as NSError {
print("Error signing out: %@", signOutError)
}
}
}
struct SideMenu_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
extension SideMenu {
func placeholder<Content: View>(
when shouldShow: Bool,
alignment: Alignment = .leading,
@ViewBuilder placeholder: () -> Content) -> some View {
ZStack(alignment: alignment) {
placeholder().opacity(shouldShow ? 1 : 0)
self
}
}
}