feat: 热门关键词取去掉loading态

This commit is contained in:
zdl
2025-10-27 00:11:46 +08:00
parent b06d51813a
commit 794581e429

View File

@@ -1,6 +1,6 @@
// src/views/Community/components/PopularKeywords.js // src/views/Community/components/PopularKeywords.js
import React, { useState, useEffect } from 'react'; import React, { useState, useEffect } from 'react';
import { Tag, Space, Spin, Button } from 'antd'; import { Tag, Space, Button } from 'antd';
import { useNavigate } from 'react-router-dom'; import { useNavigate } from 'react-router-dom';
import { RightOutlined } from '@ant-design/icons'; import { RightOutlined } from '@ant-design/icons';
import { logger } from '../../../utils/logger'; import { logger } from '../../../utils/logger';
@@ -15,12 +15,10 @@ const DOMAIN_PREFIX = process.env.NODE_ENV === 'production'
const PopularKeywords = ({ onKeywordClick, keywords: propKeywords }) => { const PopularKeywords = ({ onKeywordClick, keywords: propKeywords }) => {
const [keywords, setKeywords] = useState([]); const [keywords, setKeywords] = useState([]);
const [loading, setLoading] = useState(false);
const navigate = useNavigate(); const navigate = useNavigate();
// 加载热门概念涨幅前20 // 加载热门概念涨幅前20
const loadPopularConcepts = async () => { const loadPopularConcepts = async () => {
setLoading(true);
try { try {
const response = await fetch(`${API_BASE_URL}/search`, { const response = await fetch(`${API_BASE_URL}/search`, {
method: 'POST', method: 'POST',
@@ -53,8 +51,6 @@ const PopularKeywords = ({ onKeywordClick, keywords: propKeywords }) => {
} catch (error) { } catch (error) {
logger.error('PopularKeywords', 'loadPopularConcepts', error); logger.error('PopularKeywords', 'loadPopularConcepts', error);
setKeywords([]); setKeywords([]);
} finally {
setLoading(false);
} }
}; };
@@ -118,7 +114,7 @@ const PopularKeywords = ({ onKeywordClick, keywords: propKeywords }) => {
}; };
return ( return (
<Spin spinning={loading}> <>
{keywords && keywords.length > 0 && ( {keywords && keywords.length > 0 && (
<div style={{ position: 'relative' }}> <div style={{ position: 'relative' }}>
<Space <Space
@@ -199,7 +195,7 @@ const PopularKeywords = ({ onKeywordClick, keywords: propKeywords }) => {
</Button> </Button>
</div> </div>
)} )}
</Spin> </>
); );
}; };