yggdrasil/components/comments/
pending_item.rs1use dioxus::prelude::*;
7
8use crate::utils::comment_storage::{render_pending_content, PendingComment};
9use crate::utils::time::format_relative_time_iso;
10
11#[component]
20#[allow(unused_variables)]
21pub fn PendingCommentItem(comment: PendingComment, post_id: i32) -> Element {
22 let depth = if comment.parent_id.is_none() && comment.depth > 0 {
24 0
25 } else {
26 comment.depth
27 };
28
29 let indent = depth.min(6) * 24;
30 let content_html = render_pending_content(&comment.content_md);
31 let relative_time = format_relative_time_iso(&comment.created_at);
33
34 let author_element = match &comment.author_url {
36 Some(url) if !url.is_empty() => rsx! {
37 a {
38 href: "{url}",
39 rel: "nofollow noopener",
40 target: "_blank",
41 class: "font-medium text-paper-primary hover:text-paper-accent transition-colors",
42 "{comment.author_name}"
43 }
44 },
45 _ => rsx! {
46 span { class: "font-medium text-paper-primary", "{comment.author_name}" }
47 },
48 };
49
50 rsx! {
51 div { class: "py-4 opacity-70", style: "margin-left: {indent}px",
52
53 div { class: "flex gap-3",
54 img {
55 src: "{comment.avatar_url}",
56 alt: "{comment.author_name} 的头像",
57 loading: "lazy",
58 decoding: "async",
59 class: "w-8 h-8 rounded-full shrink-0 mt-0.5 bg-gray-200 dark:bg-gray-800",
60 }
61
62 div { class: "flex-1 min-w-0",
63 div { class: "flex items-center gap-1.5 text-sm mb-1.5 flex-wrap",
64 {author_element}
65 span { class: "text-paper-tertiary", "·" }
66 span {
67 class: "text-paper-tertiary",
68 title: "{comment.created_at}",
69 "{relative_time}"
70 }
71 span { class: "inline-flex items-center px-1.5 py-0.5 rounded text-xs font-medium bg-amber-100 text-amber-700 dark:bg-amber-900/30 dark:text-amber-400",
72 "审核中"
73 }
74 }
75
76 div {
77 class: "prose prose-sm dark:prose-invert max-w-none text-paper-secondary",
78 dangerous_inner_html: "{content_html}",
79 }
80 }
81 }
82 }
83 }
84}