From e8fd578b776db53d0904c7253b07f5f0086ab854 Mon Sep 17 00:00:00 2001 From: Ryan Mwangi Date: Tue, 17 Dec 2024 16:14:49 +0300 Subject: [PATCH] feat(comparison table): add comparison table to compare checked items. --- src/components/items_list.rs | 59 ++++++++++++++++++++++++++++++++++-- 1 file changed, 57 insertions(+), 2 deletions(-) diff --git a/src/components/items_list.rs b/src/components/items_list.rs index 79af6c5..1274ad5 100644 --- a/src/components/items_list.rs +++ b/src/components/items_list.rs @@ -5,13 +5,32 @@ use crate::models::item::Item; #[component] pub fn ItemsList(items: ReadSignal>) -> impl IntoView { + // Create a signal for selected items + let (selected_items_signal, set_selected_items) = create_signal(Vec::::new()); + view! {

{ "Items" }

    {move || items.get().iter().enumerate().map(|(i, item)| view! {
  • + +
    { item.name.clone() } - { item.description.clone() } +

      { "Tags:" }

      {item.tags.iter().map(|(key, value)| view! { @@ -27,7 +46,43 @@ pub fn ItemsList(items: ReadSignal>) -> impl IntoView { }).collect::>()}
    + + // Comparison Table +

    { "Comparison Table" }

    + + + + + + + + + + + {move || { + let selected_indices = selected_items_signal.get(); + selected_indices.iter().map(|&i| { + let item = &items.get()[i]; + view! { + + + + + + + } + }).collect::>() + }} + +
    { "Item Name" }{ "Description" }{ "Tags" }{ "Reviews" }
    { item.name.clone() }{ item.description.clone() } + {item.tags.iter().map(|(key, value)| view! { + { key.clone() + ": " + value + " " } + }).collect::>()} + + {item.reviews.iter().map(|review| view! { + { format!("Rating: {}/5 ", review.rating) } + }).collect::>()} +
} -} - +} \ No newline at end of file