Add a semaphore to avoid the empty page in the DetailsView and get the user infos when the menu is open 🐛

fix/multiples-fix
Emre KARTAL 10 months ago
parent d5e50e4168
commit 2bb46d3b6f

@ -12,7 +12,6 @@ struct Menu: View {
@Inject var authService: IAuthService
let parameters: [(String, String, String, String)] = [
("videoGameImage", String(localized: "drawer_create_a_bet"), String(localized: "drawer_create_a_bet_subtitle"), "CreationBet"),
("globeImage", String(localized: "drawer_public_bets"), String(localized: "drawer_public_bets_subtitle"), "Bet"),
@ -40,7 +39,7 @@ struct Menu: View {
HStack(spacing: 30) {
Spacer()
VStack(){
Text(AppStateContainer.shared.user?.bestWin.description ?? "0")
Text(AppStateContainer.shared.user?.bestWin ?? 0, format: .number)
.fontWeight(.heavy)
.font(.system(size: 15))
.foregroundColor(.white)
@ -50,7 +49,7 @@ struct Menu: View {
.foregroundColor(AllInColors.grey600Color)
}
VStack(){
Text(AppStateContainer.shared.user?.bestWin.description ?? "0")
Text(AppStateContainer.shared.user!.bestWin, format: .number)
.fontWeight(.heavy)
.font(.system(size: 15))
.foregroundColor(.white)
@ -60,7 +59,7 @@ struct Menu: View {
.foregroundColor(AllInColors.grey600Color)
}
VStack(){
Text(AppStateContainer.shared.user?.nbFriends.description ?? "0")
Text(AppStateContainer.shared.user!.nbFriends, format: .number)
.fontWeight(.heavy)
.font(.system(size: 15))
.foregroundColor(.white)
@ -104,6 +103,9 @@ struct Menu: View {
.frame(maxWidth: .infinity,alignment: .leading)
.background(AllInColors.primaryColor)
.edgesIgnoringSafeArea(.bottom)
.onAppear {
authService.refreshAuthentication()
}
}
}

@ -26,13 +26,20 @@ class DetailsViewModel: ObservableObject {
}
func getItem(withId id: String) {
let semaphore = DispatchSemaphore(value: 0)
manager.getBet(withId: id) { bet in
DispatchQueue.main.async {
self.betDetail = bet
if let firstAnswer = bet.answers.first {
self.selectedAnswer = firstAnswer
}
semaphore.signal()
}
let result = semaphore.wait(timeout: DispatchTime.now() + .seconds(2))
if result == .timedOut {
print("The request has exceeded the deadline")
return
}
}

@ -6,7 +6,6 @@ struct DetailsView: View {
@Binding var isModalPresented: Bool
@Binding var isModalParticipated: Bool
@StateObject private var viewModel: DetailsViewModel
@State private var isLoading = true
var isFinished: Bool {
viewModel.betDetail?.wonParticipation == nil ? false : true

Loading…
Cancel
Save