Skip to content

Commit d5637bc

Browse files
authored
Merge branch 'jpochyla:main' into main
2 parents 606534e + 76b6a2a commit d5637bc

File tree

10 files changed

+196
-152
lines changed

10 files changed

+196
-152
lines changed

psst-gui/src/controller/nav.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ impl NavController {
2323
ctx.submit_command(library::LOAD_ALBUMS);
2424
}
2525
}
26-
Nav::SavedShows => {
26+
Nav::Shows => {
2727
if !data.library.saved_shows.is_resolved() {
2828
ctx.submit_command(library::LOAD_SHOWS);
2929
}

psst-gui/src/data/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ pub struct Library {
341341
pub playlists: Promise<Vector<Playlist>>,
342342
pub saved_albums: Promise<SavedAlbums>,
343343
pub saved_tracks: Promise<SavedTracks>,
344-
pub saved_shows: Promise<SavedShows>,
344+
pub saved_shows: Promise<Shows>,
345345
}
346346

347347
impl Library {
@@ -523,12 +523,12 @@ impl SavedAlbums {
523523
}
524524

525525
#[derive(Clone, Default, Data, Lens)]
526-
pub struct SavedShows {
526+
pub struct Shows {
527527
pub shows: Vector<Arc<Show>>,
528528
pub set: HashSet<Arc<str>>,
529529
}
530530

531-
impl SavedShows {
531+
impl Shows {
532532
pub fn new(shows: Vector<Arc<Show>>) -> Self {
533533
let set = shows.iter().map(|a| a.id.clone()).collect();
534534
Self { shows, set }

psst-gui/src/data/nav.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ pub enum Route {
1515
Lyrics,
1616
SavedTracks,
1717
SavedAlbums,
18-
SavedShows,
18+
Shows,
1919
SearchResults,
2020
ArtistDetail,
2121
AlbumDetail,
@@ -31,7 +31,7 @@ pub enum Nav {
3131
Lyrics,
3232
SavedTracks,
3333
SavedAlbums,
34-
SavedShows,
34+
Shows,
3535
SearchResults(Arc<str>),
3636
AlbumDetail(AlbumLink, Option<TrackId>),
3737
ArtistDetail(ArtistLink),
@@ -47,7 +47,7 @@ impl Nav {
4747
Nav::Lyrics => Route::Lyrics,
4848
Nav::SavedTracks => Route::SavedTracks,
4949
Nav::SavedAlbums => Route::SavedAlbums,
50-
Nav::SavedShows => Route::SavedShows,
50+
Nav::Shows => Route::Shows,
5151
Nav::SearchResults(_) => Route::SearchResults,
5252
Nav::AlbumDetail(_, _) => Route::AlbumDetail,
5353
Nav::ArtistDetail(_) => Route::ArtistDetail,
@@ -63,7 +63,7 @@ impl Nav {
6363
Nav::Lyrics => "Lyrics".to_string(),
6464
Nav::SavedTracks => "Saved Tracks".to_string(),
6565
Nav::SavedAlbums => "Saved Albums".to_string(),
66-
Nav::SavedShows => "Saved Podcasts".to_string(),
66+
Nav::Shows => "Podcasts".to_string(),
6767
Nav::SearchResults(query) => query.to_string(),
6868
Nav::AlbumDetail(link, _) => link.name.to_string(),
6969
Nav::ArtistDetail(link) => link.name.to_string(),
@@ -79,7 +79,7 @@ impl Nav {
7979
Nav::Lyrics => "Lyrics".to_string(),
8080
Nav::SavedTracks => "Saved Tracks".to_string(),
8181
Nav::SavedAlbums => "Saved Albums".to_string(),
82-
Nav::SavedShows => "Saved Shows".to_string(),
82+
Nav::Shows => "Saved Shows".to_string(),
8383
Nav::SearchResults(query) => format!("Search \"{}\"", query),
8484
Nav::AlbumDetail(link, _) => format!("Album \"{}\"", link.name),
8585
Nav::ArtistDetail(link) => format!("Artist \"{}\"", link.name),

psst-gui/src/data/show.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ pub struct Show {
2222
pub images: Vector<Image>,
2323
pub publisher: Arc<str>,
2424
pub description: Arc<str>,
25+
pub total_episodes: Option<usize>,
2526
}
2627

2728
impl Show {

psst-gui/src/ui/home.rs

Lines changed: 66 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ use druid::im::Vector;
44
use druid::widget::{Either, Flex, Label, Scroll};
55
use 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};
89
use crate::widget::Empty;
910
use 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()

psst-gui/src/ui/library.rs

Lines changed: 11 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,22 @@
11
use std::sync::Arc;
22

3-
use druid::{widget::List, LensExt, Selector, Widget, WidgetExt};
3+
use druid::{
4+
widget::{Flex, List},
5+
LensExt, Selector, Widget, WidgetExt,
6+
};
47

58
use crate::{
69
cmd,
710
data::{
8-
Album, AlbumLink, AppState, Ctx, Library, SavedAlbums, SavedShows, SavedTracks, Show,
9-
ShowLink, Track, TrackId,
11+
Album, AlbumLink, AppState, Ctx, Library, SavedAlbums, SavedTracks, Show, ShowLink, Track,
12+
TrackId,
1013
},
14+
ui::home::{shows_that_you_might_like, your_shows},
1115
webapi::WebApi,
1216
widget::{Async, MyWidgetExt},
1317
};
1418

15-
use super::{album, playable, show, track, utils};
19+
use super::{album, playable, track, utils};
1620

1721
pub const LOAD_TRACKS: Selector = Selector::new("app.library.load-tracks");
1822
pub const LOAD_ALBUMS: Selector = Selector::new("app.library.load-albums");
@@ -163,62 +167,7 @@ pub fn saved_albums_widget() -> impl Widget<AppState> {
163167
}
164168

165169
pub fn saved_shows_widget() -> impl Widget<AppState> {
166-
Async::new(
167-
utils::spinner_widget,
168-
|| List::new(|| show::show_widget(false)).lens(Ctx::map(SavedShows::shows)),
169-
utils::error_widget,
170-
)
171-
.lens(
172-
Ctx::make(
173-
AppState::common_ctx,
174-
AppState::library.then(Library::saved_shows.in_arc()),
175-
)
176-
.then(Ctx::in_promise()),
177-
)
178-
.on_command_async(
179-
LOAD_SHOWS,
180-
|_| WebApi::global().get_saved_shows().map(SavedShows::new),
181-
|_, data, _| {
182-
data.with_library_mut(|library| {
183-
library.saved_shows.defer_default();
184-
});
185-
},
186-
|_, data, r| {
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-
)
170+
Flex::column()
171+
.with_child(your_shows())
172+
.with_child(shows_that_you_might_like())
224173
}

psst-gui/src/ui/menu.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ fn view_menu() -> Menu<AppState> {
7575
MenuItem::new(
7676
LocalizedString::new("menu-item-saved-shows").with_placeholder("Saved Shows"),
7777
)
78-
.command(cmd::NAVIGATE.with(Nav::SavedShows))
78+
.command(cmd::NAVIGATE.with(Nav::Shows))
7979
.hotkey(SysMods::Cmd, "4"),
8080
)
8181
.entry(

psst-gui/src/ui/mod.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -355,11 +355,9 @@ fn route_widget() -> impl Widget<AppState> {
355355
.vertical()
356356
.boxed()
357357
}
358-
Route::SavedShows => {
359-
Scroll::new(library::saved_shows_widget().padding(theme::grid(1.0)))
360-
.vertical()
361-
.boxed()
362-
}
358+
Route::Shows => Scroll::new(library::saved_shows_widget().padding(theme::grid(1.0)))
359+
.vertical()
360+
.boxed(),
363361
Route::SearchResults => Scroll::new(search::results_widget().padding(theme::grid(1.0)))
364362
.vertical()
365363
.boxed(),
@@ -398,7 +396,7 @@ fn sidebar_menu_widget() -> impl Widget<AppState> {
398396
.with_child(sidebar_link_widget("Home", Nav::Home))
399397
.with_child(sidebar_link_widget("Tracks", Nav::SavedTracks))
400398
.with_child(sidebar_link_widget("Albums", Nav::SavedAlbums))
401-
.with_child(sidebar_link_widget("Podcasts", Nav::SavedShows))
399+
.with_child(sidebar_link_widget("Podcasts", Nav::Shows))
402400
.with_child(search::input_widget().padding((theme::grid(1.0), theme::grid(1.0))))
403401
}
404402

@@ -593,7 +591,7 @@ fn route_icon_widget() -> impl Widget<Nav> {
593591
|nav: &Nav, _, _| {
594592
let icon = |icon: &SvgIcon| icon.scale(theme::ICON_SIZE_MEDIUM);
595593
match &nav {
596-
Nav::Home | Nav::Lyrics | Nav::SavedTracks | Nav::SavedAlbums | Nav::SavedShows => {
594+
Nav::Home | Nav::Lyrics | Nav::SavedTracks | Nav::SavedAlbums | Nav::Shows => {
597595
Empty.boxed()
598596
}
599597
Nav::SearchResults(_) | Nav::Recommendations(_) => icon(&icons::SEARCH).boxed(),

0 commit comments

Comments
 (0)