Skip to content

Commit

Permalink
fix: bug
Browse files Browse the repository at this point in the history
  • Loading branch information
521xueweihan committed Nov 15, 2024
1 parent 83f1985 commit 1dc4ed5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/components/ImageWithPreview.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useState } from 'react';
import { useEffect, useState } from 'react';
import { AiOutlineClose } from 'react-icons/ai';

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

// 添加 useEffect 监听 src 变化
useEffect(() => {
setImgSrc(src?.endsWith('gif') ? `${src}${gifCoverImage}` : src);
}, [src]);

const handleLoadGif = (e: React.MouseEvent) => {
e.stopPropagation();
setTimeout(() => {
Expand Down Expand Up @@ -45,6 +50,7 @@ const ImageWithPreview = ({ src, alt, ...rest }: ImageWithPreviewProps) => {
<div className='relative flex'>
<img
{...rest}
key={src} // 添加 key 属性
src={imgSrc}
alt={alt}
style={{
Expand Down
1 change: 1 addition & 0 deletions src/components/respository/Info.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ const Info = ({ repo, t, i18n_lang }: RepositoryProps) => {
setIsCollected(res.is_collected);
}
};
setVoteTotal(repo.votes);
fetchUserRepoStatus();
}, [repo.rid]);

Expand Down

0 comments on commit 1dc4ed5

Please sign in to comment.