Home.js 3.89 KB
Newer Older
Kim, Subin's avatar
Kim, Subin committed
1
import React, { useState, useEffect, useRef } from 'react';
kusang96's avatar
kusang96 committed
2
import { Link } from 'react-router-dom';
3
4
5
import ListCard from '../Components/ListCard';
import axios from 'axios';
import catchError from '../utils/catchErrors';
kusang96's avatar
kusang96 committed
6
import { Container, Row } from 'react-bootstrap';
7

Kim, Subin's avatar
Kim, Subin committed
8
9

function Home() {
kusang96's avatar
kusang96 committed
10
11
12
13
14
    const INIT_PRODUCT = {
        bestProduct: [],
        newProduct: [],
    }
    const [productlist, setProductlist] = useState(INIT_PRODUCT)
15
    const [error, setError] = useState('')
kusang96's avatar
kusang96 committed
16

17
18
19
20
21
22
23
    useEffect(() => {
        getProductlist()
    }, [])

    async function getProductlist() {
        try {
            const response = await axios.get(`/api/product/getproduct`)
kusang96's avatar
kusang96 committed
24
            setProductlist({ bestProduct: response.data.bestProduct, newProduct: response.data.newProduct })
25
26
27
28
        } catch (error) {
            catchError(error, setError)
        }
    }
kusang96's avatar
kusang96 committed
29

Kim, Subin's avatar
Kim, Subin committed
30
    return (
kusang96's avatar
kusang96 committed
31
32
33
        <Container>
            <style type="text/css">
                {`
박상호's avatar
css    
박상호 committed
34
35
36
37
38
39
40
41
                @font-face {
                    font-family: 'Jal_Onuel';
                    src: url('https://cdn.jsdelivr.net/gh/projectnoonnu/noonfonts_20-10-21@1.0/Jal_Onuel.woff') format('woff');
                    font-weight: normal;
                    font-style: normal;
                }
                body{font-family:'Jal_Onuel'}
                
kusang96's avatar
kusang96 committed
42
43
44
                a, a:hover, a:active {
                    color: #000;
                    text-decoration: none;
박상호's avatar
css    
박상호 committed
45
46
47
                }
                
                
kusang96's avatar
kusang96 committed
48
49
                `}
            </style>
박상호's avatar
css    
박상호 committed
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
                <div className="my-4">
                    <h2 style={{ marginRight: "5rem", marginLeft: "3rem", marginBottom: "2rem" }}><u>Best</u></h2>
                    <Row className="justify-content-center mx-0">
                        {productlist.bestProduct.map(pro => (
                            <Link to={{
                                pathname: `/product/${pro._id}`,
                                state: {
                                    id: pro._id,
                                    name: pro.pro_name,
                                    price: pro.price,
                                    colors: pro.colors,
                                    sizes: pro.sizes,
                                    description: pro.description,
                                    main_img: pro.main_imgUrl,
                                    detail_imgs: pro.detail_imgUrls
                                }
                            }}>
                                <ListCard id={pro._id} name={pro.pro_name} price={pro.price} main_img={pro.main_imgUrl} />
                            </Link>
                        ))}
                    </Row>
                </div>
                <div className="my-4">
                    <h2 style={{ marginRight: "5rem", marginLeft: "3rem", marginBottom: "2rem", marginTop: "2rem" }}><u>New Arrival</u></h2>
                    <Row className="justify-content-center mx-0">
                        {productlist.newProduct.map(pro => (
                            <Link to={{
                                pathname: `/product/${pro._id}`,
                                state: {
                                    id: pro._id,
                                    name: pro.pro_name,
                                    price: pro.price,
                                    colors: pro.colors,
                                    sizes: pro.sizes,
                                    description: pro.description,
                                    main_img: pro.main_imgUrl,
                                    detail_imgs: pro.detail_imgUrls
                                }
                            }}>
                                <ListCard id={pro._id} name={pro.pro_name} price={pro.price} main_img={pro.main_imgUrl} />
                            </Link>
                        ))}
                    </Row>
                </div>
kusang96's avatar
kusang96 committed
94
        </Container>
Kim, Subin's avatar
Kim, Subin committed
95
96
97
98
    )
}

export default Home