Compare commits
No commits in common. "2b36a7c669509390094d47b6c3a515e8b47409b1" and "792b06a2ebbc6bfc2bf24d7a78f9e4ce635ec06a" have entirely different histories.
2b36a7c669
...
792b06a2eb
@ -3,15 +3,12 @@ use dioxus::prelude::*;
|
||||
use crate::api::comments::create_comment;
|
||||
use crate::components::comments::section::CommentContext;
|
||||
use crate::components::forms::{INPUT_CLASS, BUTTON_PRIMARY_CLASS, AlertBox};
|
||||
use crate::hooks::comment_storage::{self, PendingComment};
|
||||
|
||||
#[component]
|
||||
pub fn CommentForm(post_id: i32, parent_id: Option<i64>) -> Element {
|
||||
let ctx: CommentContext = use_context();
|
||||
let mut active_reply = ctx.active_reply;
|
||||
let mut refresh_trigger = ctx.refresh_trigger;
|
||||
let mut pending_comments = ctx.pending_comments;
|
||||
|
||||
let mut author_name = use_signal(String::new);
|
||||
let mut author_email = use_signal(String::new);
|
||||
let mut author_url = use_signal(String::new);
|
||||
@ -19,19 +16,6 @@ pub fn CommentForm(post_id: i32, parent_id: Option<i64>) -> Element {
|
||||
let mut honeypot = use_signal(String::new);
|
||||
let mut submitting = use_signal(|| false);
|
||||
let mut message = use_signal(|| Option::<(String, &'static str)>::None);
|
||||
let mut loaded = use_signal(|| false);
|
||||
|
||||
use_effect(move || {
|
||||
if loaded() {
|
||||
return;
|
||||
}
|
||||
loaded.set(true);
|
||||
if let Some(info) = comment_storage::load_author() {
|
||||
author_name.set(info.name);
|
||||
author_email.set(info.email);
|
||||
author_url.set(info.url);
|
||||
}
|
||||
});
|
||||
|
||||
if let Some(pid) = parent_id {
|
||||
if active_reply() != Some(pid) {
|
||||
@ -119,10 +103,6 @@ pub fn CommentForm(post_id: i32, parent_id: Option<i64>) -> Element {
|
||||
class: BUTTON_PRIMARY_CLASS,
|
||||
disabled: submitting(),
|
||||
onclick: move |_| {
|
||||
if submitting() {
|
||||
return;
|
||||
}
|
||||
|
||||
let post_id = post_id;
|
||||
let parent_id = parent_id;
|
||||
let name = author_name();
|
||||
@ -147,10 +127,10 @@ pub fn CommentForm(post_id: i32, parent_id: Option<i64>) -> Element {
|
||||
let result = create_comment(
|
||||
post_id,
|
||||
parent_id,
|
||||
name.clone(),
|
||||
email.clone(),
|
||||
if url_val.trim().is_empty() { None } else { Some(url_val.clone()) },
|
||||
content.clone(),
|
||||
name,
|
||||
email,
|
||||
if url_val.trim().is_empty() { None } else { Some(url_val) },
|
||||
content,
|
||||
).await;
|
||||
|
||||
submitting.set(false);
|
||||
@ -158,33 +138,6 @@ pub fn CommentForm(post_id: i32, parent_id: Option<i64>) -> Element {
|
||||
match result {
|
||||
Ok(resp) => {
|
||||
if resp.success {
|
||||
comment_storage::save_author(
|
||||
&name,
|
||||
&email,
|
||||
&url_val,
|
||||
);
|
||||
|
||||
if let Some(comment_id) = resp.comment_id {
|
||||
let avatar_url = resp.avatar_url.unwrap_or_default();
|
||||
let depth = resp.depth.unwrap_or(0);
|
||||
|
||||
let now = chrono::Utc::now().to_rfc3339();
|
||||
let pending = PendingComment {
|
||||
id: comment_id,
|
||||
parent_id,
|
||||
depth,
|
||||
author_name: name.clone(),
|
||||
author_url: if url_val.trim().is_empty() { None } else { Some(url_val) },
|
||||
avatar_url,
|
||||
content_md: content,
|
||||
created_at: now.clone(),
|
||||
stored_at: now,
|
||||
};
|
||||
|
||||
comment_storage::save_pending_comment(post_id, pending.clone());
|
||||
pending_comments.write().push(pending);
|
||||
}
|
||||
|
||||
content_md.set(String::new());
|
||||
message.set(Some((resp.message, "success")));
|
||||
if parent_id.is_some() {
|
||||
|
||||
@ -46,12 +46,16 @@ pub fn CommentList(
|
||||
rsx! {
|
||||
div { class: "space-y-0 divide-y divide-gray-100 dark:divide-[#2a2a2a]",
|
||||
for item in merged {
|
||||
let key_id = match &item {
|
||||
MergedComment::Approved(c) => c.id,
|
||||
MergedComment::Pending(c) => c.id,
|
||||
};
|
||||
match item {
|
||||
MergedComment::Approved(comment) => rsx! {
|
||||
CommentItem { key: "{comment.id}", comment, post_id }
|
||||
CommentItem { key: "{key_id}", comment, post_id }
|
||||
},
|
||||
MergedComment::Pending(comment) => rsx! {
|
||||
PendingCommentItem { key: "{comment.id}", comment, post_id }
|
||||
PendingCommentItem { key: "{key_id}", comment, post_id }
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@ -3,8 +3,7 @@ use dioxus::prelude::*;
|
||||
use crate::hooks::comment_storage::{PendingComment, render_pending_content};
|
||||
|
||||
#[component]
|
||||
#[allow(unused_variables)]
|
||||
pub fn PendingCommentItem(comment: PendingComment, post_id: i32) -> Element {
|
||||
pub fn PendingCommentItem(comment: PendingComment, _post_id: i32) -> Element {
|
||||
|
||||
let depth = if comment.parent_id.is_none() && comment.depth > 0 {
|
||||
0
|
||||
|
||||
@ -45,8 +45,8 @@ pub fn CommentSection(post_id: i32) -> Element {
|
||||
pending.write().retain(|c| !to_remove.contains(&c.id));
|
||||
}
|
||||
}
|
||||
Err(_e) => {
|
||||
// Silently ignore on WASM; server-only logging not available
|
||||
Err(e) => {
|
||||
tracing::warn!("check_pending_status failed: {}", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
use chrono::DateTime;
|
||||
use chrono::{DateTime, Utc};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
const AUTHOR_KEY: &str = "yggdrasil-comment-author";
|
||||
@ -28,7 +28,6 @@ pub struct PendingComment {
|
||||
|
||||
type PendingMap = std::collections::HashMap<String, Vec<PendingComment>>;
|
||||
|
||||
#[allow(unused_variables)]
|
||||
fn read_storage(key: &str) -> Option<String> {
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
{
|
||||
@ -42,7 +41,6 @@ fn read_storage(key: &str) -> Option<String> {
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(unused_variables)]
|
||||
fn write_storage(key: &str, value: &str) {
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
{
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user