diff --git a/Sources/AllInApp/AllIn/Components/ChoiceFinalAnswerCell.swift b/Sources/AllInApp/AllIn/Components/ChoiceFinalAnswerCell.swift new file mode 100644 index 0000000..eeefe0f --- /dev/null +++ b/Sources/AllInApp/AllIn/Components/ChoiceFinalAnswerCell.swift @@ -0,0 +1,32 @@ +// +// ChoiceFinalAnswerCell.swift +// AllIn +// +// Created by Lucas Delanier on 29/01/2024. +// + +import Foundation +import SwiftUI +import Model + +struct ChoiceFinalAnswerCell: View { + + var selected = false + var answer: AnswerDetail + var rawColor = AllInColors.blueAccentColor + + var body: some View { + ZStack{ + HStack{ + Spacer() + Text(answer.response) + .textStyle(weight: .bold, color: selected ? AllInColors.whiteColor :rawColor, size: 40).padding(.vertical, 10) + Spacer() + } + HStack{ + Spacer() + OddCapsule(backgroundColor: selected ? AllInColors.whiteColor : AllInColors.purpleAccentColor, foregroundColor: selected ? AllInColors.purpleAccentColor : AllInColors.whiteColor ,odd: answer.odds ).padding(.trailing,20).scaleEffect(0.9) + } + }.background(selected ? AllInColors.purpleAccentColor : AllInColors.whiteColor).cornerRadius(17) + } +} diff --git a/Sources/AllInApp/AllIn/Components/OddCapsule.swift b/Sources/AllInApp/AllIn/Components/OddCapsule.swift new file mode 100644 index 0000000..f4dc9bb --- /dev/null +++ b/Sources/AllInApp/AllIn/Components/OddCapsule.swift @@ -0,0 +1,33 @@ +// +// OddCapsule.swift +// AllIn +// +// Created by Lucas Delanier on 03/02/2024. +// + +import Foundation +import SwiftUI + +struct OddCapsule: View { + var backgroundColor: Color = AllInColors.purpleAccentColor + var foregroundColor: Color = AllInColors.whiteColor + var odd: Float = 0.0 + var body: some View { + HStack(alignment: .center) { + Text("x\(odd.description)") + .fontWeight(.bold) + .foregroundColor(foregroundColor) + } + .padding(.horizontal, 10) + .padding(.vertical,5) + .background(backgroundColor) + .cornerRadius(9999) + + } +} + +struct OddCapsule_Previews: PreviewProvider { + static var previews: some View { + AllcoinsCounter() + } +} diff --git a/Sources/AllInApp/AllIn/Components/ReviewCard.swift b/Sources/AllInApp/AllIn/Components/ReviewCard.swift index 1730ff8..91f0cfe 100644 --- a/Sources/AllInApp/AllIn/Components/ReviewCard.swift +++ b/Sources/AllInApp/AllIn/Components/ReviewCard.swift @@ -6,11 +6,12 @@ // import SwiftUI +import Model struct ReviewCard: View { @State var showDetails: Bool = false @State var showPartipated: Bool = false - + @State var betDetail: BetDetail var amountBetted: Int var isAWin: Bool var body: some View { @@ -18,14 +19,14 @@ struct ReviewCard: View { VStack(alignment: .leading,spacing: 2){ HStack{ Spacer() - Text("proposé par Lucas").font(.system(size: 10)).foregroundColor(AllInColors.grey800Color) + Text("proposé par \(betDetail.bet.author.username)").font(.system(size: 10)).foregroundColor(AllInColors.grey800Color) } - Text("Etudes").font(.system(size: 15)).foregroundColor(AllInColors.grey800Color) - Text("Emre va réussir son TP de CI/CD mercredi?").font(.system(size: 20)).fontWeight(.bold) + Text(betDetail.bet.theme).font(.system(size: 15)).foregroundColor(AllInColors.grey800Color) + Text(betDetail.bet.phrase).font(.system(size: 20)).fontWeight(.bold) HStack{ Text("Fini le").font(.system(size: 15)).foregroundColor(AllInColors.grey800Color) - TextCapsule(date: Date()) + TextCapsule(date: betDetail.bet.endBetDate) Spacer() } @@ -37,17 +38,24 @@ struct ReviewCard: View { VStack(alignment: .center,spacing:0){ HStack(){ Spacer() - Text(amountBetted.description) - .foregroundColor(.white) - .font(.system(size: 25)) - .fontWeight(.bold) - Image("allcoinWhiteIcon") - .resizable() - .frame(width: 20, height: 20, alignment: .bottom) - Text(isAWin ? "Gagnés!" : "Perdus!") - .foregroundColor(.white) - .font(.system(size: 25)) - .fontWeight(.bold) + if(betDetail.bet.isFinish()){ + Text("Terminé") + .foregroundColor(.white) + .font(.system(size: 25)) + .fontWeight(.bold) + } + else{Text(amountBetted.description) + .foregroundColor(.white) + .font(.system(size: 25)) + .fontWeight(.bold) + Image("allcoinWhiteIcon") + .resizable() + .frame(width: 20, height: 20, alignment: .bottom) + Text(isAWin ? "Gagnés!" : "Perdus!") + .foregroundColor(.white) + .font(.system(size: 25)) + .fontWeight(.bold) + } Spacer() } @@ -62,7 +70,7 @@ struct ReviewCard: View { .frame(width: .infinity) .padding(.all,2) .background( - isAWin ? + isAWin || betDetail.bet.isFinish() ? AnyView(AllInColors.primaryGradient) : AnyView(Color.black) ) .cornerRadius(20, corners: [.bottomLeft,.bottomRight]) diff --git a/Sources/AllInApp/AllIn/Components/WinModal.swift b/Sources/AllInApp/AllIn/Components/WinModal.swift index 84082f6..85544a8 100644 --- a/Sources/AllInApp/AllIn/Components/WinModal.swift +++ b/Sources/AllInApp/AllIn/Components/WinModal.swift @@ -78,7 +78,7 @@ struct InfiniteScroller: View { content() content() } - .offset(x: xOffset, y: 0) + .offset(x: xOffset, y: 0).opacity(0.3) } .disabled(true) .onAppear { @@ -89,9 +89,9 @@ struct InfiniteScroller: View { xOffset = +contentWidth } } - .frame(width: 1000, height: 1000) + .frame(width: 1300, height: 1300) .padding(.leading, -400) .rotationEffect(.degrees(30)) - .opacity(0.04) + .opacity(0.1) } } diff --git a/Sources/AllInApp/AllIn/Views/BetEndingValidationView.swift b/Sources/AllInApp/AllIn/Views/BetEndingValidationView.swift index b8be880..02b0eca 100644 --- a/Sources/AllInApp/AllIn/Views/BetEndingValidationView.swift +++ b/Sources/AllInApp/AllIn/Views/BetEndingValidationView.swift @@ -7,10 +7,14 @@ import Foundation import SwiftUI +import Model +import StubLib struct BetEndingValidation: View { @Environment(\.dismiss) var dismiss @State var xOffset: CGFloat = 0 + @State var selectedAnswer : String? + var bet: BetDetail = BetStubManager().getABetDetail() var body: some View { ZStack{ GeometryReader { geometry in @@ -32,18 +36,42 @@ struct BetEndingValidation: View { } } - HStack{ - Text("FÉLICITATIONS").font(.system(size: 20)).foregroundColor(.white).fontWeight(.semibold).italic() - Text("PSEUDO!").padding(.top,9).font(.system(size: 33)).fontWeight(.heavy).foregroundColor(.white) + ReviewCard(betDetail: bet, amountBetted: 0, isAWin: false).padding(.top, 20).padding(.bottom, 10) + Text("Ce bet est arrivé à la date de fin. Vous devez à présent distribuer les gains en validant le pari gagnant.") + .textStyle(weight: .regular, color: AllInColors.grey800Color, size: 13).multilineTextAlignment(.center) + Text("Veuillez choisir la réponse finale:") + .font(.system(size: 17)) + .foregroundStyle(AllInColors.whiteColor) + .fontWeight(.bold) + .padding(.top, 30) + .padding(.bottom, 10) + .frame(maxWidth: .infinity, alignment: .leading) + VStack(spacing: 14){ + ForEach(bet.answers, id: \.self) { answer in + ChoiceFinalAnswerCell(selected : answer.response == selectedAnswer, answer: answer).onTapGesture { + if(selectedAnswer == answer.response){ + selectedAnswer = nil + } + else { + selectedAnswer = answer.response + } + } + } } - .rotationEffect(.degrees(-4)) - .padding(.top,40) - - Spacer() - AllcoinsCapsule() - Spacer() - RecapBetCard() Spacer() + selectedAnswer != nil ? Button { + dismiss() + } label: { + Text("Valider") + .font(.system(size: 23)) + .foregroundColor(AllInColors.whiteColor) + .fontWeight(.bold) + .frame(maxWidth: .infinity) + .padding(.vertical, 3) + } + .buttonStyle(.borderedProminent) + .tint(AllInColors.purpleAccentColor) + : nil } .padding([.all],20) } @@ -52,3 +80,5 @@ struct BetEndingValidation: View { } } + + diff --git a/Sources/AllInApp/AllIn/Views/BetView.swift b/Sources/AllInApp/AllIn/Views/BetView.swift index 9f28940..62ab8dd 100644 --- a/Sources/AllInApp/AllIn/Views/BetView.swift +++ b/Sources/AllInApp/AllIn/Views/BetView.swift @@ -58,7 +58,7 @@ struct BetView: View { viewModel.getItems() } .sheet(isPresented: $showingSheet) { - WinModal() + BetEndingValidation() } Spacer() } diff --git a/Sources/AllInApp/AllIn/Views/HistoricBetView.swift b/Sources/AllInApp/AllIn/Views/HistoricBetView.swift index beaebcb..1981632 100644 --- a/Sources/AllInApp/AllIn/Views/HistoricBetView.swift +++ b/Sources/AllInApp/AllIn/Views/HistoricBetView.swift @@ -23,8 +23,8 @@ struct HistoricBetView: View { .textStyle(weight: .bold, color: AllInColors.grey500Color, size: 25) .padding([.top],15) VStack(spacing: 20){ - ReviewCard(amountBetted: 110, isAWin: true) - ReviewCard(amountBetted: 3, isAWin: false) +// ReviewCard(amountBetted: 110, isAWin: true) +// ReviewCard(amountBetted: 3, isAWin: false) } .padding([.trailing, .leading, .bottom],25) } diff --git a/Sources/AllInApp/AllInApp.xcodeproj/project.pbxproj b/Sources/AllInApp/AllInApp.xcodeproj/project.pbxproj index 9d640e0..def970a 100644 --- a/Sources/AllInApp/AllInApp.xcodeproj/project.pbxproj +++ b/Sources/AllInApp/AllInApp.xcodeproj/project.pbxproj @@ -10,11 +10,13 @@ 120919182B56D0AE00D0FA29 /* ParticipationModal.swift in Sources */ = {isa = PBXBuildFile; fileRef = 120919172B56D0AE00D0FA29 /* ParticipationModal.swift */; }; 1209191A2B56DC6C00D0FA29 /* DropDownAnswerMenu.swift in Sources */ = {isa = PBXBuildFile; fileRef = 120919192B56DC6C00D0FA29 /* DropDownAnswerMenu.swift */; }; 123225D92B67B46100D30BB3 /* BetEndingValidationView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 123225D82B67B46100D30BB3 /* BetEndingValidationView.swift */; }; + 123225DB2B67E41400D30BB3 /* ChoiceFinalAnswerCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 123225DA2B67E41400D30BB3 /* ChoiceFinalAnswerCell.swift */; }; 123590B42B51792000F7AEBD /* DetailsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 123590B32B51792000F7AEBD /* DetailsView.swift */; }; 123590B62B5537E200F7AEBD /* ResultBanner.swift in Sources */ = {isa = PBXBuildFile; fileRef = 123590B52B5537E200F7AEBD /* ResultBanner.swift */; }; 123590B82B5541BA00F7AEBD /* ParticipateButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 123590B72B5541BA00F7AEBD /* ParticipateButton.swift */; }; 1244EF602B4EC31E00374ABF /* HistoricBetView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1244EF5F2B4EC31E00374ABF /* HistoricBetView.swift */; }; 1244EF622B4EC67000374ABF /* ReviewCard.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1244EF612B4EC67000374ABF /* ReviewCard.swift */; }; + 129D051D2B6E7FF0003D3E08 /* OddCapsule.swift in Sources */ = {isa = PBXBuildFile; fileRef = 129D051C2B6E7FF0003D3E08 /* OddCapsule.swift */; }; 12C370482B5A5EE500CD9F0F /* BetLineLoading.swift in Sources */ = {isa = PBXBuildFile; fileRef = 12C370472B5A5EE500CD9F0F /* BetLineLoading.swift */; }; 12C3704A2B5D5BD000CD9F0F /* ParticiationCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 12C370492B5D5BD000CD9F0F /* ParticiationCell.swift */; }; EC0193782B25BF16005D81E6 /* AllcoinsCapsule.swift in Sources */ = {isa = PBXBuildFile; fileRef = EC0193772B25BF16005D81E6 /* AllcoinsCapsule.swift */; }; @@ -110,11 +112,13 @@ 122278B72B4BDE1100E632AA /* DependencyInjection.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = DependencyInjection.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 122278B92B4BDE9500E632AA /* Package.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = Package.swift; path = ../Model/Package.swift; sourceTree = ""; }; 123225D82B67B46100D30BB3 /* BetEndingValidationView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BetEndingValidationView.swift; sourceTree = ""; }; + 123225DA2B67E41400D30BB3 /* ChoiceFinalAnswerCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChoiceFinalAnswerCell.swift; sourceTree = ""; }; 123590B32B51792000F7AEBD /* DetailsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DetailsView.swift; sourceTree = ""; }; 123590B52B5537E200F7AEBD /* ResultBanner.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ResultBanner.swift; sourceTree = ""; }; 123590B72B5541BA00F7AEBD /* ParticipateButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ParticipateButton.swift; sourceTree = ""; }; 1244EF5F2B4EC31E00374ABF /* HistoricBetView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HistoricBetView.swift; sourceTree = ""; }; 1244EF612B4EC67000374ABF /* ReviewCard.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReviewCard.swift; sourceTree = ""; }; + 129D051C2B6E7FF0003D3E08 /* OddCapsule.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OddCapsule.swift; sourceTree = ""; }; 12C370472B5A5EE500CD9F0F /* BetLineLoading.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BetLineLoading.swift; sourceTree = ""; }; 12C370492B5D5BD000CD9F0F /* ParticiationCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ParticiationCell.swift; sourceTree = ""; }; EC0193772B25BF16005D81E6 /* AllcoinsCapsule.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AllcoinsCapsule.swift; sourceTree = ""; }; @@ -341,6 +345,8 @@ 120919192B56DC6C00D0FA29 /* DropDownAnswerMenu.swift */, 12C370472B5A5EE500CD9F0F /* BetLineLoading.swift */, 12C370492B5D5BD000CD9F0F /* ParticiationCell.swift */, + 123225DA2B67E41400D30BB3 /* ChoiceFinalAnswerCell.swift */, + 129D051C2B6E7FF0003D3E08 /* OddCapsule.swift */, ); path = Components; sourceTree = ""; @@ -540,6 +546,8 @@ EC30770D2B24DB7A0060E34D /* Extensions.swift in Sources */, EC6B96D82B24BF2100FC1C58 /* Menu.swift in Sources */, EC650A4E2B278EDB003AFCAD /* TrendingBetCard.swift in Sources */, + 123225DB2B67E41400D30BB3 /* ChoiceFinalAnswerCell.swift in Sources */, + 129D051D2B6E7FF0003D3E08 /* OddCapsule.swift in Sources */, 123225D92B67B46100D30BB3 /* BetEndingValidationView.swift in Sources */, EC0193782B25BF16005D81E6 /* AllcoinsCapsule.swift in Sources */, EC650A4A2B25DD58003AFCAD /* FriendsView.swift in Sources */, diff --git a/Sources/Model/Sources/Model/AnswerDetail.swift b/Sources/Model/Sources/Model/AnswerDetail.swift index 6474788..9b87ed4 100644 --- a/Sources/Model/Sources/Model/AnswerDetail.swift +++ b/Sources/Model/Sources/Model/AnswerDetail.swift @@ -8,8 +8,8 @@ import Foundation /// A class representing detailed information about a specific answer option for a bet. -public class AnswerDetail: ObservableObject { - +public class AnswerDetail: ObservableObject, Hashable { + /// The response or outcome associated with this answer. public private(set) var response: String @@ -40,4 +40,17 @@ public class AnswerDetail: ObservableObject { self.highestStake = highestStake self.odds = odds } + + public func hash(into hasher: inout Hasher) { + // Use properties that define the uniqueness of the instance for hashing + hasher.combine(response) + // ... (combine other properties) + } + + public static func == (lhs: AnswerDetail, rhs: AnswerDetail) -> Bool { + // Check equality based on properties + return lhs.response == rhs.response + // ... (check other properties) + } + } diff --git a/Sources/Model/Sources/Model/Bet.swift b/Sources/Model/Sources/Model/Bet.swift index 68d4427..861c6df 100644 --- a/Sources/Model/Sources/Model/Bet.swift +++ b/Sources/Model/Sources/Model/Bet.swift @@ -98,4 +98,8 @@ public class Bet: ObservableObject, Identifiable { public func addRegistered(newUser: User){ self.registered.append(newUser) } + + public func isFinish() -> Bool{ + self.endBetDate < Date() + } } diff --git a/Sources/StubLib/Sources/StubLib/BetStubManager.swift b/Sources/StubLib/Sources/StubLib/BetStubManager.swift index 7bb801f..fa9e5bc 100644 --- a/Sources/StubLib/Sources/StubLib/BetStubManager.swift +++ b/Sources/StubLib/Sources/StubLib/BetStubManager.swift @@ -29,4 +29,8 @@ public struct BetStubManager: BetDataManager { } } + public func getABetDetail() -> BetDetail{ + Stub.shared.betsDetail.first! + } + } diff --git a/Sources/StubLib/Sources/StubLib/Stub.swift b/Sources/StubLib/Sources/StubLib/Stub.swift index 5371b6c..7bcca01 100644 --- a/Sources/StubLib/Sources/StubLib/Stub.swift +++ b/Sources/StubLib/Sources/StubLib/Stub.swift @@ -85,7 +85,7 @@ struct Stub { self.bets.append(bet4) for bet in bets { - let betDetail = BetDetail(bet: bet, answers: [], participations: []) + 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.betsDetail.append(betDetail) }