feat(reviews): add reviews section

This commit is contained in:
Ryan 2024-12-16 19:06:33 +03:00
parent 06bd46c40c
commit ccd23654e3
7 changed files with 74 additions and 1 deletions

View File

@ -2,8 +2,9 @@
/// Combines the item management components (form and list) to provide a cohesive user interface.
use leptos::*;
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::review::Review;
use crate::nostr::NostrClient;
use tokio::sync::mpsc;
use uuid::Uuid;
@ -37,6 +38,7 @@ pub fn App() -> impl IntoView {
name: name.clone(),
description: description.clone(),
tags: tags.clone(),
reviews: vec![],
};
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! {
<>
<Stylesheet href="/assets/style.css" />
@ -56,6 +63,9 @@ pub fn App() -> impl IntoView {
<ItemForm on_submit=Box::new(add_item) />
// Component to display the list of items.
<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>
</>
}

View File

@ -1,2 +1,4 @@
pub mod item_form;
pub mod items_list;
pub mod review_form;
pub mod reviews_list;

View File

@ -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>
}
}

View File

@ -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>
}
}

View File

@ -2,10 +2,18 @@
/// Each item has metadata and key-value tags for categorization.
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)]
pub struct Item {
pub id: String, // Unique ID for the item
pub name: String, // Item name
pub description: String, // Short description of the item
pub tags: Vec<(String, String)>, // Key-value tags (e.g., "type" -> "software")
pub reviews: Vec<Review>, // Reviews
}

View File

@ -1 +1,2 @@
pub mod item;
pub mod review;

9
src/models/review.rs Normal file
View File

@ -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
}