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 { struct ParticipateButton: View {
@Binding var isOpen : Bool @Binding var isOpen : Bool
@State var isDisabled: Bool = false
var body: some View { var body: some View {
Button { Button {
isOpen.toggle() isOpen.toggle()
} label: { } label: {
Text("Participer") Text("Participer")
.font(.system(size: 30)) .font(.system(size: 27))
.fontWeight(.bold) .fontWeight(.semibold)
.frame(maxWidth: .infinity).padding(10) .frame(maxWidth: .infinity).padding(10)
.multilineTextAlignment(.center) .multilineTextAlignment(.center)
.overlay { .overlay {
AllInColors.primaryGradient.frame(width: 170) switch isDisabled{
.mask( case true:
Text("Participer") AllInColors.grey700Color.frame(width: 170)
.font(.system(size: 30)) .mask(
.fontWeight(.bold) Text("Participer")
.frame(maxWidth: .infinity).padding(10) .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 @Binding var isModalPresented: Bool
@State var isModalParticipated: Bool = false @State var isModalParticipated: Bool = false
@State var progressValue: Float = 0.2 @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 var id: String
@StateObject private var viewModel: DetailsViewModel @StateObject private var viewModel: DetailsViewModel
@ -20,7 +59,7 @@ struct DetailsView: View {
ZStack(alignment: .bottom) { ZStack(alignment: .bottom) {
VStack(alignment: .center) { VStack(alignment: .center) {
HStack{ 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() Spacer()
Image("closeIcon") Image("closeIcon")
.resizable() .resizable()
@ -32,7 +71,7 @@ struct DetailsView: View {
Spacer() Spacer()
} }
.padding(.horizontal, 15) .padding(.horizontal, 15)
.background(Color.green) .background(StatusValues.1)
.transition(.slideInFromBottom(yOffset:0)) .transition(.slideInFromBottom(yOffset:0))
VStack(spacing: 0) { VStack(spacing: 0) {
VStack(alignment: .leading,spacing: 5){ VStack(alignment: .leading,spacing: 5){
@ -73,7 +112,9 @@ struct DetailsView: View {
.padding(.all,15).padding(.vertical, 10) .padding(.all,15).padding(.vertical, 10)
.background(AllInColors.componentBackgroundColor) .background(AllInColors.componentBackgroundColor)
.cornerRadius(20, corners: [.topLeft,.topRight]).padding(.bottom,0) .cornerRadius(20, corners: [.topLeft,.topRight]).padding(.bottom,0)
ResultBanner() if isFinished {
ResultBanner()
}
VStack(alignment: .leading, spacing: 15) { VStack(alignment: .leading, spacing: 15) {
BetLineLoading(value: $progressValue).padding(.vertical, 15) BetLineLoading(value: $progressValue).padding(.vertical, 15)
Spacer() Spacer()
@ -91,7 +132,7 @@ struct DetailsView: View {
.background(AllInColors.componentBackgroundColor) .background(AllInColors.componentBackgroundColor)
.cornerRadius(15) .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. /// The user's own participation in the bet.
public private(set) var userParticipation: Participation public private(set) var userParticipation: Participation
public private(set) var finalAnswer: String?
/// Custom Constructor /// Custom Constructor
/// ///
/// - Parameters: /// - Parameters:
@ -29,10 +31,15 @@ public class BetDetail: ObservableObject {
/// - answers: Details about the answers available for the bet. /// - answers: Details about the answers available for the bet.
/// - participations: List of user participations in the bet. /// - participations: List of user participations in the bet.
/// - userParticipation: The user's own participation 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.bet = bet
self.answers = answers self.answers = answers
self.participations = participations self.participations = participations
self.userParticipation = userParticipation self.userParticipation = userParticipation
self.finalAnswer = finalAnswer
} }
public func updateFinalAnswer(newFinalAnswer: String) {
self.finalAnswer = newFinalAnswer
}
} }

@ -35,7 +35,7 @@ struct Stub {
let bet1 = BinaryBet( let bet1 = BinaryBet(
theme: "Football - Finale de la Ligue des Champions", theme: "Football - Finale de la Ligue des Champions",
phrase: "Le gagnant de la finale sera l'équipe avec le plus de tirs au but.", 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), endBetDate: Date().addingTimeInterval(172800),
totalStakes: 100, totalStakes: 100,
isPublic: true, isPublic: true,
@ -91,7 +91,7 @@ struct Stub {
} }
public mutating func add(bet: Bet) { 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) self.betsDetail.append(newBetDetail)
} }
} }

Loading…
Cancel
Save