import React, { useState, useEffect } from 'react'; import { useTranslation } from 'react-i18next'; import { getAllVideos, isLoggedIn } from '../../utils/api'; import { VideoListItem } from '../../types/api'; import LoginPromptModal from '../../components/LoginPromptModal'; import VideoDetailModal from '../../components/VideoDetailModal'; import CitySelectModal from '../../components/CitySelectModal'; interface ADO2ContentsPageProps { onBack?: () => void; } const ADO2ContentsPage: React.FC = () => { const { t } = useTranslation(); const authed = isLoggedIn(); const [selectedVideoId, setSelectedVideoId] = useState(null); const [videos, setVideos] = useState([]); const [total, setTotal] = useState(0); const [loading, setLoading] = useState(authed); const [error, setError] = useState(null); const [page, setPage] = useState(1); const [hasNext, setHasNext] = useState(false); const [hasPrev, setHasPrev] = useState(false); const [totalPages, setTotalPages] = useState(1); const pageSize = 20; const [sortBy, setSortBy] = useState<'created_at' | 'like_count' | 'comment_count'>('created_at'); const [order, setOrder] = useState<'desc' | 'asc'>('desc'); const [searchInput, setSearchInput] = useState(''); const [storeName, setStoreName] = useState(''); const [region, setRegion] = useState(''); const [showCityModal, setShowCityModal] = useState(false); useEffect(() => { if (!authed) return; fetchVideos(); }, [page, sortBy, order, storeName, region]); const fetchVideos = async () => { setLoading(true); setError(null); try { const response = await getAllVideos(page, pageSize, sortBy, storeName, order, region); setVideos(response.items); setTotal(response.total); setTotalPages(response.total_pages); setHasNext(response.has_next); setHasPrev(response.has_prev); } catch (err) { console.error('Failed to fetch all videos:', err); setError(t('ado2Contents.loadFailed')); } finally { setLoading(false); } }; const handleCardClick = (videoId: number) => { setSelectedVideoId(videoId); }; const formatDate = (dateString: string) => { const date = new Date(dateString); const year = date.getFullYear(); const month = String(date.getMonth() + 1).padStart(2, '0'); const day = String(date.getDate()).padStart(2, '0'); return `${year}.${month}.${day}`; }; return (

{t('sidebar.ado2Contents')}

{t('ado2Contents.totalCount', { count: total })}
{ e.preventDefault(); setStoreName(searchInput); setPage(1); }} > setSearchInput(e.target.value)} placeholder={t('ado2Contents.searchPlaceholder')} />
{loading ? (

{t('ado2Contents.loading')}

) : error ? (

{error}

) : videos.length === 0 ? (

{t('ado2Contents.noContent')}

) : ( <>
{videos.map((video) => (
handleCardClick(video.video_id)} role="button" tabIndex={0} onKeyDown={(e) => e.key === 'Enter' && handleCardClick(video.video_id)} >
{video.thumbnail_url ? ( {video.store_name} ) : video.result_movie_url ? (
))}
{page} / {totalPages}
)} {!authed && ( { window.location.href = '/'; }} /> )} {selectedVideoId !== null && ( setSelectedVideoId(null)} /> )} {showCityModal && ( { setRegion(city); setPage(1); }} onClose={() => setShowCityModal(false)} /> )}
); }; export default ADO2ContentsPage;