From 58e8faa11c57063dea181872a211bf5a7fa15748 Mon Sep 17 00:00:00 2001 From: Ryan Mwangi Date: Mon, 9 Dec 2024 19:24:46 +0300 Subject: [PATCH] refactor(comments): add comments to files --- src/app.rs | 6 ++++++ src/components/item_form.rs | 4 ++++ src/components/items_list.rs | 2 ++ src/models/item.rs | 2 ++ 4 files changed, 14 insertions(+) diff --git a/src/app.rs b/src/app.rs index 4bcffff..66d86a0 100644 --- a/src/app.rs +++ b/src/app.rs @@ -1,3 +1,5 @@ +/// Main application entry point for CompareWare. +/// Combines the item management components (form and list) to provide a cohesive user interface. use leptos::*; use crate::components::{item_form::ItemForm, items_list::ItemsList}; use crate::models::item::Item; @@ -5,8 +7,10 @@ use uuid::Uuid; #[component] pub fn App() -> impl IntoView { + // Signal to store and update the list of items. let (items_signal, set_items) = create_signal(Vec::::new()); + // Function to handle adding a new item to the list. let add_item = move |name: String, description: String, tags: Vec<(String, String)>| { set_items.update(|items| { items.push(Item { @@ -21,7 +25,9 @@ pub fn App() -> impl IntoView { view! {

{ "CompareWare" }

+ // Form component for adding new items. + // Component to display the list of items.
} diff --git a/src/components/item_form.rs b/src/components/item_form.rs index ed98fff..7e6c12b 100644 --- a/src/components/item_form.rs +++ b/src/components/item_form.rs @@ -1,3 +1,6 @@ +/// Form component for adding a new item. +/// Handles user input for item name, description, and optional tags. +/// Calls `on_submit` when the form is submitted. use leptos::*; use leptos_dom::ev::SubmitEvent; @@ -7,6 +10,7 @@ pub fn ItemForm(on_submit: Box)>) - let (description, set_description) = create_signal(String::new()); let (tags, set_tags) = create_signal(Vec::<(String, String)>::new()); + // Handle form submission. let handle_submit = move |ev: SubmitEvent| { ev.prevent_default(); on_submit(name.get(), description.get(), tags.get().clone()); diff --git a/src/components/items_list.rs b/src/components/items_list.rs index 2393fb9..202c92b 100644 --- a/src/components/items_list.rs +++ b/src/components/items_list.rs @@ -1,3 +1,5 @@ +/// Component to display a list of items. +/// Iterates through the items and renders their name, description, and tags. use leptos::*; use crate::models::item::Item; diff --git a/src/models/item.rs b/src/models/item.rs index bdb3402..545e8f8 100644 --- a/src/models/item.rs +++ b/src/models/item.rs @@ -1,3 +1,5 @@ +/// Represents an Item in CompareWare. +/// Each item has metadata and key-value tags for categorization. use serde::{Deserialize, Serialize}; #[derive(Serialize, Deserialize, Debug, Clone)]