HomePage.js 1.13 KB
Newer Older
1
import { useState, useEffect } from "react"
2
import BoxOffice from "../components/BoxOffice";
Kim, Subin's avatar
Kim, Subin committed
3
import Collection from "../components/Collection";
4
import Footer from "../components/Footer";
5
6
import movieApi from '../apis/movie.api'
import catchErrors from '../utils/catchErrors.js'
7
8

const HomePage = () => {
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
    const [TMDB_TopRated_Data, setTMDB_TopRated_Data] = useState([])
    const [error, setError] = useState("")
    const category = "popular"

    useEffect(() => {
        getTMDB_TopRated()
    }, [])

    async function getTMDB_TopRated() {
        try {
            setError("")
            const data = await movieApi.getListByCategoryfromDB(category)
            console.log("sdad==", data)
            data.sort(function (a, b) {
                return b.popularity - a.popularity
            })
            setTMDB_TopRated_Data([...data])
        } catch (error) {
            catchErrors(error, setError)
        }
    }
30
    return (
Jiwon Yoon's avatar
Jiwon Yoon committed
31
        <>
32
33
            <BoxOffice TMDB_TopRated_Data={TMDB_TopRated_Data}  />
            <Collection  TMDB_TopRated_Data={TMDB_TopRated_Data} />
34
            <Footer />
Jiwon Yoon's avatar
Jiwon Yoon committed
35
        </>
36
37
38
39
    )
}

export default HomePage