1
1
import SwiftUI
2
-
3
2
struct CourseView : View {
4
3
@State private var isLoading = false
5
4
@State private var downloadProgress : [ Course : Progress ] = [ : ]
6
5
@State private var userTrainingData = UserTrainingData ( )
7
6
@State private var showingNotificationSettings = false
8
7
@State private var notificationsEnabled = false
8
+ @State private var showingInfoPopup = false
9
+
9
10
@StateObject private var viewModel = DownloadViewModel ( )
10
11
@StateObject private var questionLoader : QuestionLoader
11
12
13
+ @Environment ( \. colorScheme) var colorScheme
14
+
12
15
let course : Course
13
16
14
17
init ( course: Course ) {
@@ -41,7 +44,7 @@ struct CourseView: View {
41
44
42
45
Spacer ( )
43
46
VStack ( spacing: 20 ) {
44
- NavigationLink ( destination: TrainingView ( course: course, questionLoader : questionLoader ) ) {
47
+ NavigationLink ( destination: TrainingView ( course: course) ) {
45
48
VStack {
46
49
Text ( " Training " )
47
50
. font ( . title)
@@ -55,7 +58,7 @@ struct CourseView: View {
55
58
. cornerRadius ( 10 )
56
59
}
57
60
58
- NavigationLink ( destination: TrainingView ( course: course, questionLoader : questionLoader ) ) {
61
+ NavigationLink ( destination: TrainingView ( course: course) ) {
59
62
VStack {
60
63
Text ( " Intelligent Training " )
61
64
. font ( . title)
@@ -85,14 +88,16 @@ struct CourseView: View {
85
88
}
86
89
Spacer ( )
87
90
88
- HStack ( spacing: 20 ) {
89
- Link ( " Certification " , destination: URL ( string: course. url) !)
90
- . padding ( )
91
- . font ( . subheadline)
92
-
93
- Link ( " Sources " , destination: URL ( string: course. repositoryURL) !)
94
- . padding ( )
95
- . font ( . subheadline)
91
+ NavigationLink ( destination: BookmarksView ( ) ) {
92
+ HStack {
93
+ Image ( systemName: " bookmark " )
94
+ . font ( . title3)
95
+ . foregroundColor ( colorScheme == . dark ? . white : . black)
96
+ Text ( " Bookmarks " )
97
+ . font ( . title3)
98
+ . foregroundColor ( colorScheme == . dark ? . white : . black)
99
+ }
100
+ . cornerRadius ( 10 )
96
101
}
97
102
}
98
103
. onAppear {
@@ -104,14 +109,20 @@ struct CourseView: View {
104
109
}
105
110
}
106
111
. navigationBarTitle ( course. shortName, displayMode: . inline)
107
- . navigationBarItems ( trailing: notificationButton)
112
+ . navigationBarItems ( trailing: HStack {
113
+ notificationButton
114
+ infoButton
115
+ } )
108
116
. navigationBarBackButtonHidden ( false )
109
117
. sheet ( isPresented: $showingNotificationSettings) {
110
118
NotificationSettingsView ( isPresented: $showingNotificationSettings, notificationsEnabled: $notificationsEnabled, course: course)
111
119
. onDisappear {
112
120
checkNotificationSettings ( )
113
121
}
114
122
}
123
+ . sheet ( isPresented: $showingInfoPopup) {
124
+ CourseInformationPopup ( course: course)
125
+ }
115
126
. overlay (
116
127
DownloadOverlayView (
117
128
isShowing: $viewModel. isDownloading,
@@ -135,6 +146,14 @@ struct CourseView: View {
135
146
}
136
147
}
137
148
149
+ private var infoButton : some View {
150
+ Button ( action: {
151
+ showingInfoPopup = true
152
+ } ) {
153
+ Image ( systemName: " info.circle " )
154
+ }
155
+ }
156
+
138
157
func loadUserTrainingData( for course: Course ) {
139
158
if let data = UserDefaults . standard. data ( forKey: course. shortName) {
140
159
if let decodedData = try ? JSONDecoder ( ) . decode ( UserTrainingData . self, from: data) {
@@ -163,7 +182,7 @@ struct CourseView: View {
163
182
func downloadCourse( ) {
164
183
viewModel. downloadCourse ( course)
165
184
viewModel. $isDownloading. sink { isDownloading in
166
- if !isDownloading {
185
+ if ( !isDownloading) {
167
186
DispatchQueue . main. async {
168
187
questionLoader. reloadQuestions ( from: course. shortName + " .json " )
169
188
}
@@ -181,3 +200,39 @@ struct CourseView: View {
181
200
. store ( in: & viewModel. cancellables)
182
201
}
183
202
}
203
+
204
+ struct CourseInformationPopup : View {
205
+ let course : Course
206
+
207
+ var body : some View {
208
+ VStack ( spacing: 20 ) {
209
+ Text ( " Course information " )
210
+ . font ( . title2)
211
+ . multilineTextAlignment ( . center)
212
+
213
+ VStack ( spacing: 10 ) {
214
+ HStack {
215
+ Spacer ( )
216
+ Image ( systemName: " book.pages.fill " )
217
+ Text ( " Certification " )
218
+ Spacer ( )
219
+ }
220
+ Link ( course. url, destination: URL ( string: course. url) !)
221
+ }
222
+
223
+ VStack ( spacing: 10 ) {
224
+ HStack {
225
+ Spacer ( )
226
+ Image ( systemName: " link " )
227
+ Text ( " Sources " )
228
+ Spacer ( )
229
+ }
230
+ Link ( course. repositoryURL, destination: URL ( string: course. repositoryURL) !)
231
+ }
232
+
233
+ Spacer ( )
234
+ }
235
+ . padding ( )
236
+ }
237
+
238
+ }
0 commit comments