feat: 重构评论功能,支持删除和点赞,更新国际化文本,优化组件结构

This commit is contained in:
2025-09-09 20:11:31 +08:00
parent dd7641bf6e
commit ad9dfb0c4c
15 changed files with 504 additions and 85 deletions

View File

@ -0,0 +1,25 @@
import { useRef, useState } from "react";
export function useDoubleConfirm(timeout = 2000) {
const [confirming, setConfirming] = useState(false);
const timer = useRef<NodeJS.Timeout | null>(null);
const onClick = (callback: () => void) => {
if (confirming) {
setConfirming(false);
if (timer.current) clearTimeout(timer.current);
callback();
} else {
setConfirming(true);
timer.current = setTimeout(() => setConfirming(false), timeout);
}
};
// 可选:失焦时自动取消
const onBlur = () => {
setConfirming(false);
if (timer.current) clearTimeout(timer.current);
};
return { confirming, onClick, onBlur };
}

View File

@ -0,0 +1,27 @@
import { useRouter, usePathname } from "next/navigation"
/**
* 用于跳转到登录页并自动带上 redirect_back 参数
* 用法const toLogin = useToLogin(); <Button onClick={toLogin}>去登录</Button>
*/
export function useToLogin() {
const router = useRouter()
const pathname = usePathname()
return () => {
router.push(`/login?redirect_back=${encodeURIComponent(pathname)}`)
}
}
export function clickToUserprofile(username: string) {
const router = useRouter()
return () => {
router.push(`/user/${username}`)
}
}
export function clickToPost(postId: number) {
const router = useRouter()
return () => {
router.push(`/p/${postId}`)
}
}

View File

@ -1,13 +0,0 @@
import { useRouter, usePathname } from "next/navigation"
/**
* 用于跳转到登录页并自动带上 redirect_back 参数
* 用法const toLogin = useToLogin(); <Button onClick={toLogin}>去登录</Button>
*/
export function useToLogin() {
const router = useRouter()
const pathname = usePathname()
return () => {
router.push(`/login?redirect_back=${encodeURIComponent(pathname)}`)
}
}