Mercurial > public > geoquiz
annotate GeoQuiz/ProfileModalView.swift @ 22:56add5561261
add mock data creation
author | Dennis C. M. <dennis@denniscm.com> |
---|---|
date | Wed, 26 Oct 2022 08:20:19 +0200 |
parents | b145c408f791 |
children | 02dcebb8cc4a |
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 | |
9 | |
10 struct ProfileModalView: View { | |
19 | 11 @ObservedObject var userController: UserController |
12 @ObservedObject var storeKitController: StoreKitController | |
14 | 13 |
20 | 14 @State private var showingEditModalView = false |
15
f1967f8cc67b
first iteration of core data
Dennis C. M. <dennis@denniscm.com>
parents:
14
diff
changeset
|
15 |
f1967f8cc67b
first iteration of core data
Dennis C. M. <dennis@denniscm.com>
parents:
14
diff
changeset
|
16 @FetchRequest(sortDescriptors: [ |
16 | 17 SortDescriptor(\.date, order: .reverse), |
15
f1967f8cc67b
first iteration of core data
Dennis C. M. <dennis@denniscm.com>
parents:
14
diff
changeset
|
18 ]) var playedGames: FetchedResults<PlayedGame> |
14 | 19 |
19 | 20 @Environment(\.dismiss) var dismiss |
21 @Environment(\.managedObjectContext) var moc | |
14 | 22 |
6 | 23 var body: some View { |
19 | 24 NavigationStack { |
25 ScrollView { | |
26 VStack(spacing: 30) { | |
27 UserProfile( | |
28 userController: userController, | |
29 storeKitController: storeKitController, | |
30 isShowing: $showingEditModalView | |
31 ) | |
32 | |
21 | 33 if !playedGames.isEmpty { |
34 VStack(spacing: 20) { | |
35 HStack { | |
36 Text("Latest games") | |
37 .foregroundColor(.secondary) | |
38 | |
39 Spacer() | |
40 | |
41 NavigationLink { | |
42 PlayedGamesList() | |
43 } label: { | |
44 HStack { | |
45 Text("Show all") | |
46 Image(systemName: "chevron.right") | |
47 } | |
48 } | |
49 .disabled(playedGames.isEmpty) | |
50 } | |
20 | 51 |
52 ForEach(playedGames.prefix(8)) { playedGame in | |
53 RecentGame(game: playedGame) | |
54 .padding() | |
55 .background(Color(.secondarySystemGroupedBackground)) | |
56 .cornerRadius(20) | |
57 } | |
19 | 58 } |
59 } | |
17 | 60 } |
19 | 61 .padding() |
17 | 62 } |
20 | 63 .frame(maxWidth: .infinity) |
17 | 64 .navigationTitle("Profile") |
65 .navigationBarTitleDisplayMode(.inline) | |
19 | 66 .background(Color(.systemGroupedBackground)) |
17 | 67 .toolbar { |
68 ToolbarItem(placement: .cancellationAction) { | |
69 Button { | |
70 dismiss() | |
71 } label: { | |
72 Label("Exit", systemImage: "multiply") | |
14 | 73 } |
74 } | |
75 } | |
17 | 76 |
77 .sheet(isPresented: $showingEditModalView) { | |
21 | 78 ProfileEditModalView(userController: userController) |
17 | 79 } |
21 | 80 |
81 #if DEBUG | |
82 .onAppear { | |
22 | 83 PersistenceController.createMockData(playedGames, moc) |
21 | 84 } |
85 #endif | |
17 | 86 } |
6 | 87 } |
88 } | |
89 | |
90 struct ProfileView_Previews: PreviewProvider { | |
91 static var previews: some View { | |
19 | 92 ProfileModalView(userController: UserController(), storeKitController: StoreKitController()) |
16 | 93 .environment(\.managedObjectContext, PersistenceController.preview.container.viewContext) |
6 | 94 } |
95 } |