From bbc4f9a2cd293f73d1a1bfd6dbc9c6dd806cb570 Mon Sep 17 00:00:00 2001 From: Ryan Mwangi Date: Mon, 16 Dec 2024 22:16:55 +0300 Subject: [PATCH] fix(reviews): handle review item_id to stop panic while serving --- src/app.rs | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/src/app.rs b/src/app.rs index 5cae531..f2bab4e 100644 --- a/src/app.rs +++ b/src/app.rs @@ -2,7 +2,7 @@ /// Combines the item management components (form and list) to provide a cohesive user interface. use leptos::*; use leptos_meta::*; -use crate::components::{item_form::ItemForm, items_list::ItemsList, review_form::ReviewForm, reviews_list::ReviewsList }; +use crate::components::{item_form::ItemForm, items_list::ItemsList, review_form::ReviewForm, reviews_list::ReviewsList}; use crate::models::item::Item; use crate::nostr::NostrClient; use tokio::sync::mpsc; @@ -13,27 +13,34 @@ use nostr_sdk::serde_json; #[component] pub fn App() -> impl IntoView { provide_meta_context(); + // Signal to store and update the list of items. let (items_signal, set_items) = create_signal(Vec::::new()); + // Signal to store the ID of the current item for reviews + let (current_item_id, set_current_item_id) = create_signal(String::new()); let (tx, mut rx) = mpsc::channel::(100); spawn_local(async move { - //initialize nostr client + // Initialize Nostr client let nostr_client = NostrClient::new("wss://relay.damus.io").await.unwrap(); nostr_client.subscribe_to_items(tx.clone()).await.unwrap(); - //handle incoming events + // Handle incoming events while let Some(content) = rx.recv().await { if let Ok(item) = serde_json::from_str::(&content) { set_items.update(|items| items.push(item)); } } }); + // Function to handle adding a new item to the list. let add_item = move |name: String, description: String, tags: Vec<(String, String)>| { + let new_id = Uuid::new_v4().to_string(); // Generate a new UUID for the item + set_current_item_id.set(new_id.clone()); // Update the current item ID + set_items.update(|items| { let item = Item { - id: Uuid::new_v4().to_string(), + id: new_id, name: name.clone(), description: description.clone(), tags: tags.clone(), @@ -49,8 +56,9 @@ pub fn App() -> impl IntoView { }; // Handle review submission - let submit_review = move |_| { - // Handle the review submission logic + let submit_review = move |review_content: String| { + // Logic for submitting a review + println!("Review submitted: {}", review_content); }; view! { @@ -60,12 +68,13 @@ pub fn App() -> impl IntoView {

{ "CompareWare" }

// Form component for adding new items. + // Reviews form + // Component to display the list of items. - // Reviews form and list - - + // Component to display the list of reviews for the current item. + } -} \ No newline at end of file +}