@@ -142,9 +142,8 @@ pub fn window() -> Window<()> {
142142 EditBox :: new( Guard :: new( false ) ) ,
143143 EditBox :: new( Guard :: new( true ) ) ,
144144 Text :: new( |_, data: & Data | format!( "{}" , data. error) ) ,
145- Button :: new_msg( label_any( "Book" ) , ActionBook ) . on_update(
146- |cx, button, data: & Data | cx. set_disabled( button. id( ) , !data. error. is_none( ) )
147- ) ,
145+ Button :: new_msg( label_any( "Book" ) , ActionBook )
146+ . on_update( |cx, _, data: & Data | cx. set_disabled( !data. error. is_none( ) ) ) ,
148147 ] ;
149148
150149 let ui = Adapt :: new ( ui, data)
@@ -161,27 +160,24 @@ pub fn window() -> Window<()> {
161160
162161 data. update_error ( ) ;
163162 } )
164- . on_messages ( |cx, _, data| {
165- if cx. try_pop :: < ActionBook > ( ) . is_some ( ) {
166- let msg = if !data. error . is_none ( ) {
167- // should be impossible since the button is disabled
168- format ! ( "{}" , data. error)
169- } else {
170- match data. flight {
171- Flight :: OneWay => format ! (
172- "You have booked a one-way flight on {}" ,
173- data. out. unwrap( ) . format( "%Y-%m-%d" )
174- ) ,
175- Flight :: Return => format ! (
176- "You have booked an out-bound flight on {} and a return flight on {}" ,
177- data. out. unwrap( ) . format( "%Y-%m-%d" ) ,
178- data. ret. unwrap( ) . format( "%Y-%m-%d" ) ,
179- ) ,
180- }
181- } ;
182- cx. add_window :: < ( ) > ( MessageBox :: new ( msg) . into_window ( "Booker result" ) ) ;
183- }
184- false
163+ . on_message ( |cx, data, ActionBook | {
164+ let msg = if !data. error . is_none ( ) {
165+ // should be impossible since the button is disabled
166+ format ! ( "{}" , data. error)
167+ } else {
168+ match data. flight {
169+ Flight :: OneWay => format ! (
170+ "You have booked a one-way flight on {}" ,
171+ data. out. unwrap( ) . format( "%Y-%m-%d" )
172+ ) ,
173+ Flight :: Return => format ! (
174+ "You have booked an out-bound flight on {} and a return flight on {}" ,
175+ data. out. unwrap( ) . format( "%Y-%m-%d" ) ,
176+ data. ret. unwrap( ) . format( "%Y-%m-%d" ) ,
177+ ) ,
178+ }
179+ } ;
180+ cx. add_window :: < ( ) > ( MessageBox :: new ( msg) . into_window ( "Booker result" ) ) ;
185181 } ) ;
186182
187183 Window :: new ( ui, "Flight Booker" )
0 commit comments