Mercurial > public > geoquiz
annotate GeoQuiz/ProfileModalView.swift @ 20:e281791e0494
finish implementation
author | Dennis C. M. <dennis@denniscm.com> |
---|---|
date | Sun, 23 Oct 2022 11:48:39 +0100 |
parents | f140bb277c96 |
children | b145c408f791 |
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 | |
33 VStack(spacing: 20) { | |
20 | 34 HStack { |
35 Text("Latest games") | |
36 .foregroundColor(.secondary) | |
37 | |
38 Spacer() | |
39 | |
40 NavigationLink { | |
41 PlayedGamesList(playedGames: playedGames) | |
42 } label: { | |
43 Text("Show all") | |
44 } | |
45 .disabled(playedGames.isEmpty) | |
46 } | |
47 | |
48 if playedGames.isEmpty { | |
49 Spacer() | |
50 LatestGamesPlaceholder() | |
51 } else { | |
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) { | |
19 | 78 ProfileEditModalView(user: userController) |
17 | 79 } |
80 } | |
6 | 81 } |
82 } | |
83 | |
84 struct ProfileView_Previews: PreviewProvider { | |
85 static var previews: some View { | |
19 | 86 ProfileModalView(userController: UserController(), storeKitController: StoreKitController()) |
16 | 87 .environment(\.managedObjectContext, PersistenceController.preview.container.viewContext) |
6 | 88 } |
89 } |