Mercurial > public > geoquiz
annotate GeoQuiz/ProfileModalView.swift @ 17:8dac58bb4569
fix build bug
author | Dennis C. M. <dennis@denniscm.com> |
---|---|
date | Thu, 20 Oct 2022 18:07:51 +0200 |
parents | 1011e56b7832 |
children | f140bb277c96 |
rev | line source |
---|---|
6 | 1 // |
2 // ProfileModalView.swift | |
3 // GeoQuiz | |
4 // | |
5 // Created by Dennis Concepción Martín on 25/9/22. | |
6 // | |
7 | |
8 import SwiftUI | |
14 | 9 import PhotosUI |
6 | 10 |
11 struct ProfileModalView: View { | |
14 | 12 @ObservedObject var user: User |
13 @ObservedObject var storeKitRC: StoreKitRC | |
14 | |
15 @Environment(\.dismiss) var dismiss | |
15
f1967f8cc67b
first iteration of core data
Dennis C. M. <dennis@denniscm.com>
parents:
14
diff
changeset
|
16 @Environment(\.managedObjectContext) var moc |
f1967f8cc67b
first iteration of core data
Dennis C. M. <dennis@denniscm.com>
parents:
14
diff
changeset
|
17 |
f1967f8cc67b
first iteration of core data
Dennis C. M. <dennis@denniscm.com>
parents:
14
diff
changeset
|
18 @FetchRequest(sortDescriptors: [ |
16 | 19 SortDescriptor(\.date, order: .reverse), |
15
f1967f8cc67b
first iteration of core data
Dennis C. M. <dennis@denniscm.com>
parents:
14
diff
changeset
|
20 ]) var playedGames: FetchedResults<PlayedGame> |
14 | 21 |
22 @State private var showingEditModalView = false | |
23 | |
6 | 24 var body: some View { |
17 | 25 NavigationView { |
26 List { | |
27 Section { | |
28 UserProfile(user: user, storeKitRC: storeKitRC) | |
29 } | |
30 | |
31 Section { | |
32 UserProgress(playedGames: playedGames, gameType: .guessTheFlag) | |
33 UserProgress(playedGames: playedGames, gameType: .guessTheCapital) | |
34 UserProgress(playedGames: playedGames, gameType: .guessTheCountry) | |
35 UserProgress(playedGames: playedGames, gameType: .guessThePopulation) | |
36 } header: { | |
37 Text("Progress") | |
16 | 38 } |
17 | 39 |
40 Section { | |
41 ForEach(playedGames) { playedGame in | |
42 RecentGame(game: playedGame) | |
16 | 43 } |
17 | 44 .onDelete(perform: deleteGame) |
45 } header: { | |
46 Text("Recent games") | |
47 } | |
48 } | |
49 .background(.customBackground) | |
50 .navigationTitle("Profile") | |
51 .navigationBarTitleDisplayMode(.inline) | |
52 .toolbar { | |
53 ToolbarItem(placement: .cancellationAction) { | |
54 Button { | |
55 dismiss() | |
56 } label: { | |
57 Label("Exit", systemImage: "multiply") | |
14 | 58 } |
59 } | |
60 | |
17 | 61 ToolbarItem(placement: .navigationBarTrailing) { |
62 Button("Edit") { | |
63 showingEditModalView = true | |
64 } | |
14 | 65 } |
66 } | |
17 | 67 |
68 .sheet(isPresented: $showingEditModalView) { | |
69 ProfileEditModalView(user: user) | |
70 } | |
71 } | |
16 | 72 |
73 } | |
74 | |
75 private func deleteGame(at offsets: IndexSet) { | |
76 for offset in offsets { | |
77 let game = playedGames[offset] | |
78 moc.delete(game) | |
14 | 79 } |
16 | 80 |
81 try? moc.save() | |
6 | 82 } |
83 } | |
84 | |
85 struct ProfileView_Previews: PreviewProvider { | |
86 static var previews: some View { | |
14 | 87 ProfileModalView(user: User(), storeKitRC: StoreKitRC()) |
16 | 88 .environment(\.managedObjectContext, PersistenceController.preview.container.viewContext) |
6 | 89 } |
90 } |