增加评论开关,尝试修复循环依赖

This commit is contained in:
mtvpls
2025-12-03 18:20:34 +08:00
parent 567ee54c67
commit 4e05c7bcaa
11 changed files with 416 additions and 194 deletions
+13
View File
@@ -1,6 +1,7 @@
'use client';
import { useEffect, useState, useCallback } from 'react';
import { useEnableComments } from '@/hooks/useEnableComments';
interface DoubanComment {
id: string;
@@ -17,6 +18,11 @@ interface DoubanCommentsProps {
doubanId: number;
}
// 获取运行时配置的类型
interface RuntimeConfig {
EnableComments: boolean;
}
export default function DoubanComments({ doubanId }: DoubanCommentsProps) {
const [comments, setComments] = useState<DoubanComment[]>([]);
const [loading, setLoading] = useState(false);
@@ -26,6 +32,13 @@ export default function DoubanComments({ doubanId }: DoubanCommentsProps) {
const [hasStartedLoading, setHasStartedLoading] = useState(false);
const limit = 20;
const enableComments = useEnableComments();
// 如果评论功能被禁用,不显示任何内容
if (!enableComments) {
return null;
}
const fetchComments = useCallback(async (startIndex: number) => {
try {
console.log('正在获取评论,起始位置:', startIndex);
+3
View File
@@ -50,6 +50,9 @@ interface SidebarProps {
declare global {
interface Window {
__sidebarCollapsed?: boolean;
RUNTIME_CONFIG?: {
EnableComments: boolean;
};
}
}