|
|
@@ -82,33 +82,15 @@ export const ThemeProvider: React.FC<{ children: ReactNode }> = ({ children }) =
|
|
|
return localStorage.getItem('vista_custom_footer_logo') || null;
|
|
|
});
|
|
|
|
|
|
- const [heroImages, setHeroImages] = useState<string[]>(() => {
|
|
|
- const saved = localStorage.getItem('vista_hero_images');
|
|
|
- return saved ? JSON.parse(saved) : HERO_IMAGES;
|
|
|
- });
|
|
|
+ const [heroImages, setHeroImages] = useState<string[]>(HERO_IMAGES);
|
|
|
|
|
|
- // Fetch hero images from API when component mounts
|
|
|
+ // Fetch hero images from API on every page refresh
|
|
|
useEffect(() => {
|
|
|
- // Check if we already have hero images in localStorage to avoid unnecessary API calls
|
|
|
- const savedImages = localStorage.getItem('vista_hero_images');
|
|
|
- if (savedImages) {
|
|
|
- return; // Skip API call if we already have images saved
|
|
|
- }
|
|
|
-
|
|
|
const loadHeroImagesFromApi = async () => {
|
|
|
- // Add a flag to prevent duplicate API calls in React Strict Mode
|
|
|
- const apiCallFlag = 'vista_hero_images_api_called';
|
|
|
- if (sessionStorage.getItem(apiCallFlag)) {
|
|
|
- return; // Skip if we already made the call in this session
|
|
|
- }
|
|
|
-
|
|
|
try {
|
|
|
// Import the functions dynamically to avoid circular dependencies
|
|
|
const { fetchHotArticles, extractHeroImagesFromArticles } =
|
|
|
await import('../services/articleService.ts');
|
|
|
-
|
|
|
- // Mark that we're making the API call
|
|
|
- sessionStorage.setItem(apiCallFlag, 'true');
|
|
|
|
|
|
// Fetch hot articles from the API
|
|
|
const articlesData = await fetchHotArticles(1, 6);
|
|
|
@@ -119,20 +101,17 @@ export const ThemeProvider: React.FC<{ children: ReactNode }> = ({ children }) =
|
|
|
// If we got images from the API, use them
|
|
|
if (apiHeroImages.length > 0) {
|
|
|
setHeroImages(apiHeroImages);
|
|
|
- // Save to localStorage so we don't fetch on every page load
|
|
|
- localStorage.setItem('vista_hero_images', JSON.stringify(apiHeroImages));
|
|
|
}
|
|
|
- // Otherwise, keep the default HERO_IMAGES or saved images
|
|
|
+ // Otherwise, keep the default HERO_IMAGES
|
|
|
} catch (error) {
|
|
|
console.error('Failed to fetch hero images from API:', error);
|
|
|
- // Fallback to existing images if API fails
|
|
|
- // Clear the flag if the API call failed so we can try again
|
|
|
- sessionStorage.removeItem('vista_hero_images_api_called');
|
|
|
+ // Fallback to default HERO_IMAGES if API fails
|
|
|
+ setHeroImages(HERO_IMAGES);
|
|
|
}
|
|
|
};
|
|
|
|
|
|
loadHeroImagesFromApi();
|
|
|
- }, []); // Empty dependency array means this runs only once when component mounts
|
|
|
+ }, []); // Empty dependency array means this runs on every component mount (page refresh)
|
|
|
|
|
|
// --- Content Sections ---
|
|
|
const [itineraries, setItineraries] = useState<Itinerary[]>(() => {
|
|
|
@@ -171,9 +150,7 @@ export const ThemeProvider: React.FC<{ children: ReactNode }> = ({ children }) =
|
|
|
else localStorage.removeItem('vista_custom_footer_logo');
|
|
|
}, [customFooterLogo]);
|
|
|
|
|
|
- useEffect(() => {
|
|
|
- localStorage.setItem('vista_hero_images', JSON.stringify(heroImages));
|
|
|
- }, [heroImages]);
|
|
|
+
|
|
|
|
|
|
useEffect(() => {
|
|
|
localStorage.setItem('vista_itineraries', JSON.stringify(itineraries));
|