Add View CurrentBet

pull/21/head
Emre KARTAL 1 year ago
parent ef15072a22
commit 86b6e0c765

@ -86,17 +86,26 @@ struct Menu: View {
.padding([.leading,.trailing], 13) .padding([.leading,.trailing], 13)
} }
NavigationLink(destination: MainView(page: "Bet").navigationBarBackButtonHidden(true)) VStack {
{ NavigationLink(destination: MainView(page: "Bet").navigationBarBackButtonHidden(true))
ParameterMenu(image: "moneyImage", title: "BET EN COURS", description: "Gérez vos bets et récompensez les gagnants.") {
.padding([.leading,.trailing], 13) ParameterMenu(image: "moneyImage", title: "BET EN COURS", description: "Gérez vos bets et récompensez les gagnants.")
.padding([.leading,.trailing], 13)
}
NavigationLink(destination: MainView(page: "Ranking").navigationBarBackButtonHidden(true))
{
ParameterMenu(image: "rankingImage", title: "CLASSEMENT", description: "Consultez votre classement parmis vos amis.")
.padding([.leading,.trailing], 13)
}
} }
NavigationLink(destination: MainView(page: "Ranking").navigationBarBackButtonHidden(true))
NavigationLink(destination: MainView(page: "Current").navigationBarBackButtonHidden(true))
{ {
ParameterMenu(image: "rankingImage", title: "CLASSEMENT", description: "Consultez votre classement parmis vos amis.") ParameterMenu(image: "eyesImage", title: "BETS EN COURS", description: "Consultez vos paris en cours.")
.padding([.leading,.trailing], 13) .padding([.leading,.trailing], 13)
} }
HStack { HStack {
Spacer() Spacer()
Button { Button {

@ -0,0 +1,28 @@
//
// CurrentBetViewModel.swift
// AllIn
//
// Created by Emre on 31/01/2024.
//
import Foundation
import DependencyInjection
import Model
class CurrentBetViewModel: ObservableObject {
@Inject var manager: Manager
@Published private(set) var bets: [Bet] = []
init() {
getItems()
}
func getItems() {
manager.getCurrentBets(withIndex: 0, withCount: 20) { bets in
self.bets = bets
}
}
}

@ -0,0 +1,42 @@
//
// CurrentBetView.swift
// AllIn
//
// Created by Emre on 31/01/2024.
//
import SwiftUI
import Model
struct CurrentBetView: View {
@StateObject private var viewModel = CurrentBetViewModel()
@Binding var showMenu: Bool
@State private var showingSheet = false
var body: some View {
VStack(alignment: .center, spacing: 0) {
TopBar(showMenu: self.$showMenu)
ScrollView(showsIndicators: false) {
Text("En cours")
.textStyle(weight: .bold, color: AllInColors.grey500Color, size: 25)
.padding([.top],15)
VStack(spacing: 20){
ForEach(viewModel.bets, id: \.id) { (bet: Bet) in
ReviewCard(amountBetted: 110, isAWin: false)
}
}
.padding([.trailing, .leading, .bottom],25)
}
.refreshable {
viewModel.getItems()
}
Spacer()
}
.edgesIgnoringSafeArea(.bottom)
.background(AllInColors.backgroundColor)
}
}

@ -9,7 +9,6 @@ import SwiftUI
struct HistoricBetView: View { struct HistoricBetView: View {
@StateObject private var viewModel = BetViewModel()
@Binding var showMenu: Bool @Binding var showMenu: Bool
@State private var showingSheet = false @State private var showingSheet = false

@ -46,6 +46,8 @@ struct MainView: View {
FriendsView(showMenu: self.$showMenu) FriendsView(showMenu: self.$showMenu)
case "CreationBet": case "CreationBet":
CreationBetView(showMenu: self.$showMenu) CreationBetView(showMenu: self.$showMenu)
case "Current":
CurrentBetView(showMenu: self.$showMenu)
default: default:
BetView(showMenu: self.$showMenu) BetView(showMenu: self.$showMenu)
} }

@ -23,6 +23,8 @@
EC01937E2B25C52E005D81E6 /* TopBar.swift in Sources */ = {isa = PBXBuildFile; fileRef = EC01937D2B25C52E005D81E6 /* TopBar.swift */; }; EC01937E2B25C52E005D81E6 /* TopBar.swift in Sources */ = {isa = PBXBuildFile; fileRef = EC01937D2B25C52E005D81E6 /* TopBar.swift */; };
EC01FCC32B56650400BB2390 /* DetailsViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = EC01FCC22B56650400BB2390 /* DetailsViewModel.swift */; }; EC01FCC32B56650400BB2390 /* DetailsViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = EC01FCC22B56650400BB2390 /* DetailsViewModel.swift */; };
EC01FCC52B56791B00BB2390 /* HistoricBetViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = EC01FCC42B56791B00BB2390 /* HistoricBetViewModel.swift */; }; EC01FCC52B56791B00BB2390 /* HistoricBetViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = EC01FCC42B56791B00BB2390 /* HistoricBetViewModel.swift */; };
EC17A15E2B6A955E008A8679 /* CurrentBetView.swift in Sources */ = {isa = PBXBuildFile; fileRef = EC17A15D2B6A955E008A8679 /* CurrentBetView.swift */; };
EC17A1602B6A9781008A8679 /* CurrentBetViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = EC17A15F2B6A9781008A8679 /* CurrentBetViewModel.swift */; };
EC3077072B24CB840060E34D /* SplashView.swift in Sources */ = {isa = PBXBuildFile; fileRef = EC3077062B24CB840060E34D /* SplashView.swift */; }; EC3077072B24CB840060E34D /* SplashView.swift in Sources */ = {isa = PBXBuildFile; fileRef = EC3077062B24CB840060E34D /* SplashView.swift */; };
EC3077092B24CF7F0060E34D /* Colors.swift in Sources */ = {isa = PBXBuildFile; fileRef = EC3077082B24CF7F0060E34D /* Colors.swift */; }; EC3077092B24CF7F0060E34D /* Colors.swift in Sources */ = {isa = PBXBuildFile; fileRef = EC3077082B24CF7F0060E34D /* Colors.swift */; };
EC30770B2B24D9160060E34D /* WelcomeView.swift in Sources */ = {isa = PBXBuildFile; fileRef = EC30770A2B24D9160060E34D /* WelcomeView.swift */; }; EC30770B2B24D9160060E34D /* WelcomeView.swift in Sources */ = {isa = PBXBuildFile; fileRef = EC30770A2B24D9160060E34D /* WelcomeView.swift */; };
@ -123,6 +125,8 @@
EC01937D2B25C52E005D81E6 /* TopBar.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TopBar.swift; sourceTree = "<group>"; }; EC01937D2B25C52E005D81E6 /* TopBar.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TopBar.swift; sourceTree = "<group>"; };
EC01FCC22B56650400BB2390 /* DetailsViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DetailsViewModel.swift; sourceTree = "<group>"; }; EC01FCC22B56650400BB2390 /* DetailsViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DetailsViewModel.swift; sourceTree = "<group>"; };
EC01FCC42B56791B00BB2390 /* HistoricBetViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HistoricBetViewModel.swift; sourceTree = "<group>"; }; EC01FCC42B56791B00BB2390 /* HistoricBetViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HistoricBetViewModel.swift; sourceTree = "<group>"; };
EC17A15D2B6A955E008A8679 /* CurrentBetView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CurrentBetView.swift; sourceTree = "<group>"; };
EC17A15F2B6A9781008A8679 /* CurrentBetViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CurrentBetViewModel.swift; sourceTree = "<group>"; };
EC3077062B24CB840060E34D /* SplashView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SplashView.swift; sourceTree = "<group>"; }; EC3077062B24CB840060E34D /* SplashView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SplashView.swift; sourceTree = "<group>"; };
EC3077082B24CF7F0060E34D /* Colors.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Colors.swift; sourceTree = "<group>"; }; EC3077082B24CF7F0060E34D /* Colors.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Colors.swift; sourceTree = "<group>"; };
EC30770A2B24D9160060E34D /* WelcomeView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WelcomeView.swift; sourceTree = "<group>"; }; EC30770A2B24D9160060E34D /* WelcomeView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WelcomeView.swift; sourceTree = "<group>"; };
@ -309,6 +313,7 @@
1244EF5F2B4EC31E00374ABF /* HistoricBetView.swift */, 1244EF5F2B4EC31E00374ABF /* HistoricBetView.swift */,
123590B32B51792000F7AEBD /* DetailsView.swift */, 123590B32B51792000F7AEBD /* DetailsView.swift */,
123225D82B67B46100D30BB3 /* BetEndingValidationView.swift */, 123225D82B67B46100D30BB3 /* BetEndingValidationView.swift */,
EC17A15D2B6A955E008A8679 /* CurrentBetView.swift */,
); );
path = Views; path = Views;
sourceTree = "<group>"; sourceTree = "<group>";
@ -367,6 +372,7 @@
ECB26A1A2B40746C00FE06B3 /* FriendsViewModel.swift */, ECB26A1A2B40746C00FE06B3 /* FriendsViewModel.swift */,
EC01FCC22B56650400BB2390 /* DetailsViewModel.swift */, EC01FCC22B56650400BB2390 /* DetailsViewModel.swift */,
EC01FCC42B56791B00BB2390 /* HistoricBetViewModel.swift */, EC01FCC42B56791B00BB2390 /* HistoricBetViewModel.swift */,
EC17A15F2B6A9781008A8679 /* CurrentBetViewModel.swift */,
); );
path = ViewModels; path = ViewModels;
sourceTree = "<group>"; sourceTree = "<group>";
@ -526,11 +532,13 @@
ECB26A192B40744F00FE06B3 /* RankingViewModel.swift in Sources */, ECB26A192B40744F00FE06B3 /* RankingViewModel.swift in Sources */,
EC650A502B2793D5003AFCAD /* TextCapsule.swift in Sources */, EC650A502B2793D5003AFCAD /* TextCapsule.swift in Sources */,
EC650A482B25DCFF003AFCAD /* UsersPreview.swift in Sources */, EC650A482B25DCFF003AFCAD /* UsersPreview.swift in Sources */,
EC17A15E2B6A955E008A8679 /* CurrentBetView.swift in Sources */,
EC650A462B25D686003AFCAD /* RankingRow.swift in Sources */, EC650A462B25D686003AFCAD /* RankingRow.swift in Sources */,
EC01937A2B25C12B005D81E6 /* BetCard.swift in Sources */, EC01937A2B25C12B005D81E6 /* BetCard.swift in Sources */,
EC650A422B25C817003AFCAD /* Friend.swift in Sources */, EC650A422B25C817003AFCAD /* Friend.swift in Sources */,
EC7A882F2B28E6BE004F226A /* ConfidentialityButton.swift in Sources */, EC7A882F2B28E6BE004F226A /* ConfidentialityButton.swift in Sources */,
ECB7BC702B336E28002A6654 /* RegisterViewModel.swift in Sources */, ECB7BC702B336E28002A6654 /* RegisterViewModel.swift in Sources */,
EC17A1602B6A9781008A8679 /* CurrentBetViewModel.swift in Sources */,
EC650A4C2B25E9C7003AFCAD /* RankingView.swift in Sources */, EC650A4C2B25E9C7003AFCAD /* RankingView.swift in Sources */,
EC7A882B2B28D1E0004F226A /* DropDownMenu.swift in Sources */, EC7A882B2B28D1E0004F226A /* DropDownMenu.swift in Sources */,
EC7A882D2B28D8A1004F226A /* CreationBetView.swift in Sources */, EC7A882D2B28D8A1004F226A /* CreationBetView.swift in Sources */,

@ -51,6 +51,36 @@ public struct UserApiManager: UserDataManager {
fatalError("Not implemented yet") fatalError("Not implemented yet")
} }
public func getCurrentBets(withIndex index: Int, withCount count: Int, completion: @escaping ([Bet]) -> Void) {
let url = URL(string: allInApi + "bets/current")!
var request = URLRequest(url: url)
request.httpMethod = "GET"
request.setValue("application/json", forHTTPHeaderField: "Content-Type")
request.setValue("Bearer \(token)", forHTTPHeaderField: "Authorization")
var bets: [Bet] = []
URLSession.shared.dataTask(with: request) { data, response, error in
if let data = data {
print ("ALLIN : get current bets")
do {
if let httpResponse = response as? HTTPURLResponse, let jsonArray = try JSONSerialization.jsonObject(with: data, options: []) as? [[String: Any]] {
for json in jsonArray {
if let bet = FactoryApiBet().toBet(from: json) {
bets.append(bet)
}
}
print(httpResponse.statusCode)
completion(bets)
}
} catch {
print("Error parsing JSON: \(error)")
}
}
}.resume()
}
public func addParticipation(withId id: String, withAnswer answer: String, andStake stake: Int, completion : @escaping (Int)-> ()) { public func addParticipation(withId id: String, withAnswer answer: String, andStake stake: Int, completion : @escaping (Int)-> ()) {
let url = URL(string: allInApi + "participations/add")! let url = URL(string: allInApi + "participations/add")!
var request = URLRequest(url: url) var request = URLRequest(url: url)

@ -40,6 +40,12 @@ public struct Manager {
} }
} }
public func getCurrentBets(withIndex index: Int, withCount count: Int, completion: @escaping ([Bet]) -> Void) {
userDataManager.getCurrentBets(withIndex: index, withCount: count) { bets in
completion(bets)
}
}
public func addParticipation(withId id: String, withAnswer answer: String, andStake stake: Int, completion : @escaping (Int)-> ()) { public func addParticipation(withId id: String, withAnswer answer: String, andStake stake: Int, completion : @escaping (Int)-> ()) {
userDataManager.addParticipation(withId: id, withAnswer: answer, andStake: stake) { status in userDataManager.addParticipation(withId: id, withAnswer: answer, andStake: stake) { status in
completion(status) completion(status)

@ -12,5 +12,6 @@ public protocol UserDataManager {
func addBet(bet: Bet, completion : @escaping (Int)-> ()) func addBet(bet: Bet, completion : @escaping (Int)-> ())
func getFriends() -> [User] func getFriends() -> [User]
func getOldBets(withIndex index: Int, withCount count: Int, completion: @escaping ([Bet]) -> Void) func getOldBets(withIndex index: Int, withCount count: Int, completion: @escaping ([Bet]) -> Void)
func getCurrentBets(withIndex index: Int, withCount count: Int, completion: @escaping ([Bet]) -> Void)
func addParticipation(withId id: String, withAnswer answer: String, andStake stake: Int, completion : @escaping (Int)-> ()) func addParticipation(withId id: String, withAnswer answer: String, andStake stake: Int, completion : @escaping (Int)-> ())
} }

Loading…
Cancel
Save