fix: fix App component signal handling and on_submit prop

- Replaced incorrect path statement in `add_item` with proper use of `set_items.update` for signal mutation.
- Fixed dynamic dispatch for `on_submit` by boxing the `add_item` closure.
- Simplified `items_signal` usage by removing unnecessary `.clone()`.
- Improved code consistency and alignment with the latest Leptos updates.
This commit is contained in:
Ryan Mwangi 2024-12-09 14:58:05 +03:00
parent fca8c6fa2f
commit 8c03fa35a1
1 changed files with 6 additions and 5 deletions

View File

@ -1,15 +1,16 @@
use leptos::*;
use crate::components::{item_form::ItemForm, items_list::ItemsList};
use crate::models::item::Item;
use uuid::Uuid;
#[component]
pub fn App() -> impl IntoView {
let (items_signal, set_items) = create_signal(Vec::<Item>::new());
let add_item = move |name: String, description: String, tags: Vec<(String, String)>| {
set_items;(|mut items: Vec<Item>| {
set_items.update(|items| {
items.push(Item {
id: uuid::Uuid::new_v4().to_string(),
id: Uuid::new_v4().to_string(),
name,
description,
tags,
@ -19,9 +20,9 @@ pub fn App() -> impl IntoView {
view! {
<div>
<h1>CompareWare</h1>
<h1>{ "CompareWare" }</h1>
<ItemForm on_submit=Box::new(add_item) />
<ItemsList items={items_signal.get().clone()} />
<ItemsList items=items_signal.get() />
</div>
}
}
}