Skip to content

Commit

Permalink
Setting screen in iOS client to set leagues
Browse files Browse the repository at this point in the history
  • Loading branch information
joreilly committed Sep 2, 2023
1 parent 36f2534 commit 7e62526
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ fun SettingsView(viewModel: FantasyPremierLeagueViewModel, popBackStack: () -> U
})
Button(onClick = {
viewModel.updateLeagues(leagueIdsString.value.split(", "))
//viewModel.updateLeagues(listOf("2263", "622004"))
}) {
Text("Set Leagues")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
1AA7EE3E25D809D000B4DECB /* FixtureDetailView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1AA7EE3D25D809D000B4DECB /* FixtureDetailView.swift */; };
1ABD670625C5F8FF009FA782 /* ViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1ABD670525C5F8FF009FA782 /* ViewModel.swift */; };
1AD9A1232AA2692800B14FE3 /* CollectionConcurrencyKit in Frameworks */ = {isa = PBXBuildFile; productRef = 1AD9A1222AA2692800B14FE3 /* CollectionConcurrencyKit */; };
1AD9A1252AA355F500B14FE3 /* SettingsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1AD9A1242AA355F500B14FE3 /* SettingsView.swift */; };
1AE9AE7E2A29470800F439E1 /* KMPNativeCoroutinesAsync in Frameworks */ = {isa = PBXBuildFile; productRef = 1AE9AE7D2A29470800F439E1 /* KMPNativeCoroutinesAsync */; };
1AE9AE802A29470800F439E1 /* KMPNativeCoroutinesCore in Frameworks */ = {isa = PBXBuildFile; productRef = 1AE9AE7F2A29470800F439E1 /* KMPNativeCoroutinesCore */; };
/* End PBXBuildFile section */
Expand All @@ -36,6 +37,7 @@
1A45B23E25CB3C9C00A8C613 /* FixtureListView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FixtureListView.swift; sourceTree = "<group>"; };
1AA7EE3D25D809D000B4DECB /* FixtureDetailView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FixtureDetailView.swift; sourceTree = "<group>"; };
1ABD670525C5F8FF009FA782 /* ViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewModel.swift; sourceTree = "<group>"; };
1AD9A1242AA355F500B14FE3 /* SettingsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsView.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -81,6 +83,7 @@
1A0F7AEA25C5C97000EB34CF /* Info.plist */,
1A0F7AE725C5C97000EB34CF /* Preview Content */,
1ABD670525C5F8FF009FA782 /* ViewModel.swift */,
1AD9A1242AA355F500B14FE3 /* SettingsView.swift */,
);
path = FantasyPremierLeague;
sourceTree = "<group>";
Expand Down Expand Up @@ -223,6 +226,7 @@
1A45B23B25CB3BF100A8C613 /* PlayerDetailsView.swift in Sources */,
1A1D2B32289EA235000149CC /* LeagueListView.swift in Sources */,
1A45B23825CB3BBE00A8C613 /* PlayerListView.swift in Sources */,
1AD9A1252AA355F500B14FE3 /* SettingsView.swift in Sources */,
1A45B23F25CB3C9C00A8C613 /* FixtureListView.swift in Sources */,
1A0F7AE425C5C96F00EB34CF /* ContentView.swift in Sources */,
1ABD670625C5F8FF009FA782 /* ViewModel.swift in Sources */,
Expand Down
10 changes: 4 additions & 6 deletions ios/FantasyPremierLeague/FantasyPremierLeague/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,10 @@ struct ContentView: View {
.tabItem {
Label("Fixtues", systemImage: "clock")
}
if (!viewModel.leagues.isEmpty) {
LeagueListView(viewModel: viewModel)
.tabItem {
Label("League", systemImage: "list.number")
}
}
LeagueListView(viewModel: viewModel)
.tabItem {
Label("League", systemImage: "list.number")
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,42 +8,48 @@ extension LeagueResultDto: Identifiable { }
extension EventStatusDto: Identifiable { }



struct LeagueListView: View {
@ObservedObject var viewModel: FantasyPremierLeagueViewModel

var body: some View {
VStack(alignment: .center) {
if let eventStatusList = viewModel.eventStatusList {
NavigationStack {
VStack(alignment: .center) {
if let eventStatusList = viewModel.eventStatusList {
List {
Section(header: Text("Status"), content: {
ForEach(eventStatusList.status) { eventStatus in
InfoRowView(label: eventStatus.date, value: eventStatus.bonus_added.description)
}
})
}
.frame(height: 200)
}

let leagueStandingsList = viewModel.leagueStandings
List {
Section(header: Text("Status"), content: {
ForEach(eventStatusList.status) { eventStatus in
InfoRowView(label: eventStatus.date, value: eventStatus.bonus_added.description)
}
})
ForEach(leagueStandingsList) { leagueStandings in
Section(header: Text(leagueStandings.league.name), content: {
ForEach(leagueStandings.standings.results) { leagueResult in
LeagueReesultView(leagueResult: leagueResult)
}

})
}

}
.frame(height: 200)
}

let leagueStandingsList = viewModel.leagueStandings
List {
ForEach(leagueStandingsList) { leagueStandings in
Section(header: Text(leagueStandings.league.name), content: {
ForEach(leagueStandings.standings.results) { leagueResult in
LeagueReesultView(leagueResult: leagueResult)
}

})
.refreshable {
await viewModel.getLeageStandings()
}

}
.refreshable {
await viewModel.getLeageStandings()
}
.navigationBarTitle(Text("Leagues"))
.navigationBarTitleDisplayMode(.inline)
.navigationBarItems(trailing:
NavigationLink(destination: SettingsView(viewModel: viewModel)) {
Image(systemName: "gearshape")
}
)
}
.task {
await viewModel.getLeageStandings()
}

}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ struct PlayerListView: View {
}
.searchable(text: $viewModel.query)
.navigationBarTitle(Text("Players"))
.navigationBarTitleDisplayMode(.inline)
.navigationBarItems(trailing:
NavigationLink(destination: SettingsView(viewModel: viewModel)) {
Image(systemName: "gearshape")
}
)
}
.task {
await viewModel.getPlayers()
Expand Down
19 changes: 19 additions & 0 deletions ios/FantasyPremierLeague/FantasyPremierLeague/SettingsView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import SwiftUI

struct SettingsView: View {
@ObservedObject var viewModel: FantasyPremierLeagueViewModel

var body: some View {
NavigationStack {
Form {
TextField("Leagues", text: $viewModel.leagueListString)

Button("Save") {
viewModel.setLeagues()
}
}
.navigationBarTitle("Settings")
}
}
}

19 changes: 11 additions & 8 deletions ios/FantasyPremierLeague/FantasyPremierLeague/ViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ class FantasyPremierLeagueViewModel: ObservableObject {
@Published var leagueStandings = [LeagueStandingsDto]()
@Published var eventStatusList: EventStatusListDto? = nil

@Published public var leagues = [String]()
@Published var leagues = [String]()
@Published var leagueListString = ""

@Published var query: String = ""

Expand All @@ -28,14 +29,12 @@ class FantasyPremierLeagueViewModel: ObservableObject {
self.repository = repository

Task {
// TEMP to set a particular league until settings screen added
repository.updateLeagues(leagues: ["622004", "2263"])


do {
let leagueStream = asyncSequence(for: repository.leagues)
for try await data in leagueStream {
self.leagues = data
leagues = data
leagueListString = leagues.joined(separator: ",")
await getLeageStandings()
}

} catch {
Expand Down Expand Up @@ -82,11 +81,10 @@ class FantasyPremierLeagueViewModel: ObservableObject {

func getLeageStandings() async {
do {
print("getLeageStandings, leagues = \(leagues)")
self.leagueStandings = try await leagues.asyncCompactMap { leagueIdString in
if let leagueId = Int32(leagueIdString) {
return try await asyncFunction(for: repository.getLeagueStandings(leagueId: Int32(leagueId)))
//self.leagueStandings = leagueStandings
//print(self.leagueStandings!)
} else {
return nil
}
Expand Down Expand Up @@ -121,6 +119,11 @@ class FantasyPremierLeagueViewModel: ObservableObject {
}


func setLeagues() {
let leagues = leagueListString.components(separatedBy:", ")
print("setLeagues, leagues = \(leagues)")
repository.updateLeagues(leagues: leagues)
}
}


Expand Down

0 comments on commit 7e62526

Please sign in to comment.