MovieTable.js 3.16 KB
Newer Older
1
2
3
import { useState } from "react";
import movieApi from "../../apis/movie.api.js";
import catchErrors from "../../utils/catchErrors.js";
Kim, Subin's avatar
Kim, Subin committed
4
5
import styles from "./movie-table.module.scss";

6
7
8
9
10
11
12
13
14
15
const MovieTable = ({ movieList }) => {
    const [error, setError] = useState("")

    async function handleClick(e, movieId) {
        e.preventDefault();
        try {
            setError("");
            await movieApi.submit(movieId)
            alert("서버 등록이 완료되었습니다.")
        } catch (error) {
Kim, Subin's avatar
Kim, Subin committed
16
            catchErrors(error, setError)
17
18
19
        }
    }

Kim, Subin's avatar
Kim, Subin committed
20
21
22
23
24
25
    return (
        <table className={`table text-center ${styles.tableForm}`}>
            <thead className={`table-dark ${styles.dNone}`}>
                <tr>
                    <th>제목</th>
                    <th>감독</th>
26
                    <th>상영일</th>
Kim, Subin's avatar
Kim, Subin committed
27
28
29
30
31
32
33
                    <th>줄거리</th>
                    <th>포스터</th>
                    <th>스틸컷</th>
                    <th>예고편</th>
                </tr>
            </thead>
            <tbody>
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
                {movieList?.map(movie =>
                    <>
                        <tr className={styles.Row} data-bs-toggle="collapse" data-bs-target={"#movie" + movie.id}>
                            <td className="d-inline-block d-md-table-cell">{movie.title}</td>
                            <td data-label="- " className={`d-inline-block d-md-table-cell ${styles.data}`}>케이트 쇼트랜드</td>
                            <td data-label="/ " className={`d-inline-block d-md-table-cell ${styles.data}`}>{movie.release_date}</td>
                            <td className="d-none d-md-table-cell">{movie.overview !== '' ? 'O' : 'X'}</td>
                            <td className="d-none d-md-table-cell">{movie.poster_path !== '' ? 'O' : 'X'}</td>
                            <td className="d-none d-md-table-cell">{movie.backdrop_path !== '' ? 'O' : 'X'}</td>
                            <td className="d-none d-md-table-cell">{movie.video !== false ? 'O' : 'X'}</td>
                        </tr>
                        <tr className={styles.Row}>
                            <td colSpan="7" className="collapse" id={"movie" + movie.id}>
                                <div className={`d-inline-block d-md-none ${styles.word} mb-2`}>
                                    줄거리 - {movie.overview !== '' ? 'O' : 'X'} /
                                    포스터 - {movie.poster_path !== '' ? 'O' : 'X'} /
                                    스틸컷 - {movie.backdrop_path !== '' ? 'O' : 'X'} /
                                    예고편 - {movie.video !== false ? 'O' : 'X'}
                                </div>
                                <div className="d-flex justify-content-end">
                                    <button type="button" className="btn btn-primary" onClick={(e) => handleClick(e, movie.id)}>등록</button>
                                    {/* <button type="button" className="btn btn-danger">삭제</button> */}
                                </div>
                            </td>
                        </tr>
                    </>)}
Kim, Subin's avatar
Kim, Subin committed
60
61
62
63
64
65
            </tbody>
        </table>
    )
}

export default MovieTable