File tree Expand file tree Collapse file tree 2 files changed +29
-4
lines changed
Expand file tree Collapse file tree 2 files changed +29
-4
lines changed Original file line number Diff line number Diff line change @@ -20,6 +20,14 @@ impl Index {
2020 serde_yaml:: from_str ( & content) . map_err ( |e| Error :: Parse ( e. to_string ( ) ) ) ?;
2121 Ok ( lesson)
2222 }
23+
24+ pub fn next_lesson ( & self , current_lesson : & str ) -> Option < & str > {
25+ if let Some ( index) = self . lessons . iter ( ) . position ( |index_record| index_record. file . eq ( current_lesson) ) {
26+ self . lessons . get ( index + 1 ) . map ( |index_record| index_record. file . as_str ( ) )
27+ } else {
28+ None
29+ }
30+ }
2331}
2432
2533#[ derive( Debug , Error , Clone ) ]
Original file line number Diff line number Diff line change @@ -142,17 +142,23 @@ impl Raiti {
142142 if self . dialog == DialogType :: ConfirmExitLesson {
143143 self . dialog = DialogType :: None ;
144144 self . lesson = None ;
145+ return Task :: none ( ) ;
145146 }
146- let finished = self . exercise_components . iter ( ) . all ( |ex| ex. exercise_finished ( ) ) ;
147+ let finished = self
148+ . exercise_components
149+ . iter ( )
150+ . all ( |ex| ex. exercise_finished ( ) ) ;
147151 if finished {
148152 self . move_next_page ( ) ;
149153 }
150154 for exercise_component in self . exercise_components . iter_mut ( ) {
151155 if !exercise_component. exercise_finished ( ) {
152- exercise_component. update ( exercise_component:: Message :: SetFocus ( true ) ) ;
156+ exercise_component
157+ . update ( exercise_component:: Message :: SetFocus ( true ) ) ;
153158 break ;
154159 } else {
155- exercise_component. update ( exercise_component:: Message :: SetFocus ( false ) ) ;
160+ exercise_component
161+ . update ( exercise_component:: Message :: SetFocus ( false ) ) ;
156162 }
157163 }
158164 }
@@ -335,7 +341,18 @@ impl Raiti {
335341 }
336342 } ;
337343 } else {
338- self . lesson = None ;
344+ self . lesson = self
345+ . config
346+ . index
347+ . next_lesson ( & self . config . current_lesson )
348+ . map ( String :: from)
349+ . map ( |name| {
350+ self . config
351+ . load_lesson ( & name)
352+ . expect ( "Enable to load next lesson" )
353+ } ) ;
354+ self . config . current_exercise = 0 ;
355+ self . config . current_page = 0 ;
339356 }
340357 }
341358 }
You can’t perform that action at this time.
0 commit comments