app,server: Display rating in recipe
This commit is contained in:
parent
1ea5c8aafa
commit
5ef000dec0
3 changed files with 28 additions and 8 deletions
|
|
@ -99,12 +99,13 @@ pub struct CreateRecipeResponse {
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Clone, Debug)]
|
#[derive(Serialize, Deserialize, Clone, Debug)]
|
||||||
pub struct ListRecipesResponse {
|
pub struct ListRecipesResponse {
|
||||||
pub recipes: Vec<(i64, String)>,
|
pub recipes: Vec<(i64, String, u8)>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Clone, Debug)]
|
#[derive(Serialize, Deserialize, Clone, Debug)]
|
||||||
pub struct RecipeInfo {
|
pub struct RecipeInfo {
|
||||||
pub name: String,
|
pub name: String,
|
||||||
|
pub rating: u8,
|
||||||
pub steps: String,
|
pub steps: String,
|
||||||
pub ingredients: Vec<(i64, IngredientInfo, f64)>,
|
pub ingredients: Vec<(i64, IngredientInfo, f64)>,
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -50,7 +50,7 @@ fn RecipeListInner(props: &RecipeListProps) -> HtmlResult {
|
||||||
Ok(l) => html! {
|
Ok(l) => html! {
|
||||||
<div class="container text-center">
|
<div class="container text-center">
|
||||||
<div class="row row-cols-2 row-cols-sm-2 row-cols-md-4 g-2 mb-2">
|
<div class="row row-cols-2 row-cols-sm-2 row-cols-md-4 g-2 mb-2">
|
||||||
{for l.recipes.iter().sorted_by_key(|(_, name)| name).map(|(id, name)| html!{
|
{for l.recipes.iter().sorted_by_key(|(_, name, _)| name).map(|(id, name, _)| html!{
|
||||||
<div class="col" key={*id}>
|
<div class="col" key={*id}>
|
||||||
<div class="p-3 border rounded border-light-subtle h-100">
|
<div class="p-3 border rounded border-light-subtle h-100">
|
||||||
<Link<Route>
|
<Link<Route>
|
||||||
|
|
@ -623,6 +623,21 @@ fn EditSteps(props: &EditStepsProps) -> Html {
|
||||||
</>}
|
</>}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, PartialEq, Properties)]
|
||||||
|
struct RecipeRatingProps {
|
||||||
|
rating: u8,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[function_component]
|
||||||
|
fn RecipeRating(props: &RecipeRatingProps) -> Html {
|
||||||
|
let rating = (props.rating + 1).min(3);
|
||||||
|
html! {
|
||||||
|
<div aria-label={format!("Rating: {rating}")}>
|
||||||
|
{ for (0..rating).map(|_| html!{<i aria-hidden="true" class="bi-star-fill" />}) }
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[function_component]
|
#[function_component]
|
||||||
fn RecipeViewerInner(props: &RecipeViewerInnerProps) -> HtmlResult {
|
fn RecipeViewerInner(props: &RecipeViewerInnerProps) -> HtmlResult {
|
||||||
let recipe_render = use_state(|| 0u64);
|
let recipe_render = use_state(|| 0u64);
|
||||||
|
|
@ -664,11 +679,6 @@ fn RecipeViewerInner(props: &RecipeViewerInnerProps) -> HtmlResult {
|
||||||
Ok(match &*recipe {
|
Ok(match &*recipe {
|
||||||
Ok(r) => html! {<>
|
Ok(r) => html! {<>
|
||||||
<h1>{&r.name}</h1>
|
<h1>{&r.name}</h1>
|
||||||
if let Some(e) = &*error {
|
|
||||||
<div class={classes!("alert", "alert-danger")} role="alert">
|
|
||||||
{e}
|
|
||||||
</div>
|
|
||||||
}
|
|
||||||
<EditName
|
<EditName
|
||||||
token={props.token.clone()}
|
token={props.token.clone()}
|
||||||
id={props.id}
|
id={props.id}
|
||||||
|
|
@ -676,6 +686,14 @@ fn RecipeViewerInner(props: &RecipeViewerInnerProps) -> HtmlResult {
|
||||||
name={r.name.clone()}
|
name={r.name.clone()}
|
||||||
update={update.clone()}
|
update={update.clone()}
|
||||||
/>
|
/>
|
||||||
|
<div class="mt-2">
|
||||||
|
<RecipeRating rating={r.rating}/>
|
||||||
|
</div>
|
||||||
|
if let Some(e) = &*error {
|
||||||
|
<div class={classes!("alert", "alert-danger")} role="alert">
|
||||||
|
{e}
|
||||||
|
</div>
|
||||||
|
}
|
||||||
<hr />
|
<hr />
|
||||||
<div class="text-start">
|
<div class="text-start">
|
||||||
<h2>{"Ingredients"}</h2>
|
<h2>{"Ingredients"}</h2>
|
||||||
|
|
|
||||||
|
|
@ -76,7 +76,7 @@ pub(super) async fn list_recipes(
|
||||||
.all(&state.db)
|
.all(&state.db)
|
||||||
.await?
|
.await?
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|r| (r.id, r.name))
|
.map(|r| (r.id, r.name, r.ranking as _))
|
||||||
.collect(),
|
.collect(),
|
||||||
}
|
}
|
||||||
.into())
|
.into())
|
||||||
|
|
@ -144,6 +144,7 @@ pub(super) async fn fetch_recipe(
|
||||||
Ok(RecipeInfo {
|
Ok(RecipeInfo {
|
||||||
name: recipe.name,
|
name: recipe.name,
|
||||||
steps: recipe.steps,
|
steps: recipe.steps,
|
||||||
|
rating: recipe.ranking as _,
|
||||||
ingredients,
|
ingredients,
|
||||||
}
|
}
|
||||||
.into())
|
.into())
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue