make the page accurate style for the status of the bet

view/details-page
Lucas DELANIER 1 year ago
parent 5b0c2248a4
commit f9e45ce979

@ -9,30 +9,45 @@ import SwiftUI
struct ParticipateButton: View {
@Binding var isOpen : Bool
@State var isDisabled: Bool = false
var body: some View {
Button {
isOpen.toggle()
} label: {
Text("Participer")
.font(.system(size: 30))
.fontWeight(.bold)
.font(.system(size: 27))
.fontWeight(.semibold)
.frame(maxWidth: .infinity).padding(10)
.multilineTextAlignment(.center)
.overlay {
AllInColors.primaryGradient.frame(width: 170)
.mask(
Text("Participer")
.font(.system(size: 30))
.fontWeight(.bold)
.frame(maxWidth: .infinity).padding(10)
)
switch isDisabled{
case true:
AllInColors.grey700Color.frame(width: 170)
.mask(
Text("Participer")
.font(.system(size: 27))
.fontWeight(.semibold)
.frame(maxWidth: .infinity).padding(10)
)
case false:
AllInColors.primaryGradient.frame(width: 170)
.mask(
Text("Participer")
.font(.system(size: 27))
.fontWeight(.semibold)
.frame(maxWidth: .infinity).padding(10)
)
}
}
.accentColor(AllInColors.componentBackgroundColor)
.background(isDisabled ? AllInColors.delimiterGrey.opacity(0.5):AllInColors.whiteColor)
.buttonStyle(.borderedProminent).cornerRadius(4.0)
.overlay(
RoundedRectangle(cornerRadius: 12).stroke(AllInColors.delimiterGrey, lineWidth: 1)
)
}
.accentColor(AllInColors.componentBackgroundColor)
.buttonStyle(.borderedProminent).cornerRadius(4.0)
.overlay(
RoundedRectangle(cornerRadius: 12).stroke(AllInColors.delimiterGrey, lineWidth: 1)
)
}
}

@ -5,6 +5,45 @@ struct DetailsView: View {
@Binding var isModalPresented: Bool
@State var isModalParticipated: Bool = false
@State var progressValue: Float = 0.2
var isFinished: Bool {
viewModel.betDetail?.finalAnswer == nil ? false : true
}
var isDisabled: Bool {
if let endRegisterDate = viewModel.betDetail?.bet.endRegisterDate {
let currentDate = Date()
switch currentDate.compare(endRegisterDate) {
case .orderedAscending:
return false
case .orderedDescending:
return true
case .orderedSame:
return true
}
} else {
return true
}
}
var StatusValues: (String, Color) {
if let endRegisterDate = viewModel.betDetail?.bet.endRegisterDate {
let currentDate = Date()
switch currentDate.compare(endRegisterDate) {
case .orderedAscending:
return ("En cours...", AllInColors.purpleAccentColor)
case .orderedDescending:
return ("En attente...",AllInColors.pink100)
case .orderedSame:
return ("Fin des inscriptions...",AllInColors.grey50Color)
}
} else {
return ("Statut indisponible", AllInColors.whiteColor)
}
}
var id: String
@StateObject private var viewModel: DetailsViewModel
@ -20,7 +59,7 @@ struct DetailsView: View {
ZStack(alignment: .bottom) {
VStack(alignment: .center) {
HStack{
Text("Terminé!").font(.system(size: 25)).fontWeight(.bold).padding(.bottom, 10).foregroundStyle(AllInColors.blackTitleColor).opacity(0.7)
Text(StatusValues.0).font(.system(size: 25)).fontWeight(.bold).padding(.bottom, 10).foregroundStyle(Color.black).opacity(0.4)
Spacer()
Image("closeIcon")
.resizable()
@ -32,7 +71,7 @@ struct DetailsView: View {
Spacer()
}
.padding(.horizontal, 15)
.background(Color.green)
.background(StatusValues.1)
.transition(.slideInFromBottom(yOffset:0))
VStack(spacing: 0) {
VStack(alignment: .leading,spacing: 5){
@ -73,7 +112,9 @@ struct DetailsView: View {
.padding(.all,15).padding(.vertical, 10)
.background(AllInColors.componentBackgroundColor)
.cornerRadius(20, corners: [.topLeft,.topRight]).padding(.bottom,0)
ResultBanner()
if isFinished {
ResultBanner()
}
VStack(alignment: .leading, spacing: 15) {
BetLineLoading(value: $progressValue).padding(.vertical, 15)
Spacer()
@ -91,7 +132,7 @@ struct DetailsView: View {
.background(AllInColors.componentBackgroundColor)
.cornerRadius(15)
ParticipateButton(isOpen: $isModalParticipated).padding(10)
ParticipateButton(isOpen: $isModalParticipated, isDisabled: isDisabled).padding(10).disabled(isDisabled)
}

@ -22,6 +22,8 @@ public class BetDetail: ObservableObject {
/// The user's own participation in the bet.
public private(set) var userParticipation: Participation
public private(set) var finalAnswer: String?
/// Custom Constructor
///
/// - Parameters:
@ -29,10 +31,15 @@ public class BetDetail: ObservableObject {
/// - answers: Details about the answers available for the bet.
/// - participations: List of user participations in the bet.
/// - userParticipation: The user's own participation in the bet.
public init(bet: Bet, answers: [BetAnswerDetail], participations: [Participation], userParticipation: Participation) {
public init(bet: Bet, answers: [BetAnswerDetail], participations: [Participation], userParticipation: Participation, finalAnswer: String? = nil) {
self.bet = bet
self.answers = answers
self.participations = participations
self.userParticipation = userParticipation
self.finalAnswer = finalAnswer
}
public func updateFinalAnswer(newFinalAnswer: String) {
self.finalAnswer = newFinalAnswer
}
}

@ -35,7 +35,7 @@ struct Stub {
let bet1 = BinaryBet(
theme: "Football - Finale de la Ligue des Champions",
phrase: "Le gagnant de la finale sera l'équipe avec le plus de tirs au but.",
endRegisterDate: Date().addingTimeInterval(86400),
endRegisterDate: Date().addingTimeInterval(-86400),
endBetDate: Date().addingTimeInterval(172800),
totalStakes: 100,
isPublic: true,
@ -91,7 +91,7 @@ struct Stub {
}
public mutating func add(bet: Bet) {
let newBetDetail = BetDetail(bet: bet, answers: [], participations: [], userParticipation: Participation(stake: 0, date: Date(), response: "", user: users[1], betId: ""))
let newBetDetail = BetDetail(bet: bet, answers: [], participations: [], userParticipation: Participation(stake: 0, date: Date(), response: "", user: users[1], betId: ""), finalAnswer: "test")
self.betsDetail.append(newBetDetail)
}
}

Loading…
Cancel
Save