From 7390f5767bc54dd684fe9a3383981754626cae99 Mon Sep 17 00:00:00 2001 From: ludelanier Date: Sun, 21 Jan 2024 16:02:36 +0100 Subject: [PATCH] add list of user in detailview --- .../BleueCoin.imageset/Contents.json | 21 ++++++++ .../BleueCoin.imageset/Group 107 (1).png | Bin 0 -> 681 bytes .../PurpleAllCoin.imageset/Contents.json | 21 ++++++++ .../PurpleAllCoin.imageset/Vector (3).png | Bin 0 -> 1131 bytes .../AllIn/Components/BetLineLoading.swift | 48 +++++++++++++----- .../AllIn/Components/ParticiationCell.swift | 29 +++++++++++ .../AllInApp/AllIn/Views/DetailsView.swift | 16 ++++-- .../AllInApp.xcodeproj/project.pbxproj | 4 ++ Sources/Model/Sources/Model/Bet.swift | 4 ++ Sources/Model/Sources/Model/BetDetail.swift | 10 ++++ .../Model/Sources/Model/Participation.swift | 6 ++- Sources/StubLib/Sources/StubLib/Stub.swift | 6 +++ 12 files changed, 148 insertions(+), 17 deletions(-) create mode 100644 Sources/AllInApp/AllIn/Assets.xcassets/BleueCoin.imageset/Contents.json create mode 100644 Sources/AllInApp/AllIn/Assets.xcassets/BleueCoin.imageset/Group 107 (1).png create mode 100644 Sources/AllInApp/AllIn/Assets.xcassets/PurpleAllCoin.imageset/Contents.json create mode 100644 Sources/AllInApp/AllIn/Assets.xcassets/PurpleAllCoin.imageset/Vector (3).png create mode 100644 Sources/AllInApp/AllIn/Components/ParticiationCell.swift diff --git a/Sources/AllInApp/AllIn/Assets.xcassets/BleueCoin.imageset/Contents.json b/Sources/AllInApp/AllIn/Assets.xcassets/BleueCoin.imageset/Contents.json new file mode 100644 index 0000000..67a98bf --- /dev/null +++ b/Sources/AllInApp/AllIn/Assets.xcassets/BleueCoin.imageset/Contents.json @@ -0,0 +1,21 @@ +{ + "images" : [ + { + "filename" : "Group 107 (1).png", + "idiom" : "universal", + "scale" : "1x" + }, + { + "idiom" : "universal", + "scale" : "2x" + }, + { + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/Sources/AllInApp/AllIn/Assets.xcassets/BleueCoin.imageset/Group 107 (1).png b/Sources/AllInApp/AllIn/Assets.xcassets/BleueCoin.imageset/Group 107 (1).png new file mode 100644 index 0000000000000000000000000000000000000000..d982a56c3fa043a8c4b0c7e109628eead0745cfb GIT binary patch literal 681 zcmV;a0#^NrP)@~0drDELIAGL9O(c600d`2O+f$vv5yPra20PYFM4U!vlJWyVlJ`*N6g1G^l0C58!A+NN|;2G!>ww9He zx`}N`mXiM=oUXMCbA^BlAUgNOBf+J-K9#od1SabB^4FYHyXFN` z0Gc)lX~v(@HY{L*^5xGN0+pO?3IQU(xog~O&Zy4`PgW48H2-v$L##QdfBBU9TJ?ZF z&YZ}N&O6_M-f6Cp>jxYrD|&b48u>9~LGLtY;HD5%E8ZoKJU7aHE@SFhJz*dT#8_JQz7*Dc_xyqhm=@fggQl%!83L zZWMnC+psL2*L>UcZa5E_hafk`?WHVUxidqv-MUm6^Qp+W#uCN-#b}-T5-0AuBUY%9 zbMe2s1EEI6&2@dch5)@;-syGo(e*@gA-u@Bv2)>lyV-&p?xCO7h_r>Wpo P00000NkvXXu0mjfC#62> literal 0 HcmV?d00001 diff --git a/Sources/AllInApp/AllIn/Assets.xcassets/PurpleAllCoin.imageset/Contents.json b/Sources/AllInApp/AllIn/Assets.xcassets/PurpleAllCoin.imageset/Contents.json new file mode 100644 index 0000000..1904c47 --- /dev/null +++ b/Sources/AllInApp/AllIn/Assets.xcassets/PurpleAllCoin.imageset/Contents.json @@ -0,0 +1,21 @@ +{ + "images" : [ + { + "filename" : "Vector (3).png", + "idiom" : "universal", + "scale" : "1x" + }, + { + "idiom" : "universal", + "scale" : "2x" + }, + { + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/Sources/AllInApp/AllIn/Assets.xcassets/PurpleAllCoin.imageset/Vector (3).png b/Sources/AllInApp/AllIn/Assets.xcassets/PurpleAllCoin.imageset/Vector (3).png new file mode 100644 index 0000000000000000000000000000000000000000..2ae155ae0e4345897b9fa73f1db22db9f217316a GIT binary patch literal 1131 zcmV-x1eE)UP)@~0drDELIAGL9O(c600d`2O+f$vv5yPrw6366k7Q>zLp^{*R|LoKriG__N7(dzMe?ZT0eXlfOZJiLPA z(&G-TYw`hcK&>aAQl}luA)+uGnCvgFVCWyO?QMYspG@`_2P7g|^&q|yqJSsVbHkY))K}TjINt&y-G?rj-LWP0tNc1pT7-D+g?v zo*NLM@VE>VZJeGP3N@`1(6ydig%_}(NYhFIo$I;6XPz9IfRG|ht0{`q2ba8SP53na z0XeyvmIhSUVP8J&UIBzjJX00~W3V7k)6#%saBCs~BYM{Vbx0SQmMiL7&nTF@{T94} zoP(Mc22?*51Lt}^;B0Hl1Z+6a85RcQX+gJo(r(A1Zn>HW#t&FF5Kvz~C)wVX8!+CH zz^$INUomcn&mgA*VYoAunP0)h(rq|?u$l8v)9Rw1)igJtdp)D!q3v~RdN5!zYkj=l zGefp*8q$H)Dn0hY6^tLMxB~&lncg$AgJ-2FMU-lKI3T(nd$xv!@B1w)O+im9CYtUA z)Ou3IDLDzH)q`YILm*mJk&tS-UqPpOa7 zrJk{x_w8}j{cQ)|kX-b4E9gv5u3FIg2Bz2zzO{{AFSEgco;br*>s+#khbu4!OVWT& z^yIESUT0Rd-DOY@?`Pay%)o-T3f8Ts4j0k6bP-+pHHh-wlxUU)taZgiP2m!xqnf!M z*Twb8b3jH`C*EF71?pBiX7{dFItYj}K-o;n!7 zh=2G=bbT{K|AzXxoL0DuO>yO4Zg23(p!8g=3Fw%x9lRVp)HeM4JhFM*nZ{h3G~rjHy!MakJGVjK=lM^X^M~i) xd2_zu)Ls1iq=62Q9&5y-8;?5?ZkuJt_#bX(sxlpmL9_q>002ovPDHLkV1huR2zUSh literal 0 HcmV?d00001 diff --git a/Sources/AllInApp/AllIn/Components/BetLineLoading.swift b/Sources/AllInApp/AllIn/Components/BetLineLoading.swift index ba9dc95..8bf0d58 100644 --- a/Sources/AllInApp/AllIn/Components/BetLineLoading.swift +++ b/Sources/AllInApp/AllIn/Components/BetLineLoading.swift @@ -6,13 +6,37 @@ // import SwiftUI +import Model struct BetLineLoading: View { - @Binding var value: Float + @State var participations: [Participation] + + var value: CGFloat { + let totalParticipations = participations.count + let numberOfYes = participations.filter { $0.response == "OUI" }.count + let numberOfNo = participations.filter { $0.response == "NON" }.count + if(numberOfNo == 0 && numberOfYes == 0){ + return 0.5 + } + + return totalParticipations > 0 ? CGFloat(numberOfYes) / CGFloat(totalParticipations) : 0.0 + } + + + + var yesParticipations: [Participation] { + return participations.filter { $0.response == "OUI" } + } + + var noParticipations: [Participation] { + return participations.filter { $0.response == "NON" } + } + + var body: some View { GeometryReader { geometry in - VStack(spacing: 0){ + VStack(alignment: .leading,spacing: 0){ HStack(spacing: 5){ Text("OUI").font(.system(size: 25)).fontWeight(.bold).foregroundColor(AllInColors.bleue200) Spacer() @@ -36,31 +60,31 @@ struct BetLineLoading: View { } VStack(spacing: 1){ HStack(spacing: 5){ - Image("BleueBadge").resizable().frame(width:10, height: 14) - Text("1.2").font(.system(size: 15)).fontWeight(.bold).foregroundColor(AllInColors.bleue200) + 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.bleue200) Spacer() - Text("1.2").font(.system(size: 15)).fontWeight(.bold).foregroundColor(AllInColors.pink100) + Text(noParticipations.reduce(0, {x,y in x + y.stake}).description).font(.system(size: 15)).fontWeight(.bold).foregroundColor(AllInColors.pink100) Image("PinkBadge").resizable().frame(width:10, height: 14) } HStack(spacing: 5){ - Image("BleueBadge").resizable().frame(width:10, height: 14) - Text("1.2").font(.system(size: 15)).fontWeight(.bold).foregroundColor(AllInColors.bleue200) + Image("BleuePersonIcon").resizable().frame(width:14, height: 12) + Text(yesParticipations.count.description).font(.system(size: 15)).fontWeight(.bold).foregroundColor(AllInColors.bleue200) Spacer() - Text("1.2").font(.system(size: 15)).fontWeight(.bold).foregroundColor(AllInColors.pink100) + Text(noParticipations.count.description).font(.system(size: 15)).fontWeight(.bold).foregroundColor(AllInColors.pink100) Image("PinkBadge").resizable().frame(width:10, height: 14) } HStack(spacing: 5){ Image("BleueBadge").resizable().frame(width:10, height: 14) - Text("1.2").font(.system(size: 15)).fontWeight(.bold).foregroundColor(AllInColors.bleue200) + Text(yesParticipations.max(by: { $0.stake < $1.stake })?.stake.description ?? "0").font(.system(size: 15)).fontWeight(.bold).foregroundColor(AllInColors.bleue200) Spacer() - Text("1.2").font(.system(size: 15)).fontWeight(.bold).foregroundColor(AllInColors.pink100) + Text(noParticipations.max(by: { $0.stake < $1.stake })?.stake.description ?? "0").font(.system(size: 15)).fontWeight(.bold).foregroundColor(AllInColors.pink100) Image("PinkBadge").resizable().frame(width:10, height: 14) } HStack(spacing: 5){ - Image("BleueBadge").resizable().frame(width:10, height: 14) + Image("BleueTrophyIcon").resizable().frame(width:14, height: 13) Text("1.2").font(.system(size: 15)).fontWeight(.bold).foregroundColor(AllInColors.bleue200) Spacer() Text("1.2").font(.system(size: 15)).fontWeight(.bold).foregroundColor(AllInColors.pink100) @@ -70,7 +94,7 @@ struct BetLineLoading: View { } } - } + }.frame(height: 140) } } diff --git a/Sources/AllInApp/AllIn/Components/ParticiationCell.swift b/Sources/AllInApp/AllIn/Components/ParticiationCell.swift new file mode 100644 index 0000000..735f808 --- /dev/null +++ b/Sources/AllInApp/AllIn/Components/ParticiationCell.swift @@ -0,0 +1,29 @@ +// +// ParticiationCell.swift +// AllIn +// +// Created by Lucas Delanier on 21/01/2024. +// + +import SwiftUI +import Model + +struct ParticiationCell: View { + @State var participation: Participation? + var body: some View { + HStack(alignment: .center, spacing: 0){ + Circle().frame(width: 30, height: 30).foregroundColor(AllInColors.grey700Color).padding(.trailing, 5) + Text(participation?.user.username ?? "Unknown") + .font(.system(size: 15)) + .foregroundStyle(AllInColors.grey100Color) + .fontWeight(.semibold) + Spacer() + Text(participation?.stake.description ?? "NaN") + .font(.system(size: 18)) + .foregroundStyle(AllInColors.lightPurpleColor) + .fontWeight(.bold).padding(.trailing, 5) + Image("PurpleAllCoin").resizable().frame(width: 11, height: 12) + } + } +} + diff --git a/Sources/AllInApp/AllIn/Views/DetailsView.swift b/Sources/AllInApp/AllIn/Views/DetailsView.swift index 8701c81..fdf23ca 100644 --- a/Sources/AllInApp/AllIn/Views/DetailsView.swift +++ b/Sources/AllInApp/AllIn/Views/DetailsView.swift @@ -1,4 +1,5 @@ import SwiftUI +import Model struct DetailsView: View { @@ -106,7 +107,7 @@ struct DetailsView: View { .foregroundColor(AllInColors.grey800Color) TextCapsule(date: viewModel.betDetail?.bet.endBetDate ?? Date()) Spacer() - + } } .frame(width: .infinity) @@ -116,8 +117,17 @@ struct DetailsView: View { if isFinished { ResultBanner() } - VStack(alignment: .leading, spacing: 15) { - BetLineLoading(value: $progressValue).padding(.vertical, 15) + VStack(alignment: .leading, spacing: 5) { + BetLineLoading(participations: viewModel.betDetail!.participations).padding(.vertical,15) + Text("Liste des participants") + .font(.system(size: 18)) + .foregroundStyle(AllInColors.grey100Color) + .fontWeight(.bold) + .padding(.bottom, 10) + ForEach(viewModel.betDetail?.participations ?? []) { (participation: Participation) in + ParticiationCell(participation: participation).padding(.horizontal, 10) + } + Spacer() } .frame(maxWidth: /*@START_MENU_TOKEN@*/.infinity/*@END_MENU_TOKEN@*/, maxHeight: .infinity) diff --git a/Sources/AllInApp/AllInApp.xcodeproj/project.pbxproj b/Sources/AllInApp/AllInApp.xcodeproj/project.pbxproj index f394329..3fbc216 100644 --- a/Sources/AllInApp/AllInApp.xcodeproj/project.pbxproj +++ b/Sources/AllInApp/AllInApp.xcodeproj/project.pbxproj @@ -15,6 +15,7 @@ 1244EF602B4EC31E00374ABF /* HistoricBetView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1244EF5F2B4EC31E00374ABF /* HistoricBetView.swift */; }; 1244EF622B4EC67000374ABF /* ReviewCard.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1244EF612B4EC67000374ABF /* ReviewCard.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 */; }; EC01937A2B25C12B005D81E6 /* BetCard.swift in Sources */ = {isa = PBXBuildFile; fileRef = EC0193792B25C12B005D81E6 /* BetCard.swift */; }; EC01937C2B25C2A8005D81E6 /* AllcoinsCounter.swift in Sources */ = {isa = PBXBuildFile; fileRef = EC01937B2B25C2A8005D81E6 /* AllcoinsCounter.swift */; }; @@ -113,6 +114,7 @@ 1244EF5F2B4EC31E00374ABF /* HistoricBetView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HistoricBetView.swift; sourceTree = ""; }; 1244EF612B4EC67000374ABF /* ReviewCard.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReviewCard.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 = ""; }; EC0193792B25C12B005D81E6 /* BetCard.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BetCard.swift; sourceTree = ""; }; EC01937B2B25C2A8005D81E6 /* AllcoinsCounter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AllcoinsCounter.swift; sourceTree = ""; }; @@ -335,6 +337,7 @@ 120919172B56D0AE00D0FA29 /* ParticipationModal.swift */, 120919192B56DC6C00D0FA29 /* DropDownAnswerMenu.swift */, 12C370472B5A5EE500CD9F0F /* BetLineLoading.swift */, + 12C370492B5D5BD000CD9F0F /* ParticiationCell.swift */, ); path = Components; sourceTree = ""; @@ -539,6 +542,7 @@ EC3077072B24CB840060E34D /* SplashView.swift in Sources */, EC01937E2B25C52E005D81E6 /* TopBar.swift in Sources */, ECA9D1CB2B2DA2320076E0EC /* DropDownFriends.swift in Sources */, + 12C3704A2B5D5BD000CD9F0F /* ParticiationCell.swift in Sources */, 123590B82B5541BA00F7AEBD /* ParticipateButton.swift in Sources */, EC01FCC32B56650400BB2390 /* DetailsViewModel.swift in Sources */, ECB26A1B2B40746C00FE06B3 /* FriendsViewModel.swift in Sources */, diff --git a/Sources/Model/Sources/Model/Bet.swift b/Sources/Model/Sources/Model/Bet.swift index b99b7c2..4ad6268 100644 --- a/Sources/Model/Sources/Model/Bet.swift +++ b/Sources/Model/Sources/Model/Bet.swift @@ -90,4 +90,8 @@ public class Bet: ObservableObject, Identifiable { self.author = author self.registered = registered } + + public func addRegistered(newUser: User){ + self.registered.append(newUser) + } } diff --git a/Sources/Model/Sources/Model/BetDetail.swift b/Sources/Model/Sources/Model/BetDetail.swift index 8e55642..d492e8f 100644 --- a/Sources/Model/Sources/Model/BetDetail.swift +++ b/Sources/Model/Sources/Model/BetDetail.swift @@ -42,4 +42,14 @@ public class BetDetail: ObservableObject { public func updateFinalAnswer(newFinalAnswer: String) { self.finalAnswer = newFinalAnswer } + + public func addParticipation(newParticipation: Participation){ + if !self.bet.registered.contains(where: { existingUser in + return existingUser.email == newParticipation.user.email + }) { + self.bet.addRegistered(newUser: newParticipation.user) + } + + self.participations.append(newParticipation) + } } diff --git a/Sources/Model/Sources/Model/Participation.swift b/Sources/Model/Sources/Model/Participation.swift index 4040e22..9b5d088 100644 --- a/Sources/Model/Sources/Model/Participation.swift +++ b/Sources/Model/Sources/Model/Participation.swift @@ -8,8 +8,9 @@ import Foundation /// A class representing a user's participation in a bet. -public class Participation: ObservableObject { - +public class Participation: ObservableObject, Identifiable{ + + public let id: UUID /// The amount of stake in the bet. public private(set) var stake: Int @@ -39,5 +40,6 @@ public class Participation: ObservableObject { self.response = response self.user = user self.betId = betId + self.id = UUID() } } diff --git a/Sources/StubLib/Sources/StubLib/Stub.swift b/Sources/StubLib/Sources/StubLib/Stub.swift index 646abe3..2692c33 100644 --- a/Sources/StubLib/Sources/StubLib/Stub.swift +++ b/Sources/StubLib/Sources/StubLib/Stub.swift @@ -88,6 +88,12 @@ struct Stub { let betDetail = BetDetail(bet: bet, answers: [], participations: [], userParticipation: Participation(stake: 0, date: Date(), response: "", user: user1, betId: "")) self.betsDetail.append(betDetail) } + + self.betsDetail[0].addParticipation(newParticipation: Participation(stake: 120, date: Date(), response: "OUI", user: user1, betId: "1")) + self.betsDetail[0].addParticipation(newParticipation: Participation(stake: 20, date: Date(), response: "NON", user: user2, betId: "2")) + self.betsDetail[0].addParticipation(newParticipation: Participation(stake: 320, date: Date(), response: "OUI", user: user3, betId: "3")) + self.betsDetail[0].addParticipation(newParticipation: Participation(stake: 320, date: Date(), response: "OUI", user: user3, betId: "3")) + } public mutating func add(bet: Bet) {