File size: 1,051 Bytes
f5071ca
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import React, { useEffect } from 'react'

import { useSelector, useDispatch } from 'react-redux'
import { fetchLatestVideos, selectLatestVideos } from 'store/reducers/slices/latestVideoSlice'
import BrowseContent from '../BrowseContent/BrowseContent'
import LoadingScreen from 'components/StaticPages/LoadingScreen/LoadingScreen'
import ErrorPage from 'components/StaticPages/ErrorPage/ErrorPage'

const LatestVideo = () => {
    const { latestVideos, status, error } = useSelector(selectLatestVideos)
    const dispatch = useDispatch()

    useEffect(() => {
        if (status === 'idle') {
            dispatch(fetchLatestVideos())
        }
    }, [dispatch, status])

    let browseContent
    if (status === 'success') {
        browseContent = <BrowseContent videoSections={latestVideos} />
    } else if (status === 'idle' || status === 'loading') {
        browseContent = <LoadingScreen />
    } else if (status === 'error') {
        browseContent = <ErrorPage errors={error} />
    }

    return browseContent
}

export default LatestVideo