From 84e49740f312f1ef508d0b69998e6f6912b8c482 Mon Sep 17 00:00:00 2001 From: Therainclouds <245141853@qq.com> Date: Fri, 13 Feb 2026 23:59:02 +0800 Subject: [PATCH] new --- .../src/components/activity/ActivityCard.jsx | 37 +++++++++++++------ .../src/components/activity/ActivityList.jsx | 19 ++++++---- .../components/activity/activity.module.less | 1 + 3 files changed, 38 insertions(+), 19 deletions(-) diff --git a/frontend/src/components/activity/ActivityCard.jsx b/frontend/src/components/activity/ActivityCard.jsx index adbd87a..8d9bb15 100644 --- a/frontend/src/components/activity/ActivityCard.jsx +++ b/frontend/src/components/activity/ActivityCard.jsx @@ -1,16 +1,16 @@ -import React, { useState } from 'react'; +import React, { useState, useRef, useLayoutEffect } from 'react'; import { motion } from 'framer-motion'; import { CalendarOutlined } from '@ant-design/icons'; import { useNavigate } from 'react-router-dom'; import styles from './activity.module.less'; import { hoverScale } from '../../animation'; -// const ActivityCard = ({ activity }) => { const navigate = useNavigate(); const [isLoaded, setIsLoaded] = useState(false); const [hasError, setHasError] = useState(false); + const imgRef = useRef(null); const handleCardClick = () => { navigate(`/activity/${activity.id}`); @@ -33,6 +33,13 @@ const ActivityCard = ({ activity }) => { ? 'https://via.placeholder.com/600x400?text=No+Image' : (activity.display_banner_url || activity.banner_url || activity.cover_image || 'https://via.placeholder.com/600x400'); + // Check if image is already loaded (cached) to prevent flashing + useLayoutEffect(() => { + if (imgRef.current && imgRef.current.complete) { + setIsLoaded(true); + } + }, [imgSrc]); + return ( { style={{ willChange: 'transform' }} >
- {/* Placeholder / Skeleton Background */} + {/* Placeholder Background - Always visible behind the image */}
{ left: 0, width: '100%', height: '100%', - backgroundColor: '#f0f0f0', - opacity: isLoaded ? 0 : 1, - transition: 'opacity 0.5s ease' + backgroundColor: '#f5f5f5', + zIndex: 0, }} /> - setIsLoaded(true)} onError={() => { setHasError(true); - setIsLoaded(true); // Show placeholder image + setIsLoaded(true); }} loading="lazy" /> -
+
{activity.status || getStatus(activity.start_time)}
diff --git a/frontend/src/components/activity/ActivityList.jsx b/frontend/src/components/activity/ActivityList.jsx index 2e33b6e..3badb43 100644 --- a/frontend/src/components/activity/ActivityList.jsx +++ b/frontend/src/components/activity/ActivityList.jsx @@ -66,20 +66,25 @@ const ActivityList = () => { User said: "Activity only shows one, and in the form of a sliding page" */}
- + -
+
{activities.map((_, idx) => (