MovieEdit.js 1.34 KB
Newer Older
1
import { useState, useEffect } from "react";
Kim, Subin's avatar
Kim, Subin committed
2
import Search from "../Search";
Kim, Subin's avatar
Kim, Subin committed
3
4
import MovieTable from "../MovieTable";
import Pagination from "../Pagination";
5
6
import movieApi from "../../apis/movie.api.js";
import catchErrors from "../../utils/catchErrors.js";
Kim, Subin's avatar
Kim, Subin committed
7
8

const MovieEdit = () => {
9
    const [search, setSearch] = useState({ type: "admin", keyword: "" })
10
11
12
13
14
15
16
17
18
    const [movieList, setMovieList] = useState([])
    const [error, setError] = useState("")

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

    async function getMovieList() {
        try {
Kim, Subin's avatar
수빈    
Kim, Subin committed
19
            setError("")
Kim, Subin's avatar
Kim, Subin committed
20
            const getMovieList = await movieApi.getAllfromTM()
21
22
23
24
25
26
            setMovieList(getMovieList)
        } catch (error) {
            catchErrors(error, setError)
        }
    }

Kim, Subin's avatar
수빈    
Kim, Subin committed
27
28
29
    async function searchMovie() {
        try {
            setError("")
30
31
            const findMovie = await movieApi.search(search)
            setMovieList(findMovie)
Kim, Subin's avatar
수빈    
Kim, Subin committed
32
33
34
35
36
        } catch (error) {
            catchErrors(error, setError)
        }
    }

Kim, Subin's avatar
Kim, Subin committed
37
    return (
Kim, Subin's avatar
Kim, Subin committed
38
        <>
Kim, Subin's avatar
수빈    
Kim, Subin committed
39
            <div className="d-flex justify-content-md-end justify-content-center mb-3">
40
                <Search search={search} setSearch={setSearch} handleClick={searchMovie} />
Kim, Subin's avatar
Kim, Subin committed
41
            </div>
42
            <MovieTable movieList={movieList} />
43
            <Pagination />
Kim, Subin's avatar
Kim, Subin committed
44
        </>
Kim, Subin's avatar
Kim, Subin committed
45
46
47
    )
}
export default MovieEdit