2024-12-09 19:24:46 +03:00
|
|
|
/// 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::*;
|
|
|
|
use crate::components::{item_form::ItemForm, items_list::ItemsList};
|
|
|
|
use crate::models::item::Item;
|
2024-12-09 14:58:05 +03:00
|
|
|
use uuid::Uuid;
|
2024-12-06 14:45:14 +03:00
|
|
|
|
|
|
|
#[component]
|
|
|
|
pub fn App() -> impl IntoView {
|
2024-12-09 19:24:46 +03:00
|
|
|
// Signal to store and update the list of items.
|
2024-12-09 13:56:39 +03:00
|
|
|
let (items_signal, set_items) = create_signal(Vec::<Item>::new());
|
2024-12-06 14:45:14 +03:00
|
|
|
|
2024-12-09 19:24:46 +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)>| {
|
2024-12-09 14:58:05 +03:00
|
|
|
set_items.update(|items| {
|
2024-12-06 14:45:14 +03:00
|
|
|
items.push(Item {
|
2024-12-09 14:58:05 +03:00
|
|
|
id: Uuid::new_v4().to_string(),
|
2024-12-06 14:45:14 +03:00
|
|
|
name,
|
|
|
|
description,
|
|
|
|
tags,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
view! {
|
|
|
|
<div>
|
2024-12-09 14:58:05 +03:00
|
|
|
<h1>{ "CompareWare" }</h1>
|
2024-12-09 19:24:46 +03:00
|
|
|
// Form component for adding new items.
|
2024-12-09 13:56:39 +03:00
|
|
|
<ItemForm on_submit=Box::new(add_item) />
|
2024-12-09 19:24:46 +03:00
|
|
|
// Component to display the list of items.
|
2024-12-09 14:58:05 +03:00
|
|
|
<ItemsList items=items_signal.get() />
|
2024-12-06 14:45:14 +03:00
|
|
|
</div>
|
|
|
|
}
|
2024-12-09 14:58:05 +03:00
|
|
|
}
|