Skip to content

Commit

Permalink
Merge pull request #38 from MaarifaMaarifa/search-results-refactor
Browse files Browse the repository at this point in the history
Search results refactor
  • Loading branch information
MaarifaMaarifa authored Oct 4, 2023
2 parents f60ff78 + 9873e67 commit 4a66618
Showing 1 changed file with 30 additions and 16 deletions.
46 changes: 30 additions & 16 deletions src/gui/tabs/discover_tab/searching.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,11 +149,12 @@ impl Search {
};

let search_results = search_results.map(|search_results| {
scrollable(
container(search_results)
.style(styles::container_styles::first_class_container_rounded_theme()),
container(
scrollable(search_results)
.direction(styles::scrollable_styles::vertical_direction()),
)
.direction(styles::scrollable_styles::vertical_direction())
.padding(5)
.style(styles::container_styles::first_class_container_rounded_theme())
.into()
});

Expand All @@ -165,13 +166,15 @@ mod search_result {
use std::sync::mpsc;

use bytes::Bytes;
use iced::widget::{column, image, mouse_area, row, text, Space};
use iced::widget::{column, image, mouse_area, row, svg, text, Space};
use iced::{Command, Element, Renderer};

use crate::core::api::tv_maze::series_information::SeriesMainInformation;
use crate::core::api::tv_maze::Rating;
use crate::core::{api::tv_maze::series_searching, caching};
use crate::gui::assets::icons::STAR_FILL;
pub use crate::gui::message::IndexedMessage;
use crate::gui::styles;
use crate::gui::{helpers, styles};

#[derive(Debug, Clone)]
pub enum Message {
Expand Down Expand Up @@ -236,16 +239,9 @@ mod search_result {
// Getting the series genres
let genres: Element<'_, Message, Renderer> =
if !self.search_result.show.genres.is_empty() {
let mut genres = String::from("Genres: ");

let mut series_result_iter = self.search_result.show.genres.iter().peekable();
while let Some(genre) = series_result_iter.next() {
genres.push_str(genre);
if series_result_iter.peek().is_some() {
genres.push_str(", ");
}
}
text(genres).size(11).into()
text(helpers::genres_with_pipes(&self.search_result.show.genres))
.size(11)
.into()
} else {
Space::new(0, 0).into()
};
Expand All @@ -261,10 +257,28 @@ mod search_result {
column = column.push(text(format!("Premiered: {}", premier)).size(9));
}

column = column.push(Self::rating_widget(&self.search_result.show.rating));

let element: Element<'_, Message, Renderer> = mouse_area(row.push(column))
.on_press(Message::SeriesResultPressed)
.into();
element.map(|message| IndexedMessage::new(self.index, message))
}

fn rating_widget(rating: &Rating) -> Element<'_, Message, Renderer> {
if let Some(average_rating) = rating.average {
let star_handle = svg::Handle::from_memory(STAR_FILL);
let star_icon = svg(star_handle)
.width(12)
.height(12)
.style(styles::svg_styles::colored_svg_theme());

row![star_icon, text(average_rating).size(11)]
.spacing(5)
.into()
} else {
Space::new(0, 0).into()
}
}
}
}

0 comments on commit 4a66618

Please sign in to comment.