Refactor comment components and update OIDC configuration

- Updated OIDC configuration to include additional fields in the UpdateOidcConfig method.
- Enhanced CommentService to include IsPrivate field in the comment DTO.
- Refactored comment components: renamed neo-comment to comment, and moved related files.
- Implemented new CommentInput and CommentItem components for better structure and readability.
- Removed obsolete files related to the old comment system.
- Added CSS animations for comment components to improve user experience.
This commit is contained in:
2025-09-09 22:37:27 +08:00
parent 5fb6cd63dd
commit cb3f602663
13 changed files with 190 additions and 179 deletions

View File

@ -13,6 +13,7 @@ type CommentDto struct {
ReplyCount int64 `json:"reply_count"` // 回复数量
LikeCount uint64 `json:"like_count"` // 点赞数量
IsLiked bool `json:"is_liked"` // 当前用户是否点赞
IsPrivate bool `json:"is_private"`
}
type CreateCommentReq struct {

View File

@ -2,11 +2,12 @@ package model
import (
"fmt"
"time"
"github.com/sirupsen/logrus"
"github.com/snowykami/neo-blog/internal/dto"
"gorm.io/gorm"
"resty.dev/v3"
"time"
)
type OidcConfig struct {
@ -16,7 +17,7 @@ type OidcConfig struct {
ClientSecret string // 客户端密钥
DisplayName string // 显示名称,例如:轻雪通行证
Icon string // 图标url为空则使用内置默认图标
OidcDiscoveryUrl string // OpenID自动发现URL例如 https://pass.liteyuki.icu/.well-known/openid-configuration
OidcDiscoveryUrl string // OpenID自动发现URL例如 https://pass.liteyuki.org/.well-known/openid-configuration
Enabled bool `gorm:"default:true"` // 是否启用
Type string `gorm:"oauth2"` // OIDC类型默认为oauth2,也可以为misskey
// 以下字段为自动获取字段,每次更新配置时自动填充

View File

@ -110,7 +110,7 @@ func (cr *CommentRepo) UpdateComment(comment *model.Comment) error {
return errs.New(http.StatusBadRequest, "invalid comment ID", nil)
}
if err := GetDB().Updates(comment).Error; err != nil {
if err := GetDB().Select("IsPrivate", "Content").Updates(comment).Error; err != nil {
return err
}
@ -204,6 +204,7 @@ func (cr *CommentRepo) ListComments(currentUserID, targetID, commentID uint, tar
} else {
query = query.Where("target_id = ? AND target_type = ?", targetID, targetType)
}
items, _, err := PaginateQuery[model.Comment](query, page, size, orderBy, desc)
if err != nil {

View File

@ -3,6 +3,9 @@ package repo
import (
"errors"
"fmt"
"os"
"path/filepath"
"github.com/glebarez/sqlite"
"github.com/sirupsen/logrus"
"github.com/snowykami/neo-blog/internal/model"
@ -10,8 +13,6 @@ import (
"gorm.io/driver/postgres"
"gorm.io/gorm"
"gorm.io/gorm/logger"
"os"
"path/filepath"
)
var db *gorm.DB

View File

@ -1,9 +1,10 @@
package repo
import (
"net/http"
"github.com/snowykami/neo-blog/internal/model"
"github.com/snowykami/neo-blog/pkg/errs"
"net/http"
)
type oidcRepo struct {
@ -62,7 +63,9 @@ func (o *oidcRepo) UpdateOidcConfig(oidcConfig *model.OidcConfig) error {
if oidcConfig.ID == 0 {
return errs.New(http.StatusBadRequest, "invalid OIDC config ID", nil)
}
if err := GetDB().Select("Enabled").Updates(oidcConfig).Error; err != nil {
if err := GetDB().Select("Name", "ClientID", "ClientSecret",
"DisplayName", "Icon", "OidcDiscoveryUrl",
"Enabled", "Type").Updates(oidcConfig).Error; err != nil {
return err
}
return nil

View File

@ -157,6 +157,7 @@ func (cs *CommentService) GetCommentList(ctx context.Context, req *dto.GetCommen
ReplyCount: replyCount,
LikeCount: comment.LikeCount,
IsLiked: isLiked,
IsPrivate: comment.IsPrivate,
}
commentDtos = append(commentDtos, commentDto)
}

View File

@ -4,7 +4,7 @@ import { Calendar, Clock, FileText, Flame, Heart, MessageCircle, PenLine, Square
import { RenderMarkdown } from "@/components/common/markdown";
import { isMobileByUA } from "@/utils/server/device";
import { calculateReadingTime } from "@/utils/common/post";
import {CommentSection} from "@/components/neo-comment";
import {CommentSection} from "@/components/comment";
import { TargetType } from '../../models/types';
function PostMeta({ post }: { post: Post }) {

View File

@ -10,6 +10,7 @@ import { Textarea } from "@/components/ui/textarea";
import { Checkbox } from "@/components/ui/checkbox"
import { Label } from "@/components/ui/label";
export function CommentInput(
{
user,
@ -54,7 +55,7 @@ export function CommentInput(
</div>
<div className="flex-1 pl-2 fade-in-up">
<Textarea
placeholder={t("placeholder")}
placeholder={user?t("placeholder"):t("login_required")}
className="w-full p-2 border border-gray-300 rounded-md fade-in-up"
value={commentContent}
onChange={(e) => setCommentContent(e.target.value)}

View File

@ -14,6 +14,7 @@ import { createComment, deleteComment, listComments, updateComment } from "@/api
import { OrderBy } from "@/models/common";
import config from "@/config";
export function CommentItem(
{
user,
@ -33,6 +34,7 @@ export function CommentItem(
const [likeCount, setLikeCount] = useState(comment.likeCount);
const [liked, setLiked] = useState(comment.isLiked);
const [isPrivate, setIsPrivate] = useState(comment.isPrivate);
const [replyCount, setReplyCount] = useState(comment.replyCount);
const [showReplies, setShowReplies] = useState(false);
const [showReplyInput, setShowReplyInput] = useState(false);
@ -81,7 +83,7 @@ export function CommentItem(
updateComment({ id: comment.id, content: newContent, isPrivate }).then(() => {
toast.success(t("edit_success"));
comment.content = newContent;
comment.isPrivate = isPrivate;
setIsPrivate(isPrivate);
setShowEditInput(false);
}).catch(error => {
toast.error(t("edit_failed") + ": " + error.message);
@ -127,7 +129,7 @@ export function CommentItem(
<div className="font-bold text-base text-slate-800 dark:text-slate-100 fade-in-up">{comment.user.nickname}</div>
<p className="text-lg text-slate-600 dark:text-slate-400 fade-in">
{
comment.isPrivate && <Lock className="inline w-4 h-4 mr-1 mb-1 text-slate-500 dark:text-slate-400" />
isPrivate && <Lock className="inline w-4 h-4 mr-1 mb-1 text-slate-500 dark:text-slate-400" />
}
{
parentComment &&
@ -201,7 +203,7 @@ export function CommentItem(
{showEditInput && !showReplyInput && <CommentInput
user={user}
initContent={comment.content}
initIsPrivate={comment.isPrivate}
initIsPrivate={isPrivate}
onCommentSubmitted={onCommentEdit}
isUpdate={true}
/>}

View File

@ -11,12 +11,12 @@ import { OrderBy } from "@/models/common";
import { Separator } from "@/components/ui/separator";
import { getLoginUser } from "@/api/user";
import { Skeleton } from "@/components/ui/skeleton";
import "./style.css";
import { CommentInput } from "./comment-input";
import { CommentItem } from "./comment-item";
import config from "@/config";
import "./style.css";
export function CommentSection(