Added and used the bet status enum instead of dates, and set the size of the betLineLoading

pull/23/head
Emre KARTAL 1 year ago
parent 65c49e1b40
commit ff9e9f6ed2

@ -80,7 +80,7 @@ struct BetCard_Previews: PreviewProvider {
endRegisterDate: Date().addingTimeInterval(86400),
endBetDate: Date().addingTimeInterval(172800),
isPublic: true,
status: .FINISHED,
status: .inProgress,
invited: [],
author: User(username: "Imri", email: "emre.kartal@etu.uca.fr", nbCoins: 75, friends: []),
registered: []))

@ -33,19 +33,20 @@ struct BetLineLoading: View {
}
var body: some View {
GeometryReader { geometry in
VStack(alignment: .leading,spacing: 0) {
HStack(spacing: 5){
Text("OUI")
.font(.system(size: 25))
.fontWeight(.bold)
.foregroundColor(AllInColors.blue200)
Spacer()
Text("NON")
.font(.system(size: 25))
.fontWeight(.bold)
.foregroundColor(AllInColors.pink100)
}
VStack(alignment: .leading, spacing: 0) {
HStack(spacing: 5) {
Text("OUI")
.font(.system(size: 25))
.fontWeight(.bold)
.foregroundColor(AllInColors.blue200)
Spacer()
Text("NON")
.font(.system(size: 25))
.fontWeight(.bold)
.foregroundColor(AllInColors.pink100)
}
GeometryReader { geometry in
ZStack(alignment: .leading) {
HStack{
Spacer()
@ -54,7 +55,7 @@ struct BetLineLoading: View {
.foregroundStyle(AllInColors.PinkBetGradiant).cornerRadius(999)
}
HStack(spacing: 0){
HStack(spacing: 0) {
Rectangle()
.frame(width: min(CGFloat(self.value) * geometry.size.width, geometry.size.width), height: 17)
.foregroundStyle(AllInColors.BlueBetGradiant)
@ -67,101 +68,99 @@ struct BetLineLoading: View {
}
.padding(.bottom, 5)
}
.frame(height: 40)
HStack {
Spacer()
Text("Détails")
.textStyle(weight: .medium, color: AllInColors.primaryTextColor, size: 10)
Image(showInfos ? "chevronUpIcon" : "chevronDownIcon")
.resizable()
.frame(width: 10, height: 7)
.scaledToFill()
HStack {
Spacer()
Text("Détails")
.textStyle(weight: .medium, color: AllInColors.primaryTextColor, size: 10)
Image(showInfos ? "chevronUpIcon" : "chevronDownIcon")
.resizable()
.frame(width: 10, height: 7)
.scaledToFill()
}
.onTapGesture {
withAnimation {
showInfos.toggle()
}
.onTapGesture {
withAnimation {
showInfos.toggle()
}
.padding(.bottom, 5)
.padding(.trailing, 5)
if showInfos {
VStack(spacing: 1) {
HStack(spacing: 5) {
Image("blueAllCoinIcon")
.resizable()
.frame(width:12, height: 12)
Text(yesParticipations.reduce(0, {x,y in x + y.stake}).description)
.font(.system(size: 15))
.fontWeight(.bold)
.foregroundColor(AllInColors.blue200)
Spacer()
Text(noParticipations.reduce(0, {x,y in x + y.stake}).description)
.font(.system(size: 15))
.fontWeight(.bold)
.foregroundColor(AllInColors.pink100)
Image("pinkAllCoinIcon")
.resizable()
.frame(width: 12, height: 12)
}
}
.padding(.bottom, 5)
.padding(.trailing, 5)
if showInfos {
VStack(spacing: 1){
HStack(spacing: 5){
Image("blueAllCoinIcon")
.resizable()
.frame(width:12, height: 12)
Text(yesParticipations.reduce(0, {x,y in x + y.stake}).description)
.font(.system(size: 15))
.fontWeight(.bold)
.foregroundColor(AllInColors.blue200)
Spacer()
Text(noParticipations.reduce(0, {x,y in x + y.stake}).description)
.font(.system(size: 15))
.fontWeight(.bold)
.foregroundColor(AllInColors.pink100)
Image("pinkAllCoinIcon")
.resizable()
.frame(width: 12, height: 12)
}
HStack(spacing: 5){
Image("bluePersonIcon")
.resizable()
.frame(width: 12, height: 12)
Text(yesParticipations.count.description)
.font(.system(size: 15))
.fontWeight(.bold)
.foregroundColor(AllInColors.blue200)
Spacer()
Text(noParticipations.count.description)
.font(.system(size: 15))
.fontWeight(.bold)
.foregroundColor(AllInColors.pink100)
Image("pinkPersonIcon")
.resizable()
.frame(width: 12, height: 12)
}
HStack(spacing: 5){
Image("blueBadgeIcon")
.resizable()
.frame(width: 12, height: 12)
Text(yesParticipations.max(by: { $0.stake < $1.stake })?.stake.description ?? "0")
.font(.system(size: 15))
.fontWeight(.bold)
.foregroundColor(AllInColors.blue200)
Spacer()
Text(noParticipations.max(by: { $0.stake < $1.stake })?.stake.description ?? "0")
.font(.system(size: 15))
.fontWeight(.bold)
.foregroundColor(AllInColors.pink100)
Image("pinkBadgeIcon")
.resizable()
.frame(width: 12, height: 12)
}
HStack(spacing: 5){
Image("blueTrophyIcon")
.resizable()
.frame(width: 12, height: 12)
Text("1.2")
.font(.system(size: 15))
.fontWeight(.bold)
.foregroundColor(AllInColors.blue200)
Spacer()
Text("1.2")
.font(.system(size: 15))
.fontWeight(.bold)
.foregroundColor(AllInColors.pink100)
Image("pinkTrophyIcon")
.resizable()
.frame(width:12, height: 12)
}
HStack(spacing: 5){
Image("bluePersonIcon")
.resizable()
.frame(width: 12, height: 12)
Text(yesParticipations.count.description)
.font(.system(size: 15))
.fontWeight(.bold)
.foregroundColor(AllInColors.blue200)
Spacer()
Text(noParticipations.count.description)
.font(.system(size: 15))
.fontWeight(.bold)
.foregroundColor(AllInColors.pink100)
Image("pinkPersonIcon")
.resizable()
.frame(width: 12, height: 12)
}
HStack(spacing: 5){
Image("blueBadgeIcon")
.resizable()
.frame(width: 12, height: 12)
Text(yesParticipations.max(by: { $0.stake < $1.stake })?.stake.description ?? "0")
.font(.system(size: 15))
.fontWeight(.bold)
.foregroundColor(AllInColors.blue200)
Spacer()
Text(noParticipations.max(by: { $0.stake < $1.stake })?.stake.description ?? "0")
.font(.system(size: 15))
.fontWeight(.bold)
.foregroundColor(AllInColors.pink100)
Image("pinkBadgeIcon")
.resizable()
.frame(width: 12, height: 12)
}
HStack(spacing: 5){
Image("blueTrophyIcon")
.resizable()
.frame(width: 12, height: 12)
Text("1.2")
.font(.system(size: 15))
.fontWeight(.bold)
.foregroundColor(AllInColors.blue200)
Spacer()
Text("1.2")
.font(.system(size: 15))
.fontWeight(.bold)
.foregroundColor(AllInColors.pink100)
Image("pinkTrophyIcon")
.resizable()
.frame(width:12, height: 12)
}
}
Spacer()
}
}
}

@ -15,16 +15,14 @@ struct ParticipateButton: View {
var bet: Bet?
var isDisabled: Bool {
guard let endRegisterDate = bet?.endRegisterDate else {
return true
}
let currentDate = Date()
switch currentDate.compare(endRegisterDate) {
case .orderedAscending:
return false
case .orderedDescending, .orderedSame:
if let betType = bet?.status {
switch betType {
case .inProgress:
return false
default:
return true
}
} else {
return true
}
}

@ -38,7 +38,7 @@ class CreationBetViewModel: ObservableObject {
resetAllFieldErrors()
if let user = AppStateContainer.shared.user {
manager.addBet(bet: toBet(theme: theme, description: description, endRegister: endRegisterDate, endBet: endBetDate, isPublic: isPublic, status: .IN_PROGRESS, creator: user, type: selectedOption)) { statusCode in
manager.addBet(bet: toBet(theme: theme, description: description, endRegister: endRegisterDate, endBet: endBetDate, isPublic: isPublic, status: .inProgress, creator: user, type: selectedOption)) { statusCode in
switch statusCode {
case 201:
self.betAdded = true

@ -13,7 +13,7 @@ class CurrentBetViewModel: ObservableObject {
@Inject var manager: Manager
@Published private(set) var bets: [Bet] = []
@Published private(set) var bets: [BetDetail] = []
init() {
getItems()
@ -21,7 +21,10 @@ class CurrentBetViewModel: ObservableObject {
func getItems() {
manager.getCurrentBets(withIndex: 0, withCount: 20) { bets in
self.bets = bets
for bet in bets {
let betDetail = BetDetail(bet: bet, answers: [AnswerDetail(response: "OUI", totalStakes: 120, totalParticipants: 2, highestStake: 200, odds: 1.2), AnswerDetail(response: "NON", totalStakes: 120, totalParticipants: 2, highestStake: 200, odds: 1.2)], participations: [])
self.bets.append(betDetail)
}
}
}

@ -14,10 +14,8 @@ struct CurrentBetView: View {
@StateObject private var viewModel = CurrentBetViewModel()
@Binding var showMenu: Bool
@State private var showingSheet = false
var betD: BetDetail = BetStubManager().getABetDetail()
var body: some View {
VStack(alignment: .center, spacing: 0) {
TopBar(showMenu: self.$showMenu)
@ -26,8 +24,8 @@ struct CurrentBetView: View {
.textStyle(weight: .bold, color: AllInColors.grey500Color, size: 25)
.padding([.top],15)
VStack(spacing: 20){
ForEach(viewModel.bets, id: \.id) { (bet: Bet) in
ReviewCard(betDetail: betD, amountBetted: 110, isAWin: false)
ForEach(viewModel.bets, id: \.bet.id) { (bet: BetDetail) in
ReviewCard(betDetail: bet, amountBetted: 110, isAWin: false)
}
}
.padding([.trailing, .leading, .bottom],25)

@ -13,36 +13,20 @@ struct DetailsView: View {
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:
if let betType = viewModel.betDetail?.bet.status {
switch betType {
case .inProgress:
return ("En cours...", AllInColors.darkPurpleColor)
case .orderedDescending:
case .waiting:
return ("En attente...", AllInColors.pink100)
case .orderedSame:
case .closing:
return ("Fin des inscriptions...", AllInColors.grey50Color)
case .finished:
return ("Terminé", AllInColors.grey100Color)
case .cancelled:
return ("Annulé", AllInColors.grey100Color)
}
} else {
return ("Statut indisponible", AllInColors.pink100)
}
@ -150,7 +134,6 @@ struct DetailsView: View {
Spacer()
}
.frame(maxWidth: /*@START_MENU_TOKEN@*/.infinity/*@END_MENU_TOKEN@*/, maxHeight: .infinity)
.padding([.bottom,.trailing,.leading], 15)
.background(AllInColors.underComponentBackgroundColor)
.border(width: 1, edges: [.top], color: AllInColors.delimiterGrey)

@ -56,7 +56,7 @@ public class FactoryApiBet: FactoryBet {
return nil
}
return toBet(id: id, theme: theme, description: phrase, endRegister: endRegisterDate, endBet: endBetDate, isPublic: isPublic, status: .FINISHED, creator: User(username: createdBy, email: createdBy, nbCoins: 0, friends: []), type: type)
return toBet(id: id, theme: theme, description: phrase, endRegister: endRegisterDate, endBet: endBetDate, isPublic: isPublic, status: .finished, creator: User(username: createdBy, email: createdBy, nbCoins: 0, friends: []), type: type)
}
public func toBet(id: String, theme: String, description: String, endRegister: Date, endBet: Date, isPublic: Bool, status: BetStatus, creator: User, type: String) -> Bet {

@ -12,7 +12,6 @@ public class CustomBetResponse {
/// The name or description of the custom bet response.
public var name: String
/// Custom Constructor
///
/// - Parameters:

@ -8,5 +8,5 @@
import Foundation
public enum BetStatus {
case WAITING, IN_PROGRESS, FINISHED
case inProgress, waiting, closing, finished, cancelled
}

@ -38,7 +38,7 @@ struct Stub {
endRegisterDate: Date().addingTimeInterval(-86400),
endBetDate: Date().addingTimeInterval(172800),
isPublic: true,
status: .IN_PROGRESS,
status: .inProgress,
invited: [],
author: user1,
registered: [user2]
@ -51,7 +51,7 @@ struct Stub {
endRegisterDate: Date().addingTimeInterval(172800),
endBetDate: Date().addingTimeInterval(259200),
isPublic: false,
status: .IN_PROGRESS,
status: .inProgress,
invited: [user3],
author: user1,
registered: [user2]
@ -64,7 +64,7 @@ struct Stub {
endRegisterDate: Date().addingTimeInterval(259200),
endBetDate: Date().addingTimeInterval(345600),
isPublic: true,
status: .FINISHED,
status: .finished,
invited: [],
author: user1,
registered: [user2, user1, user3]
@ -77,7 +77,7 @@ struct Stub {
endRegisterDate: Date().addingTimeInterval(345600),
endBetDate: Date().addingTimeInterval(432000),
isPublic: false,
status: .FINISHED,
status: .finished,
invited: [user1],
author: user2,
registered: [user3]

Loading…
Cancel
Save