增加评论开关,尝试修复循环依赖
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -50,6 +50,9 @@ interface SidebarProps {
|
||||
declare global {
|
||||
interface Window {
|
||||
__sidebarCollapsed?: boolean;
|
||||
RUNTIME_CONFIG?: {
|
||||
EnableComments: boolean;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user