Compware/src/components/items_list.rs

34 lines
1.3 KiB
Rust
Raw Normal View History

/// Component to display a list of items.
/// Iterates through the items and renders their name, description, tags, and reviews.
2024-12-06 14:45:14 +03:00
use leptos::*;
use crate::models::item::Item;
#[component]
pub fn ItemsList(items: ReadSignal<Vec<Item>>) -> impl IntoView {
2024-12-06 14:45:14 +03:00
view! {
<div>
<h2>{ "Items" }</h2>
<ul>
2024-12-17 13:39:41 +03:00
{move || items.get().iter().enumerate().map(|(i, item)| view! {
2024-12-06 14:45:14 +03:00
<li key={i.to_string()}>
<strong>{ item.name.clone() }</strong> - { item.description.clone() }
<ul>
2024-12-17 13:39:41 +03:00
<h4>{ "Tags:" }</h4>
2024-12-06 14:45:14 +03:00
{item.tags.iter().map(|(key, value)| view! {
2024-12-17 13:39:41 +03:00
<li>{ key.clone() + ": " + value }</li>
}).collect::<Vec<_>>()}
</ul>
<ul>
2024-12-17 13:39:41 +03:00
<h4>{ "Reviews:" }</h4>
{item.reviews.iter().map(|review| view! {
2024-12-17 13:39:41 +03:00
<li>{ format!("Rating: {}/5 - {}", review.rating, review.content) }</li>
2024-12-06 14:45:14 +03:00
}).collect::<Vec<_>>()}
</ul>
</li>
}).collect::<Vec<_>>()}
</ul>
</div>
}
}
2024-12-17 13:39:41 +03:00