clickToUserProfile(user.username) : clickToLogin} className="flex-shrink-0 w-10 h-10 fade-in">
+
clickToUserProfile(user.username) : clickToLogin} className="cursor-pointer flex-shrink-0 w-10 h-10 fade-in">
{user ? getGravatarByUser(user) : null}
{!user && }
diff --git a/web/src/components/comment/comment-item.tsx b/web/src/components/comment/comment-item.tsx
index c94019f..9daf81d 100644
--- a/web/src/components/comment/comment-item.tsx
+++ b/web/src/components/comment/comment-item.tsx
@@ -1,6 +1,6 @@
import { useToLogin, useToUserProfile } from "@/hooks/use-route";
import { User } from "@/models/user";
-import { useTranslations } from "next-intl";
+import { useLocale, useTranslations } from "next-intl";
import { useState } from "react";
import { toast } from "sonner";
import { getGravatarByUser } from "@/components/common/gravatar";
@@ -13,6 +13,7 @@ import { CommentInput } from "./comment-input";
import { createComment, deleteComment, listComments, updateComment } from "@/api/comment";
import { OrderBy } from "@/models/common";
import config from "@/config";
+import { formatDateTime } from "@/utils/common/datetime";
export function CommentItem(
@@ -32,8 +33,10 @@ export function CommentItem(
setActiveInputId: (input: { id: number; type: 'reply' | 'edit' } | null) => void,
}
) {
- const t = useTranslations("Comment")
- const commonT = useTranslations('Common')
+ const locale = useLocale();
+ console.log("locale", locale);
+ const t = useTranslations("Comment");
+ const commonT = useTranslations("Common");
const clickToUserProfile = useToUserProfile();
const clickToLogin = useToLogin();
const { confirming, onClick, onBlur } = useDoubleConfirm();
@@ -157,7 +160,27 @@ export function CommentItem(
{getGravatarByUser(comment.user)}
-
clickToUserProfile(comment.user.username)} className="font-bold text-base text-slate-800 dark:text-slate-100 cursor-pointer fade-in-up">{comment.user.nickname}
+
+
clickToUserProfile(comment.user.username)} className="font-bold text-base text-slate-800 dark:text-slate-100 cursor-pointer fade-in-up">
+ {comment.user.nickname}
+
+
{formatDateTime({
+ dateTimeString: comment.createdAt,
+ locale,
+ convertShortAgo: true,
+ unitI18n: { secondsAgo: commonT("secondsAgo"), minutesAgo: commonT("minutesAgo"), hoursAgo: commonT("hoursAgo"), daysAgo: commonT("daysAgo") }
+ })}
+ {comment.createdAt !== comment.updatedAt &&
+
{t("edit_at", {
+ time: formatDateTime({
+ dateTimeString: comment.updatedAt,
+ locale,
+ convertShortAgo: true,
+ unitI18n: { secondsAgo: commonT("secondsAgo"), minutesAgo: commonT("minutesAgo"), hoursAgo: commonT("hoursAgo"), daysAgo: commonT("daysAgo") }
+ })
+ })}}
+
+
{
isPrivate &&
@@ -169,7 +192,7 @@ export function CommentItem(
{comment.content}
- {new Date(comment.updatedAt).toLocaleString()}
+
{/* 点赞按钮 */}