Compware/src/app.rs

40 lines
1.2 KiB
Rust
Raw Normal View History

/// Main application entry point for CompareWare.
/// Combines the item management components (form and list) to provide a cohesive user interface.
2024-12-06 14:45:14 +03:00
use leptos::*;
2024-12-10 18:35:39 +03:00
use leptos_meta::*;
2024-12-06 14:45:14 +03:00
use crate::components::{item_form::ItemForm, items_list::ItemsList};
use crate::models::item::Item;
use uuid::Uuid;
2024-12-06 14:45:14 +03:00
#[component]
pub fn App() -> impl IntoView {
2024-12-10 18:35:39 +03:00
provide_meta_context();
// Signal to store and update the list of items.
let (items_signal, set_items) = create_signal(Vec::<Item>::new());
2024-12-06 14:45:14 +03:00
// Function to handle adding a new item to the list.
2024-12-06 14:45:14 +03:00
let add_item = move |name: String, description: String, tags: Vec<(String, String)>| {
set_items.update(|items| {
2024-12-06 14:45:14 +03:00
items.push(Item {
id: Uuid::new_v4().to_string(),
2024-12-06 14:45:14 +03:00
name,
description,
tags,
});
});
};
view! {
2024-12-10 18:35:39 +03:00
<>
<Stylesheet href="/assets/style.css" />
<div>
<h1>{ "CompareWare" }</h1>
// Form component for adding new items.
<ItemForm on_submit=Box::new(add_item) />
// Component to display the list of items.
<ItemsList items=items_signal />
</div>
</>
2024-12-06 14:45:14 +03:00
}
}