changeset 17:8dac58bb4569

fix build bug
author Dennis C. M. <dennis@denniscm.com>
date Thu, 20 Oct 2022 18:07:51 +0200
parents 1011e56b7832
children d20cf93c9812
files GeoQuiz.xcodeproj/project.pbxproj GeoQuiz/Components/ProgressBarHelper.swift GeoQuiz/Components/RecentGameHelper.swift GeoQuiz/Components/UserProfileComponent.swift GeoQuiz/Components/UserProgressComponent.swift GeoQuiz/Components/UserProgressHelper.swift GeoQuiz/ProfileModalView.swift
diffstat 7 files changed, 131 insertions(+), 168 deletions(-) [+]
line wrap: on
line diff
--- a/GeoQuiz.xcodeproj/project.pbxproj	Thu Oct 20 13:49:42 2022 +0200
+++ b/GeoQuiz.xcodeproj/project.pbxproj	Thu Oct 20 18:07:51 2022 +0200
@@ -37,6 +37,7 @@
 		95919DBC28F08D0600F21F8F /* LinkHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95919DBB28F08D0600F21F8F /* LinkHelper.swift */; };
 		95AE8D5728C8750E0067F219 /* LoadFunc.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95AE8D5628C8750E0067F219 /* LoadFunc.swift */; };
 		95AF322A28DF293900023ACC /* GuessTheCountryView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95AF322928DF293900023ACC /* GuessTheCountryView.swift */; };
+		95B5C308290190900093A086 /* UserProgressHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95B5C307290190900093A086 /* UserProgressHelper.swift */; };
 		95BC392D28EC42570049AB49 /* CityMapHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95BC392C28EC42570049AB49 /* CityMapHelper.swift */; };
 		95C430F928D0A8E500480D23 /* GradientExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95C430F828D0A8E500480D23 /* GradientExtension.swift */; };
 		95C4315628C64A8C00212131 /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95C4315528C64A8C00212131 /* ContentView.swift */; };
@@ -49,11 +50,9 @@
 		95C6459A28FFE5A3000CD570 /* PlayedGame+CoreDataClass.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95C6459828FFE5A3000CD570 /* PlayedGame+CoreDataClass.swift */; };
 		95C6459B28FFE5A3000CD570 /* PlayedGame+CoreDataProperties.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95C6459928FFE5A3000CD570 /* PlayedGame+CoreDataProperties.swift */; };
 		95C6459D290003E1000CD570 /* RecentGameHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95C6459C290003E1000CD570 /* RecentGameHelper.swift */; };
-		95C645BE29011EF9000CD570 /* UserProgressComponent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95C645BD29011EF9000CD570 /* UserProgressComponent.swift */; };
 		95C645C029011F8E000CD570 /* GameStatsClass.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95C645BF29011F8E000CD570 /* GameStatsClass.swift */; };
 		95C645C229014442000CD570 /* GameInfoProtocol+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95C645C129014442000CD570 /* GameInfoProtocol+Extension.swift */; };
 		95C645C42901552B000CD570 /* UserProfileComponent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95C645C32901552B000CD570 /* UserProfileComponent.swift */; };
-		95C645C629015A06000CD570 /* ProgressBarHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95C645C529015A06000CD570 /* ProgressBarHelper.swift */; };
 		95CA295028F6BB4500CE0B7A /* ActivityAlertHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95CA294F28F6BB4500CE0B7A /* ActivityAlertHelper.swift */; };
 		95FA409A28D9876B00129B60 /* GuessTheFlagView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95FA409928D9876B00129B60 /* GuessTheFlagView.swift */; };
 		95FA409C28D9881100129B60 /* CountryGameClass.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95FA409B28D9881100129B60 /* CountryGameClass.swift */; };
@@ -90,6 +89,7 @@
 		95919DBB28F08D0600F21F8F /* LinkHelper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LinkHelper.swift; sourceTree = "<group>"; };
 		95AE8D5628C8750E0067F219 /* LoadFunc.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoadFunc.swift; sourceTree = "<group>"; };
 		95AF322928DF293900023ACC /* GuessTheCountryView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GuessTheCountryView.swift; sourceTree = "<group>"; };
+		95B5C307290190900093A086 /* UserProgressHelper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserProgressHelper.swift; sourceTree = "<group>"; };
 		95BC392C28EC42570049AB49 /* CityMapHelper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CityMapHelper.swift; sourceTree = "<group>"; };
 		95C430F828D0A8E500480D23 /* GradientExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GradientExtension.swift; sourceTree = "<group>"; };
 		95C4315528C64A8C00212131 /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = "<group>"; };
@@ -102,11 +102,9 @@
 		95C6459828FFE5A3000CD570 /* PlayedGame+CoreDataClass.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "PlayedGame+CoreDataClass.swift"; sourceTree = "<group>"; };
 		95C6459928FFE5A3000CD570 /* PlayedGame+CoreDataProperties.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "PlayedGame+CoreDataProperties.swift"; sourceTree = "<group>"; };
 		95C6459C290003E1000CD570 /* RecentGameHelper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RecentGameHelper.swift; sourceTree = "<group>"; };
-		95C645BD29011EF9000CD570 /* UserProgressComponent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserProgressComponent.swift; sourceTree = "<group>"; };
 		95C645BF29011F8E000CD570 /* GameStatsClass.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GameStatsClass.swift; sourceTree = "<group>"; };
 		95C645C129014442000CD570 /* GameInfoProtocol+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "GameInfoProtocol+Extension.swift"; sourceTree = "<group>"; };
 		95C645C32901552B000CD570 /* UserProfileComponent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserProfileComponent.swift; sourceTree = "<group>"; };
-		95C645C529015A06000CD570 /* ProgressBarHelper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProgressBarHelper.swift; sourceTree = "<group>"; };
 		95CA294F28F6BB4500CE0B7A /* ActivityAlertHelper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ActivityAlertHelper.swift; sourceTree = "<group>"; };
 		95E6188428DDDB5C003359ED /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist; path = Info.plist; sourceTree = "<group>"; };
 		95FA409928D9876B00129B60 /* GuessTheFlagView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GuessTheFlagView.swift; sourceTree = "<group>"; };
@@ -228,8 +226,7 @@
 				95CA294F28F6BB4500CE0B7A /* ActivityAlertHelper.swift */,
 				95C6456D28FE8C04000CD570 /* UserImageHelper.swift */,
 				95C6459C290003E1000CD570 /* RecentGameHelper.swift */,
-				95C645C529015A06000CD570 /* ProgressBarHelper.swift */,
-				95C645BD29011EF9000CD570 /* UserProgressComponent.swift */,
+				95B5C307290190900093A086 /* UserProgressHelper.swift */,
 				95C645C32901552B000CD570 /* UserProfileComponent.swift */,
 				952E41E828DC521200198643 /* GameAlertsModifier.swift */,
 				95C430F828D0A8E500480D23 /* GradientExtension.swift */,
@@ -341,7 +338,6 @@
 				95C645C029011F8E000CD570 /* GameStatsClass.swift in Sources */,
 				95AF322A28DF293900023ACC /* GuessTheCountryView.swift in Sources */,
 				95919DBC28F08D0600F21F8F /* LinkHelper.swift in Sources */,
-				95C645BE29011EF9000CD570 /* UserProgressComponent.swift in Sources */,
 				951AFAEF28E565FE00A4A4BD /* CountryModel.swift in Sources */,
 				95030CEA28D1BA4D001AA3A1 /* AnswerButtonHelper.swift in Sources */,
 				95FA409C28D9881100129B60 /* CountryGameClass.swift in Sources */,
@@ -353,13 +349,13 @@
 				9590359528E098FF00B24560 /* ProfileModalView.swift in Sources */,
 				955950BB28F15FF2001BDEE8 /* FormatterExtension.swift in Sources */,
 				95C6456C28FE87E4000CD570 /* UserDataModel.swift in Sources */,
-				95C645C629015A06000CD570 /* ProgressBarHelper.swift in Sources */,
 				95C6459B28FFE5A3000CD570 /* PlayedGame+CoreDataProperties.swift in Sources */,
 				951D197328D485E000671FAD /* ColorExtension.swift in Sources */,
 				95C6457228FFC4DC000CD570 /* ProfileEditModalView.swift in Sources */,
 				95C430F928D0A8E500480D23 /* GradientExtension.swift in Sources */,
 				952E41ED28DC658900198643 /* SettingsModalView.swift in Sources */,
 				95FA409A28D9876B00129B60 /* GuessTheFlagView.swift in Sources */,
+				95B5C308290190900093A086 /* UserProgressHelper.swift in Sources */,
 				951AFAF128E5735400A4A4BD /* CityGameClass.swift in Sources */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
--- a/GeoQuiz/Components/ProgressBarHelper.swift	Thu Oct 20 13:49:42 2022 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,38 +0,0 @@
-//
-//  ProgressBarHelper.swift
-//  GeoQuiz
-//
-//  Created by Dennis Concepción Martín on 20/10/22.
-//
-
-import SwiftUI
-
-struct ProgressBar: View {
-    let pctScore: Double
-    let gradient: Gradient
-    
-    var body: some View {
-        GeometryReader { geo in
-            ZStack(alignment: .leading) {
-                Capsule()
-                    .foregroundColor(.customBackground)
-                    .frame(height: 6)
-                
-                Capsule()
-                    .fill(
-                        LinearGradient(
-                            gradient: gradient,
-                            startPoint: .trailing, endPoint: .leading
-                        )
-                    )
-                    .frame(width: geo.size.width * pctScore, height: 6)
-            }
-        }
-    }
-}
-
-struct ProgressBar_Previews: PreviewProvider {
-    static var previews: some View {
-        ProgressBar(pctScore: 0.3, gradient: .main)
-    }
-}
--- a/GeoQuiz/Components/RecentGameHelper.swift	Thu Oct 20 13:49:42 2022 +0200
+++ b/GeoQuiz/Components/RecentGameHelper.swift	Thu Oct 20 18:07:51 2022 +0200
@@ -42,13 +42,9 @@
             Spacer()
             
             Text("\(game.score, format: .number) ⭐️")
+                .font(.headline)
             
         }
-        .padding()
-        .background(
-            RoundedRectangle(cornerRadius: 20)
-                .foregroundColor(.white)
-        )
     }
     
     init(game: PlayedGame) {
--- a/GeoQuiz/Components/UserProfileComponent.swift	Thu Oct 20 13:49:42 2022 +0200
+++ b/GeoQuiz/Components/UserProfileComponent.swift	Thu Oct 20 18:07:51 2022 +0200
@@ -28,11 +28,6 @@
             
             Spacer()
         }
-        .padding()
-        .background(
-            RoundedRectangle(cornerRadius: 20)
-                .foregroundColor(.white)
-        )
     }
 }
 
--- a/GeoQuiz/Components/UserProgressComponent.swift	Thu Oct 20 13:49:42 2022 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,82 +0,0 @@
-//
-//  GameProgressHelper.swift
-//  GeoQuiz
-//
-//  Created by Dennis Concepción Martín on 20/10/22.
-//
-
-import SwiftUI
-
-struct UserProgress: View {
-    private let games: [(key: String, value: GameProgress)]
-    
-    var body: some View {
-        VStack(alignment: .leading) {
-            VStack(spacing: 10) {
-                ForEach(games, id: \.key) { game in
-                    HStack {
-                        Text(game.key)
-                            .font(.headline)
-                        
-                        Spacer()
-                        
-                        Text("\(game.value.highestScore) of \(game.value.numberOfQuestions)")
-                            .font(.caption)
-                            .foregroundColor(.secondary)
-                    }
-                    
-                    ProgressBar(pctScore: game.value.pctScore, gradient: game.value.gradient)
-                    
-                    if game.key != games.last!.key {
-                        Divider()
-                    }
-                }
-            }
-        }
-        .padding()
-        .background(
-            RoundedRectangle(cornerRadius: 20)
-                .foregroundColor(.white)
-        )
-    }
-    
-    init(playedGames: FetchedResults<PlayedGame>) {
-        let flagGames = playedGames.filter { $0.type == .guessTheFlag }
-        let capitalGames = playedGames.filter { $0.type == .guessTheCapital }
-        let countryGames = playedGames.filter { $0.type == .guessTheCountry }
-        let populationGames = playedGames.filter { $0.type == .guessThePopulation }
-        
-        self.games = [
-            GuessTheFlagInfo.name: GameProgress(
-                numberOfQuestions: GuessTheFlagInfo.numberOfQuestions,
-                highestScore: Int(flagGames.max { $0.score < $1.score }?.score ?? 0),
-                gradient: GuessTheFlagInfo.gradient
-            ),
-            GuessTheCapitalInfo.name: GameProgress(
-                numberOfQuestions: GuessTheCapitalInfo.numberOfQuestions,
-                highestScore: Int(capitalGames.max { $0.score < $1.score }?.score ?? 0),
-                gradient: GuessTheCapitalInfo.gradient
-            ),
-            GuessTheCountryInfo.name: GameProgress(
-                numberOfQuestions: GuessTheCountryInfo.numberOfQuestions,
-                highestScore: Int(countryGames.max { $0.score < $1.score }?.score ?? 0),
-                gradient: GuessTheCountryInfo.gradient
-            ),
-            GuessThePopulationInfo.name: GameProgress(
-                numberOfQuestions: GuessThePopulationInfo.numberOfQuestions,
-                highestScore: Int(populationGames.max { $0.score < $1.score }?.score ?? 0),
-                gradient: GuessThePopulationInfo.gradient
-            )
-        ].sorted { $0.value.pctScore > $1.value.pctScore }
-    }
-    
-    private struct GameProgress {
-        let numberOfQuestions: Int
-        let highestScore: Int
-        var pctScore: Double {
-            Double(highestScore) / Double(numberOfQuestions)
-        }
-        
-        let gradient: Gradient
-    }
-}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/GeoQuiz/Components/UserProgressHelper.swift	Thu Oct 20 18:07:51 2022 +0200
@@ -0,0 +1,86 @@
+//
+//  UserProgressHelper.swift
+//  GeoQuiz
+//
+//  Created by Dennis Concepción Martín on 20/10/22.
+//
+
+import SwiftUI
+
+struct ViewTest: View {
+    var body: some View {
+        GeometryReader { geo in
+            ZStack {
+                Capsule()
+                    .frame(height: 6)
+            }
+        }
+    }
+}
+
+struct UserProgress: View {
+    let name: String
+    let gradient: Gradient
+    let score: Int
+    let maxScore: Int
+    let pctScore: Double
+    
+    var body: some View {
+        VStack {
+            Spacer()
+            HStack {
+                Text(name)
+                    .font(.headline)
+                
+                Spacer()
+                
+                Text("\(score) of \(maxScore)")
+                    .font(.callout)
+                    .foregroundColor(.secondary)
+            }
+            
+            GeometryReader { geo in
+                ZStack(alignment: .leading) {
+                    Capsule()
+                        .foregroundColor(.customBackground)
+                        .frame(height: 6)
+                    
+                    Capsule()
+                        .fill(
+                            LinearGradient(
+                                gradient: gradient,
+                                startPoint: .trailing, endPoint: .leading
+                            )
+                        )
+                        .frame(width: geo.size.width * pctScore, height: 6)
+                }
+                .frame(height: geo.size.height)
+            }
+        }
+    }
+    
+    init(playedGames: FetchedResults<PlayedGame>, gameType: GameType) {
+        switch(gameType) {
+        case . guessTheFlag:
+            self.name = GuessTheFlagInfo.name
+            self.gradient = GuessTheFlagInfo.gradient
+            self.maxScore = GuessTheFlagInfo.numberOfQuestions
+        case .guessTheCapital:
+            self.name = GuessTheCapitalInfo.name
+            self.gradient = GuessTheCapitalInfo.gradient
+            self.maxScore = GuessTheCapitalInfo.numberOfQuestions
+        case .guessTheCountry:
+            self.name = GuessTheCountryInfo.name
+            self.gradient = GuessTheCountryInfo.gradient
+            self.maxScore = GuessTheCountryInfo.numberOfQuestions
+        case .guessThePopulation:
+            self.name = GuessThePopulationInfo.name
+            self.gradient = GuessThePopulationInfo.gradient
+            self.maxScore = GuessThePopulationInfo.numberOfQuestions
+        }
+        
+        let games = playedGames.filter { $0.type == gameType }
+        self.score = Int(games.max { $0.score < $1.score }?.score ?? 0)
+        self.pctScore = Double(score) / Double(maxScore)
+    }
+}
--- a/GeoQuiz/ProfileModalView.swift	Thu Oct 20 13:49:42 2022 +0200
+++ b/GeoQuiz/ProfileModalView.swift	Thu Oct 20 18:07:51 2022 +0200
@@ -22,43 +22,53 @@
     @State private var showingEditModalView = false
     
     var body: some View {
-            NavigationView {
-                ScrollView {
-                    VStack(alignment: .leading, spacing: 15) {
-                        UserProfile(user: user, storeKitRC: storeKitRC)
-                        
-                        UserProgress(playedGames: playedGames)
-                        
-                        ForEach(playedGames) { playedGame in
-                            RecentGame(game: playedGame)
-                        }
-                        .onDelete(perform: deleteGame)
-                    }
-                    .padding()
+        NavigationView {
+            List {
+                Section {
+                    UserProfile(user: user, storeKitRC: storeKitRC)
+                }
+                
+                Section {
+                    UserProgress(playedGames: playedGames, gameType: .guessTheFlag)
+                    UserProgress(playedGames: playedGames, gameType: .guessTheCapital)
+                    UserProgress(playedGames: playedGames, gameType: .guessTheCountry)
+                    UserProgress(playedGames: playedGames, gameType: .guessThePopulation)
+                } header: {
+                    Text("Progress")
                 }
-                .background(.customBackground)
-                .navigationTitle("Profile")
-                .navigationBarTitleDisplayMode(.inline)
-                .toolbar {
-                    ToolbarItem(placement: .cancellationAction) {
-                        Button {
-                            dismiss()
-                        } label: {
-                            Label("Exit", systemImage: "multiply")
-                        }
+                
+                Section {
+                    ForEach(playedGames) { playedGame in
+                        RecentGame(game: playedGame)
                     }
-                    
-                    ToolbarItem(placement: .navigationBarTrailing) {
-                        Button("Edit") {
-                            showingEditModalView = true
-                        }
+                    .onDelete(perform: deleteGame)
+                } header: {
+                    Text("Recent games")
+                }
+            }
+            .background(.customBackground)
+            .navigationTitle("Profile")
+            .navigationBarTitleDisplayMode(.inline)
+            .toolbar {
+                ToolbarItem(placement: .cancellationAction) {
+                    Button {
+                        dismiss()
+                    } label: {
+                        Label("Exit", systemImage: "multiply")
                     }
                 }
                 
-                .sheet(isPresented: $showingEditModalView) {
-                    ProfileEditModalView(user: user)
+                ToolbarItem(placement: .navigationBarTrailing) {
+                    Button("Edit") {
+                        showingEditModalView = true
+                    }
                 }
             }
+            
+            .sheet(isPresented: $showingEditModalView) {
+                ProfileEditModalView(user: user)
+            }
+        }
         
     }