Skip to content

Commit 1dc4ed5

Browse files
committed
fix: bug
1 parent 83f1985 commit 1dc4ed5

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

src/components/ImageWithPreview.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useState } from 'react';
1+
import { useEffect, useState } from 'react';
22
import { AiOutlineClose } from 'react-icons/ai';
33

44
import GifPlayButton from './loading/GifPlayButton';
@@ -18,6 +18,11 @@ const ImageWithPreview = ({ src, alt, ...rest }: ImageWithPreviewProps) => {
1818
const sourceIsGif = src?.endsWith('gif');
1919
const [isPreviewOpen, setIsPreviewOpen] = useState(false);
2020

21+
// 添加 useEffect 监听 src 变化
22+
useEffect(() => {
23+
setImgSrc(src?.endsWith('gif') ? `${src}${gifCoverImage}` : src);
24+
}, [src]);
25+
2126
const handleLoadGif = (e: React.MouseEvent) => {
2227
e.stopPropagation();
2328
setTimeout(() => {
@@ -45,6 +50,7 @@ const ImageWithPreview = ({ src, alt, ...rest }: ImageWithPreviewProps) => {
4550
<div className='relative flex'>
4651
<img
4752
{...rest}
53+
key={src} // 添加 key 属性
4854
src={imgSrc}
4955
alt={alt}
5056
style={{

src/components/respository/Info.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ const Info = ({ repo, t, i18n_lang }: RepositoryProps) => {
114114
setIsCollected(res.is_collected);
115115
}
116116
};
117+
setVoteTotal(repo.votes);
117118
fetchUserRepoStatus();
118119
}, [repo.rid]);
119120

0 commit comments

Comments
 (0)