@@ -4,7 +4,8 @@ use druid::im::Vector;
44use druid:: widget:: { Either , Flex , Label , Scroll } ;
55use druid:: { widget:: List , LensExt , Selector , Widget , WidgetExt } ;
66
7- use crate :: data:: { Artist , Ctx , HomeDetail , MixedView , Show , Track , WithCtx } ;
7+ use crate :: data:: { Artist , Ctx , HomeDetail , MixedView , Show , Shows , Track , WithCtx } ;
8+ use crate :: ui:: library:: { LOAD_SHOWS , SAVE_SHOW , UNSAVE_SHOW } ;
89use crate :: widget:: Empty ;
910use crate :: {
1011 data:: AppState ,
@@ -45,7 +46,7 @@ fn simple_title_label(title: &str) -> impl Widget<AppState> {
4546 )
4647}
4748
48- pub fn made_for_you ( ) -> impl Widget < AppState > {
49+ fn made_for_you ( ) -> impl Widget < AppState > {
4950 Async :: new ( spinner_widget, loaded_results_widget, || Empty )
5051 . lens (
5152 Ctx :: make (
@@ -62,7 +63,7 @@ pub fn made_for_you() -> impl Widget<AppState> {
6263 )
6364}
6465
65- pub fn recommended_stations ( ) -> impl Widget < AppState > {
66+ fn recommended_stations ( ) -> impl Widget < AppState > {
6667 Async :: new ( spinner_widget, loaded_results_widget, || Empty )
6768 . lens (
6869 Ctx :: make (
@@ -97,7 +98,7 @@ fn uniquely_yours_results_widget() -> impl Widget<WithCtx<MixedView>> {
9798 )
9899}
99100
100- pub fn uniquely_yours ( ) -> impl Widget < AppState > {
101+ fn uniquely_yours ( ) -> impl Widget < AppState > {
101102 Async :: new ( spinner_widget, uniquely_yours_results_widget, || Empty )
102103 . lens (
103104 Ctx :: make (
@@ -114,7 +115,7 @@ pub fn uniquely_yours() -> impl Widget<AppState> {
114115 )
115116}
116117
117- pub fn user_top_mixes ( ) -> impl Widget < AppState > {
118+ fn user_top_mixes ( ) -> impl Widget < AppState > {
118119 Async :: new ( spinner_widget, loaded_results_widget, || Empty )
119120 . lens (
120121 Ctx :: make (
@@ -131,7 +132,7 @@ pub fn user_top_mixes() -> impl Widget<AppState> {
131132 )
132133}
133134
134- pub fn best_of_artists ( ) -> impl Widget < AppState > {
135+ fn best_of_artists ( ) -> impl Widget < AppState > {
135136 Async :: new ( spinner_widget, loaded_results_widget, || Empty )
136137 . lens (
137138 Ctx :: make (
@@ -163,9 +164,66 @@ pub fn your_shows() -> impl Widget<AppState> {
163164 |_, data, q| data. home_detail . your_shows . defer ( q) ,
164165 |_, data, r| data. home_detail . your_shows . update ( r) ,
165166 )
167+ . on_command_async (
168+ LOAD_SHOWS ,
169+ |_| WebApi :: global ( ) . get_saved_shows ( ) . map ( Shows :: new) ,
170+ |_, data, q| {
171+ data. home_detail . your_shows . defer ( q) ;
172+ data. with_library_mut ( |library| {
173+ library. saved_shows . defer_default ( ) ;
174+ } ) ;
175+ } ,
176+ |_, data, r| {
177+ data. home_detail . your_shows . update ( (
178+ ( ) ,
179+ r. 1 . clone ( ) . map ( |saved_shows| MixedView {
180+ title : "Saved Shows" . into ( ) ,
181+ playlists : Vec :: new ( ) . into ( ) ,
182+ artists : Vec :: new ( ) . into ( ) ,
183+ albums : Vec :: new ( ) . into ( ) ,
184+ shows : saved_shows. shows ,
185+ } ) ,
186+ ) ) ;
187+ data. with_library_mut ( |library| {
188+ library. saved_shows . update ( r) ;
189+ } ) ;
190+ } ,
191+ )
192+ . on_command_async (
193+ SAVE_SHOW ,
194+ |a| WebApi :: global ( ) . save_show ( & a. id ) ,
195+ |_, data, s| {
196+ data. with_library_mut ( move |library| {
197+ library. add_show ( s) ;
198+ } ) ;
199+ } ,
200+ |_, data, ( _, r) | {
201+ if let Err ( err) = r {
202+ data. error_alert ( err) ;
203+ } else {
204+ data. info_alert ( "Show added to library." ) ;
205+ }
206+ } ,
207+ )
208+ . on_command_async (
209+ UNSAVE_SHOW ,
210+ |l| WebApi :: global ( ) . unsave_show ( & l. id ) ,
211+ |_, data, l| {
212+ data. with_library_mut ( |library| {
213+ library. remove_show ( & l. id ) ;
214+ } ) ;
215+ } ,
216+ |_, data, ( _, r) | {
217+ if let Err ( err) = r {
218+ data. error_alert ( err) ;
219+ } else {
220+ data. info_alert ( "Show removed from library." ) ;
221+ }
222+ } ,
223+ )
166224}
167225
168- pub fn jump_back_in ( ) -> impl Widget < AppState > {
226+ fn jump_back_in ( ) -> impl Widget < AppState > {
169227 Async :: new ( spinner_widget, loaded_results_widget, || Empty )
170228 . lens (
171229 Ctx :: make (
@@ -199,7 +257,7 @@ pub fn shows_that_you_might_like() -> impl Widget<AppState> {
199257 )
200258}
201259
202- fn loaded_results_widget ( ) -> impl Widget < WithCtx < MixedView > > {
260+ pub fn loaded_results_widget ( ) -> impl Widget < WithCtx < MixedView > > {
203261 Either :: new (
204262 |results : & WithCtx < MixedView > , _| {
205263 results. data . artists . is_empty ( )
0 commit comments