From 759bbab7ee71184f9aa92b7392f5414def2b2c51 Mon Sep 17 00:00:00 2001 From: xfy Date: Thu, 2 Jul 2026 16:18:52 +0800 Subject: [PATCH] =?UTF-8?q?refactor(utils):=20comment=5Fstorage=20?= =?UTF-8?q?=E4=BB=8E=20hooks/=20=E8=BF=81=E8=87=B3=20utils/?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 该文件全是普通函数(save_author / load_pending_comments 等),没有任何 use_ 开头的 Hook,放在 hooks/ 下名不副实。内部只剩结构体与 localStorage 读写(时间/HTML 工具已在上一 commit 拆出),迁到 utils/ 后文件名与内容 自洽,hooks/ 目录回归只放真正的渲染期 Hook。 机械替换 4 个组件文件的 use 路径(hooks::comment_storage → utils::comment_storage)。 --- src/components/comments/form.rs | 2 +- src/components/comments/list.rs | 2 +- src/components/comments/pending_item.rs | 2 +- src/components/comments/section.rs | 2 +- src/hooks/mod.rs | 7 +++---- src/{hooks => utils}/comment_storage.rs | 0 src/utils/html.rs | 2 +- src/utils/mod.rs | 3 +++ 8 files changed, 11 insertions(+), 9 deletions(-) rename src/{hooks => utils}/comment_storage.rs (100%) diff --git a/src/components/comments/form.rs b/src/components/comments/form.rs index e3c917a..9a2dc91 100644 --- a/src/components/comments/form.rs +++ b/src/components/comments/form.rs @@ -7,7 +7,7 @@ use dioxus::prelude::*; use crate::api::comments::create_comment; use crate::components::comments::section::CommentContext; use crate::components::forms::{AlertBox, INPUT_CLASS}; -use crate::hooks::comment_storage::{self, PendingComment}; +use crate::utils::comment_storage::{self, PendingComment}; /// 评论提交按钮样式:去掉全宽,改为内联宽度并右对齐。 /// diff --git a/src/components/comments/list.rs b/src/components/comments/list.rs index ce6cdb3..d1c2218 100644 --- a/src/components/comments/list.rs +++ b/src/components/comments/list.rs @@ -6,7 +6,7 @@ use dioxus::prelude::*; use crate::components::comments::item::CommentItem; use crate::components::comments::pending_item::PendingCommentItem; -use crate::hooks::comment_storage::PendingComment; +use crate::utils::comment_storage::PendingComment; use crate::models::comment::PublicComment; /// 合并后的评论节点,可能是已审核或待审核评论。 diff --git a/src/components/comments/pending_item.rs b/src/components/comments/pending_item.rs index dadb003..f52206c 100644 --- a/src/components/comments/pending_item.rs +++ b/src/components/comments/pending_item.rs @@ -5,7 +5,7 @@ use dioxus::prelude::*; -use crate::hooks::comment_storage::{render_pending_content, PendingComment}; +use crate::utils::comment_storage::{render_pending_content, PendingComment}; use crate::utils::time::format_relative_time_iso; /// 待审核评论项组件。 diff --git a/src/components/comments/section.rs b/src/components/comments/section.rs index f30ec97..67cd609 100644 --- a/src/components/comments/section.rs +++ b/src/components/comments/section.rs @@ -9,7 +9,7 @@ use crate::api::comments::{check_pending_status, get_comments, CommentTreeRespon use crate::components::comments::form::CommentForm; use crate::components::comments::list::CommentList; use crate::components::skeletons::comment_skeleton::CommentListSkeleton; -use crate::hooks::comment_storage::{self, PendingComment}; +use crate::utils::comment_storage::{self, PendingComment}; /// 评论上下文,供评论相关组件共享状态。 /// diff --git a/src/hooks/mod.rs b/src/hooks/mod.rs index 3793359..8ef138f 100644 --- a/src/hooks/mod.rs +++ b/src/hooks/mod.rs @@ -1,12 +1,11 @@ //! 共享的 Dioxus Hooks 模块。 //! //! 该模块集中管理可在组件树中复用的自定义 Hook,包括: -//! - 评论草稿在浏览器 localStorage 中的持久化(WASM 端) //! - 骨架屏延迟加载状态 //! - 通用 DOM 事件监听(注册 + 自动卸载清理) - -/// 评论草稿持久化 Hook,基于浏览器的 localStorage(仅在 WASM 端有效)。 -pub mod comment_storage; +//! +//! 评论草稿持久化(localStorage 读写)已迁至 `crate::utils::comment_storage`, +//! 因为它是纯工具函数而非渲染期 Hook。 /// 延迟加载状态 Hook。 pub mod delayed_loading; diff --git a/src/hooks/comment_storage.rs b/src/utils/comment_storage.rs similarity index 100% rename from src/hooks/comment_storage.rs rename to src/utils/comment_storage.rs diff --git a/src/utils/html.rs b/src/utils/html.rs index b8765f3..cbca198 100644 --- a/src/utils/html.rs +++ b/src/utils/html.rs @@ -1,7 +1,7 @@ //! HTML 转义工具(零依赖纯函数,前端后端通用)。 //! //! 仓库内原先存在两份 `escape_html` 实现: -//! - `hooks::comment_storage::escape_html`(`'` → `'`) +//! - `utils::html::escape_html`(`'` → `'`) //! - `api::comments::helpers::escape_html`(`'` → `'`,server-only) //! 现统一到本模块,单引号采用 HTML5 标准的 `'`。 diff --git a/src/utils/mod.rs b/src/utils/mod.rs index e23dac1..3400079 100644 --- a/src/utils/mod.rs +++ b/src/utils/mod.rs @@ -1,9 +1,12 @@ //! 通用工具函数子模块。 //! +//! - `comment_storage`:评论草稿 localStorage 持久化(WASM 端)。 //! - `html`:HTML 转义(两端通用)。 //! - `text`:Markdown / 纯文本处理(仅 `server` feature)。 //! - `time`:跨平台时间/睡眠工具(WASM 与原生异步版本)。 +/// 评论草稿 localStorage 持久化(仅在 WASM 端实际读写)。 +pub mod comment_storage; /// HTML 转义工具(前端后端通用)。 pub mod html; /// Markdown / 纯文本处理工具。