|
|
@@ -113,6 +113,35 @@ export const ThemeProvider: React.FC<{ children: ReactNode }> = ({ children }) =
|
|
|
loadHeroImagesFromApi();
|
|
|
}, []); // Empty dependency array means this runs on every component mount (page refresh)
|
|
|
|
|
|
+ // Fetch video content from API on every page refresh
|
|
|
+ useEffect(() => {
|
|
|
+ const loadVideoContentFromApi = async () => {
|
|
|
+ try {
|
|
|
+ // Import the functions dynamically to avoid circular dependencies
|
|
|
+ const { fetchVideoContent, extractVideoContentFromArticles } =
|
|
|
+ await import('../services/articleService.ts');
|
|
|
+
|
|
|
+ // Fetch video content from the API (lang=1 for Chinese)
|
|
|
+ const videoData = await fetchVideoContent(1);
|
|
|
+
|
|
|
+ // Extract video content from the articles data
|
|
|
+ const videoContent = extractVideoContentFromArticles(videoData);
|
|
|
+
|
|
|
+ // If we got video content from the API, use it
|
|
|
+ if (videoContent) {
|
|
|
+ setVideoSection(videoContent);
|
|
|
+ }
|
|
|
+ // Otherwise, keep the default video content
|
|
|
+ } catch (error) {
|
|
|
+ console.error('Failed to fetch video content from API:', error);
|
|
|
+ // Fallback to default video content if API fails
|
|
|
+ setVideoSection(DEFAULT_VIDEO);
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ loadVideoContentFromApi();
|
|
|
+ }, []); // Empty dependency array means this runs on every component mount (page refresh)
|
|
|
+
|
|
|
// --- Content Sections ---
|
|
|
const [itineraries, setItineraries] = useState<Itinerary[]>(() => {
|
|
|
const saved = localStorage.getItem('vista_itineraries');
|
|
|
@@ -129,10 +158,7 @@ export const ThemeProvider: React.FC<{ children: ReactNode }> = ({ children }) =
|
|
|
return saved ? JSON.parse(saved) : DEFAULT_DINING;
|
|
|
});
|
|
|
|
|
|
- const [videoSection, setVideoSection] = useState<VideoSectionContent>(() => {
|
|
|
- const saved = localStorage.getItem('vista_video');
|
|
|
- return saved ? JSON.parse(saved) : DEFAULT_VIDEO;
|
|
|
- });
|
|
|
+ const [videoSection, setVideoSection] = useState<VideoSectionContent>(DEFAULT_VIDEO);
|
|
|
|
|
|
const [shipsPageImages, setShipsPageImages] = useState<ShipsPageImages>(() => {
|
|
|
const saved = localStorage.getItem('vista_ships_page_images');
|
|
|
@@ -164,9 +190,7 @@ export const ThemeProvider: React.FC<{ children: ReactNode }> = ({ children }) =
|
|
|
localStorage.setItem('vista_dining', JSON.stringify(dining));
|
|
|
}, [dining]);
|
|
|
|
|
|
- useEffect(() => {
|
|
|
- localStorage.setItem('vista_video', JSON.stringify(videoSection));
|
|
|
- }, [videoSection]);
|
|
|
+
|
|
|
|
|
|
useEffect(() => {
|
|
|
localStorage.setItem('vista_ships_page_images', JSON.stringify(shipsPageImages));
|