feat(reviews): add reviews section
This commit is contained in:
parent
06bd46c40c
commit
ccd23654e3
12
src/app.rs
12
src/app.rs
|
@ -2,8 +2,9 @@
|
||||||
/// Combines the item management components (form and list) to provide a cohesive user interface.
|
/// Combines the item management components (form and list) to provide a cohesive user interface.
|
||||||
use leptos::*;
|
use leptos::*;
|
||||||
use leptos_meta::*;
|
use leptos_meta::*;
|
||||||
use crate::components::{item_form::ItemForm, items_list::ItemsList};
|
use crate::components::{item_form::ItemForm, items_list::ItemsList, review_form::ReviewForm, reviews_list::ReviewsList };
|
||||||
use crate::models::item::Item;
|
use crate::models::item::Item;
|
||||||
|
use crate::models::review::Review;
|
||||||
use crate::nostr::NostrClient;
|
use crate::nostr::NostrClient;
|
||||||
use tokio::sync::mpsc;
|
use tokio::sync::mpsc;
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
@ -37,6 +38,7 @@ pub fn App() -> impl IntoView {
|
||||||
name: name.clone(),
|
name: name.clone(),
|
||||||
description: description.clone(),
|
description: description.clone(),
|
||||||
tags: tags.clone(),
|
tags: tags.clone(),
|
||||||
|
reviews: vec![],
|
||||||
};
|
};
|
||||||
items.push(item);
|
items.push(item);
|
||||||
});
|
});
|
||||||
|
@ -47,6 +49,11 @@ pub fn App() -> impl IntoView {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Handle review submission
|
||||||
|
let submit_review = move |content: String| {
|
||||||
|
// Handle the review submission logic
|
||||||
|
};
|
||||||
|
|
||||||
view! {
|
view! {
|
||||||
<>
|
<>
|
||||||
<Stylesheet href="/assets/style.css" />
|
<Stylesheet href="/assets/style.css" />
|
||||||
|
@ -56,6 +63,9 @@ pub fn App() -> impl IntoView {
|
||||||
<ItemForm on_submit=Box::new(add_item) />
|
<ItemForm on_submit=Box::new(add_item) />
|
||||||
// Component to display the list of items.
|
// Component to display the list of items.
|
||||||
<ItemsList items=items_signal />
|
<ItemsList items=items_signal />
|
||||||
|
// Reviews form and list
|
||||||
|
<ReviewForm item_id={items_signal.get().first().unwrap().id.clone()} on_submit={submit_review} />
|
||||||
|
<ReviewsList reviews={vec![]} />
|
||||||
</div>
|
</div>
|
||||||
</>
|
</>
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,2 +1,4 @@
|
||||||
pub mod item_form;
|
pub mod item_form;
|
||||||
pub mod items_list;
|
pub mod items_list;
|
||||||
|
pub mod review_form;
|
||||||
|
pub mod reviews_list;
|
||||||
|
|
|
@ -0,0 +1,25 @@
|
||||||
|
use leptos::*;
|
||||||
|
use crate::models::item::Item;
|
||||||
|
use leptos::ev::Event;
|
||||||
|
|
||||||
|
|
||||||
|
#[component]
|
||||||
|
pub fn ReviewForm(item_id: String, on_submit: impl Fn(String) + 'static) -> impl IntoView {
|
||||||
|
let (review_content, set_review_content) = create_signal(String::new());
|
||||||
|
|
||||||
|
let submit_review = move |e| {
|
||||||
|
on_submit(review_content.get());
|
||||||
|
};
|
||||||
|
|
||||||
|
view! {
|
||||||
|
<div>
|
||||||
|
<h3>{ "Submit Review" }</h3>
|
||||||
|
<textarea
|
||||||
|
placeholder="Write your review here"
|
||||||
|
value={review_content.get()}
|
||||||
|
oninput={move |e: Event| set_review_content(e.target().unwrap().value())}
|
||||||
|
/>
|
||||||
|
<button onclick={submit_review}>{ "Submit Review" }</button>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,18 @@
|
||||||
|
use leptos::*;
|
||||||
|
use crate::models::review::Review;
|
||||||
|
|
||||||
|
#[component]
|
||||||
|
pub fn ReviewsList(reviews: Vec<Review>) -> impl IntoView {
|
||||||
|
view! {
|
||||||
|
<div>
|
||||||
|
<h3>{ "Reviews" }</h3>
|
||||||
|
<ul>
|
||||||
|
{ for review in reviews {
|
||||||
|
view! {
|
||||||
|
<li>{ &review.content }</li>
|
||||||
|
}
|
||||||
|
} }
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
}
|
|
@ -2,10 +2,18 @@
|
||||||
/// Each item has metadata and key-value tags for categorization.
|
/// Each item has metadata and key-value tags for categorization.
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
pub struct Review {
|
||||||
|
pub user_id: String,
|
||||||
|
pub title: String,
|
||||||
|
pub content: String,
|
||||||
|
pub timestamp: i64,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||||
pub struct Item {
|
pub struct Item {
|
||||||
pub id: String, // Unique ID for the item
|
pub id: String, // Unique ID for the item
|
||||||
pub name: String, // Item name
|
pub name: String, // Item name
|
||||||
pub description: String, // Short description of the item
|
pub description: String, // Short description of the item
|
||||||
pub tags: Vec<(String, String)>, // Key-value tags (e.g., "type" -> "software")
|
pub tags: Vec<(String, String)>, // Key-value tags (e.g., "type" -> "software")
|
||||||
|
pub reviews: Vec<Review>, // Reviews
|
||||||
}
|
}
|
||||||
|
|
|
@ -1 +1,2 @@
|
||||||
pub mod item;
|
pub mod item;
|
||||||
|
pub mod review;
|
|
@ -0,0 +1,9 @@
|
||||||
|
// src/models/review.rs
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||||
|
pub struct Review {
|
||||||
|
pub item_id: String, // ID of the item the review is associated with
|
||||||
|
pub content: String, // Content of the review
|
||||||
|
pub user_id: String, // ID of the user who submitted the review
|
||||||
|
}
|
Loading…
Reference in New Issue