Mercurial > public > geoquiz
annotate GeoQuiz/ProfileModalView.swift @ 27:3f4b366d476d
add flag layout settings
author | Dennis C. M. <dennis@denniscm.com> |
---|---|
date | Thu, 10 Nov 2022 09:26:48 +0100 |
parents | 425078c01194 |
children |
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 |
26 | 12 @ObservedObject var storeController: StoreController |
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, | |
26 | 29 storeController: storeController, |
19 | 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 { | |
23 | 83 if playedGames.isEmpty { |
84 PersistenceController.createMockData(with: moc) | |
85 } | |
21 | 86 } |
87 #endif | |
17 | 88 } |
6 | 89 } |
90 } | |
91 | |
92 struct ProfileView_Previews: PreviewProvider { | |
93 static var previews: some View { | |
26 | 94 ProfileModalView(userController: UserController(), storeController: StoreController()) |
16 | 95 .environment(\.managedObjectContext, PersistenceController.preview.container.viewContext) |
6 | 96 } |
97 } |