Rev 7265 | Ir a la última revisión | Autoría | Comparar con el anterior | Ultima modificación | Ver Log |
import React, { useEffect } from 'react'import { useDispatch, useSelector } from 'react-redux'import { fetchFeeds, setCurrentPage } from '../../../redux/feed/feed.actions'import Feed from './Feed'import Spinner from '../../UI/Spinner'import EmptySection from '../../UI/EmptySection'import ShareModal from '../../share-modal/ShareModal'const PaginationComponent = React.lazy(() =>import('../../UI/PaginationComponent'))const FeedList = ({ feed, image }) => {const { allFeeds, timelineUrl, pages, currentPage, loading } = useSelector(({ feed }) => feed)const dispatch = useDispatch()const fetchSpecificFeed = (currentFeed) => {dispatch(fetchFeeds(timelineUrl + '/feed/' + currentFeed, 1))}const onChangePageHandler = (currentPage) => {dispatch(setCurrentPage(currentPage))dispatch(fetchFeeds(timelineUrl, currentPage))window.scrollTo(0, 0)}useEffect(() => {if (feed) fetchSpecificFeed()}, [feed])useEffect(() => {if (!allFeeds.length && !feed && currentPage !== 1)dispatch(fetchFeeds(timelineUrl, currentPage))}, [allFeeds])useEffect(() => {dispatch(setCurrentPage(1))}, [])if (loading) {return <Spinner />}if (!allFeeds.length) {return <EmptySection message="No hay publicaciones" />}return (<>{allFeeds.map((feed) => {return <Feed key={feed.feed_uuid} image={image} {...feed} />})}<React.Suspense fallback={null}><PaginationComponentonChangePage={onChangePageHandler}pages={pages}isRowcurrentActivePage={currentPage}/><ShareModal timelineUrl={timelineUrl} currentPage={currentPage} /></React.Suspense></>)}export default FeedList