SubNav.js 1.7 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';
kusang96's avatar
kusang96 committed
3
4
import axios from 'axios';
import catchErrors from '../utils/catchErrors';
Kim, Subin's avatar
정리    
Kim, Subin committed
5
import { Navbar, Nav } from 'react-bootstrap';
Kim, Subin's avatar
Kim, Subin committed
6
7

function SubNav() {
Jiwon Yoon's avatar
Jiwon Yoon committed
8
    const [categoriesDiv, setCategoriesDiv] = useState([])
kusang96's avatar
kusang96 committed
9
10
11
12
    const [error, setError] = useState('')

    useEffect(async () => {
        try {
이재연's avatar
0115    
이재연 committed
13
            const response = await axios.get('/api/categories/main')
kusang96's avatar
kusang96 committed
14
15
            let list = []
            Object.keys(response.data[0]).forEach((ele) => {
kusang96's avatar
kusang96 committed
16
                const url = ele.toLowerCase()
kusang96's avatar
kusang96 committed
17
                list.push(
18
                    <Nav.Link href={`/categories/${url}`}>{ele}</Nav.Link>
kusang96's avatar
kusang96 committed
19
20
                )
            })
Jiwon Yoon's avatar
Jiwon Yoon committed
21
            setCategoriesDiv(list)
kusang96's avatar
kusang96 committed
22
23
24
25
        } catch (error) {
            catchErrors(error, setError)
        }
    }, [])
Kim, Subin's avatar
Kim, Subin committed
26
27

    return (
kusang96's avatar
kusang96 committed
28
        <Navbar sticky="top" className="flex-nowrap" style={{ top: "56px", paddingTop: "0", paddingBottom: "0", backgroundColor: "#fff" }}>
29
30
            <style type="text/css">
                {`
박상호's avatar
css    
박상호 committed
31
32
33
34
35
36
37
38
                @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'}
                
39
40
41
42
43
                .nav-link, .nav-link:hover, .nav-link:active {
                    color: #91877F;
                }
                `}
            </style>
kusang96's avatar
kusang96 committed
44
            <Nav style={{ overflowX: "auto" }}>
Jiwon Yoon's avatar
Jiwon Yoon committed
45
                {categoriesDiv.map(item => item)}
46
47
            </Nav>
        </Navbar>
Kim, Subin's avatar
Kim, Subin committed
48
49
50
51
    )
}

export default SubNav