Compare commits
No commits in common. "82b8b447dcddf8c0ad94dbc11b23cfe6031b1f9a" and "fca8c6fa2f071f6fcb4235707c962327932191da" have entirely different histories.
82b8b447dc
...
fca8c6fa2f
2 changed files with 11 additions and 11 deletions
11
src/app.rs
11
src/app.rs
|
@ -1,16 +1,15 @@
|
||||||
use leptos::*;
|
use leptos::*;
|
||||||
use crate::components::{item_form::ItemForm, items_list::ItemsList};
|
use crate::components::{item_form::ItemForm, items_list::ItemsList};
|
||||||
use crate::models::item::Item;
|
use crate::models::item::Item;
|
||||||
use uuid::Uuid;
|
|
||||||
|
|
||||||
#[component]
|
#[component]
|
||||||
pub fn App() -> impl IntoView {
|
pub fn App() -> impl IntoView {
|
||||||
let (items_signal, set_items) = create_signal(Vec::<Item>::new());
|
let (items_signal, set_items) = create_signal(Vec::<Item>::new());
|
||||||
|
|
||||||
let add_item = move |name: String, description: String, tags: Vec<(String, String)>| {
|
let add_item = move |name: String, description: String, tags: Vec<(String, String)>| {
|
||||||
set_items.update(|items| {
|
set_items;(|mut items: Vec<Item>| {
|
||||||
items.push(Item {
|
items.push(Item {
|
||||||
id: Uuid::new_v4().to_string(),
|
id: uuid::Uuid::new_v4().to_string(),
|
||||||
name,
|
name,
|
||||||
description,
|
description,
|
||||||
tags,
|
tags,
|
||||||
|
@ -20,9 +19,9 @@ pub fn App() -> impl IntoView {
|
||||||
|
|
||||||
view! {
|
view! {
|
||||||
<div>
|
<div>
|
||||||
<h1>{ "CompareWare" }</h1>
|
<h1>CompareWare</h1>
|
||||||
<ItemForm on_submit=Box::new(add_item) />
|
<ItemForm on_submit=Box::new(add_item) />
|
||||||
<ItemsList items=items_signal.get() />
|
<ItemsList items={items_signal.get().clone()} />
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,14 +1,15 @@
|
||||||
use leptos::*;
|
use leptos::*;
|
||||||
use leptos_dom::ev::SubmitEvent;
|
use leptos_dom::ev::SubmitEvent; // Import the correct event type
|
||||||
|
|
||||||
#[component]
|
#[component]
|
||||||
pub fn ItemForm(on_submit: Box<dyn Fn(String, String, Vec<(String, String)>)>) -> impl IntoView {
|
pub fn ItemForm(on_submit: Box<dyn Fn(String, String, Vec<String>)>) -> impl IntoView {
|
||||||
let (name, set_name) = create_signal(String::new());
|
let (name, set_name) = create_signal(String::new());
|
||||||
let (description, set_description) = create_signal(String::new());
|
let (description, set_description) = create_signal(String::new());
|
||||||
let (tags, set_tags) = create_signal(Vec::<(String, String)>::new());
|
let (tags, set_tags) = create_signal(Vec::<String>::new());
|
||||||
|
|
||||||
|
// Use SubmitEvent for the form submission handler
|
||||||
let handle_submit = move |ev: SubmitEvent| {
|
let handle_submit = move |ev: SubmitEvent| {
|
||||||
ev.prevent_default();
|
ev.prevent_default(); // Prevent form submission from reloading the page
|
||||||
on_submit(name.get(), description.get(), tags.get().clone());
|
on_submit(name.get(), description.get(), tags.get().clone());
|
||||||
|
|
||||||
// Reset values after submission
|
// Reset values after submission
|
||||||
|
@ -33,4 +34,4 @@ pub fn ItemForm(on_submit: Box<dyn Fn(String, String, Vec<(String, String)>)>) -
|
||||||
<button type="submit">{ "Add Item" }</button>
|
<button type="submit">{ "Add Item" }</button>
|
||||||
</form>
|
</form>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue