Skip to content

Commit

Permalink
Grab the homepage things
Browse files Browse the repository at this point in the history
  • Loading branch information
Samuel Oldham committed Sep 13, 2024
1 parent 8db4b7a commit 09d8681
Show file tree
Hide file tree
Showing 4 changed files with 205 additions and 123 deletions.
5 changes: 1 addition & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,4 @@ cache
.env
*.iml
rust-toolchain
*.ico
psst-gui/src/ui/artist.rs
psst-gui/src/ui/search.rs
psst-gui/src/webapi/client.rs
*.ico
5 changes: 5 additions & 0 deletions psst-gui/src/data/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ impl AppState {
home_detail: HomeDetail {
made_for_you: Promise::Empty,
user_top_mixes: Promise::Empty,
recommended_stations: Promise::Empty,
uniquely_yours: Promise::Empty,
jump_back_in: Promise::Empty,
user_top_tracks: Promise::Empty,
user_top_artists: Promise::Empty,
Expand Down Expand Up @@ -519,13 +521,16 @@ pub type WithCtx<T> = Ctx<Arc<CommonCtx>, T>;
pub struct HomeDetail {
pub made_for_you: Promise<MixedView>,
pub user_top_mixes: Promise<MixedView>,
pub recommended_stations: Promise<MixedView>,
pub uniquely_yours: Promise<MixedView>,
pub jump_back_in: Promise<MixedView>,
pub user_top_tracks: Promise<Vector<Arc<Track>>>,
pub user_top_artists: Promise<Vector<Artist>>,
}

#[derive(Clone, Data, Lens)]
pub struct MixedView {
pub title: Arc<str>,
pub playlists: Vector<Playlist>,
pub artists: Vector<Artist>,
pub albums: Vector<Album>,
Expand Down
80 changes: 66 additions & 14 deletions psst-gui/src/ui/home.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ use druid::im::Vector;
use druid::widget::{Either, Flex, Label, Scroll};
use druid::{widget::List, LensExt, Selector, Widget, WidgetExt};

use crate::data::config::authentication_derived_lenses::result;
use crate::data::mixed_view_derived_lenses::title;
use crate::data::{Album, Artist, Ctx, HomeDetail, MixedView, Show, Track, WithCtx};
use crate::widget::Empty;
use crate::{
Expand All @@ -22,24 +24,18 @@ pub const LOAD_MADE_FOR_YOU: Selector = Selector::new("app.home.load-made-for-yo

pub fn home_widget() -> impl Widget<AppState> {
Flex::column()
.with_child(
Label::new("Made for you")
.with_text_size(theme::grid(2.5))
.align_left()
.padding((theme::grid(1.5), 0.0)),
)
.with_default_spacer()
.with_child(made_for_you())
.with_default_spacer()
.with_child(user_top_mixes())
.with_child(recommended_stations())
// turn this into a function as it is like title_label(title: &str){}!!!
.with_child(
Label::new("Your top mixes")
Label::new("Uniquely yours")
.with_text_size(theme::grid(2.5))
.align_left()
.padding((theme::grid(1.5), 0.0)),
)
.with_default_spacer()
.with_child(user_top_mixes())
.with_default_spacer()
.with_child(uniquely_yours())
.with_child(
Label::new("Your top artists")
.with_text_size(theme::grid(2.5))
Expand Down Expand Up @@ -76,6 +72,40 @@ pub fn made_for_you() -> impl Widget<AppState> {
)
}

pub fn recommended_stations() -> impl Widget<AppState> {
Async::new(spinner_widget, loaded_results_widget.clone(), error_widget)
.lens(
Ctx::make(
AppState::common_ctx,
AppState::home_detail.then(HomeDetail::recommended_stations),
)
.then(Ctx::in_promise()),
)
.on_command_async(
LOAD_MADE_FOR_YOU,
|_| WebApi::global().recommended_stations(),
|_, data, q| data.home_detail.recommended_stations.defer(q),
|_, data, r| data.home_detail.recommended_stations.update(r),
)
}

pub fn uniquely_yours() -> impl Widget<AppState> {
Async::new(spinner_widget, loaded_results_widget.clone(), error_widget)
.lens(
Ctx::make(
AppState::common_ctx,
AppState::home_detail.then(HomeDetail::uniquely_yours),
)
.then(Ctx::in_promise()),
)
.on_command_async(
LOAD_MADE_FOR_YOU,
|_| WebApi::global().uniquely_yours(),
|_, data, q| data.home_detail.uniquely_yours.defer(q),
|_, data, r| data.home_detail.uniquely_yours.update(r),
)
}

pub fn user_top_mixes() -> impl Widget<AppState> {
// We need a way to parse HTML
Async::new(spinner_widget, loaded_results_widget.clone(), error_widget)
Expand Down Expand Up @@ -108,17 +138,36 @@ fn loaded_results_widget() -> impl Widget<WithCtx<MixedView>> {
.padding(theme::grid(6.0))
.center(),
Flex::column()
.with_child(title_label())
.with_child(artist_results_widget())
.with_child(album_results_widget())
.with_child(playlist_results_widget())
.with_child(show_results_widget()),
)
}

fn title_label() -> impl Widget<WithCtx<MixedView>> {
Either::new(
|title_check: &Arc<str>, _| title_check.is_empty(),
Empty,
Flex::column()
.with_default_spacer()
.with_child(Label::raw()
.with_text_size(theme::grid(2.5))
.align_left()
.padding((theme::grid(1.5), 0.0)),)
.with_default_spacer()
.align_left()
)
.lens(Ctx::data().then(MixedView::title))
}

fn artist_results_widget() -> impl Widget<WithCtx<MixedView>> {
Either::new(
|artists: &Vector<Artist>, _| artists.is_empty(),
Empty,
Flex::column().with_child(List::new(artist::recommended_artist_widget)),
Flex::column().with_child(List::new(artist::recommended_artist_widget))
.align_left(),
)
.lens(Ctx::data().then(MixedView::artists))
}
Expand All @@ -127,7 +176,8 @@ fn album_results_widget() -> impl Widget<WithCtx<MixedView>> {
Either::new(
|albums: &Vector<Album>, _| albums.is_empty(),
Empty,
Flex::column().with_child(Label::new("not implemented")),
Flex::column().with_child(Label::new("not implemented"))
.align_left(),
)
.lens(Ctx::data().then(MixedView::albums))
}
Expand All @@ -143,6 +193,7 @@ fn playlist_results_widget() -> impl Widget<WithCtx<MixedView>> {
List::new(|| playlist::horizontal_playlist_widget(false, true)).horizontal(),
)
.horizontal()
.align_left()
.lens(Ctx::map(MixedView::playlists)),
),
)
Expand All @@ -152,7 +203,8 @@ fn show_results_widget() -> impl Widget<WithCtx<MixedView>> {
Either::new(
|shows: &Vector<Show>, _| shows.is_empty(),
Empty,
Flex::column().with_child(Label::new("not implemented")),
Flex::column().with_child(Label::new("not implemented"))
.align_left(),
)
.lens(Ctx::data().then(MixedView::shows))
}
Expand Down
Loading

0 comments on commit 09d8681

Please sign in to comment.