diff --git a/frontend/src/pages/VODs.jsx b/frontend/src/pages/VODs.jsx index fc03447f..3fdc6b26 100644 --- a/frontend/src/pages/VODs.jsx +++ b/frontend/src/pages/VODs.jsx @@ -274,6 +274,29 @@ const SeriesModal = ({ series, opened, onClose }) => { ); }; +const MIN_CARD_WIDTH = 260; +const MAX_CARD_WIDTH = 320; + +const useCardColumns = () => { + const [columns, setColumns] = useState(4); + + useEffect(() => { + const calcColumns = () => { + const container = document.getElementById('vods-container'); + const width = container ? container.offsetWidth : window.innerWidth; + let colCount = Math.floor(width / MIN_CARD_WIDTH); + if (colCount < 1) colCount = 1; + if (colCount > 6) colCount = 6; + setColumns(colCount); + }; + calcColumns(); + window.addEventListener('resize', calcColumns); + return () => window.removeEventListener('resize', calcColumns); + }, []); + + return columns; +}; + const VODsPage = () => { const { vods, @@ -294,6 +317,7 @@ const VODsPage = () => { const showVideo = useVideoStore((s) => s.showVideo); const [selectedSeries, setSelectedSeries] = useState(null); const [seriesModalOpened, { open: openSeriesModal, close: closeSeriesModal }] = useDisclosure(false); + const columns = useCardColumns(); useEffect(() => { fetchCategories(); @@ -307,10 +331,6 @@ const VODsPage = () => { } }, [filters, currentPage, fetchVODs, fetchSeries]); - - - - const env_mode = useSettingsStore((s) => s.environment.env_mode); const handlePlayVOD = (vod) => { let streamUrl = vod.stream_url; @@ -338,7 +358,7 @@ const VODsPage = () => { const totalPages = Math.ceil(totalCount / pageSize); return ( - + Video on Demand @@ -382,9 +402,13 @@ const VODsPage = () => { ) : ( <> {filters.type === 'series' ? ( - + {Object.values(series).map(seriesItem => ( - + { ))} ) : ( - + {Object.values(vods).map(vod => ( - + ))}