Bookmark.js 1.5 KB
Newer Older
Lee SeoYeon's avatar
.    
Lee SeoYeon committed
1
2
3
import React, { useState, useEffect } from 'react'
import { Alert, Col, Card, Container, Form, Row, Button, Nav, Navbar, ListGroup, Image, Table } from "react-bootstrap"
import axios from "axios"
Lee SeoYeon's avatar
.    
Lee SeoYeon committed
4
import catchErrors from './utils/catchErrors.js'
Lee SeoYeon's avatar
.    
Lee SeoYeon committed
5
import { isAuthenticated } from './utils/auth'
Lee SeoYeon's avatar
.    
Lee SeoYeon committed
6
7
import { Redirect } from 'react-router-dom'

Lee SeoYeon's avatar
.    
Lee SeoYeon committed
8
const INIT_PAGE = {
Lee SeoYeon's avatar
.    
Lee SeoYeon committed
9
10
11
    bookmark: ['제주도'],
    bookmark: ['한라산'],

Lee SeoYeon's avatar
.    
Lee SeoYeon committed
12
13
}

Lee SeoYeon's avatar
.    
Lee SeoYeon committed
14
15
const user = isAuthenticated()

Lee SeoYeon's avatar
.    
Lee SeoYeon committed
16
function Bookmark() {
Lee SeoYeon's avatar
.    
Lee SeoYeon committed
17
    const [page, setPage] = useState(INIT_PAGE)
Lee SeoYeon's avatar
.    
Lee SeoYeon committed
18
19
    const [error, setError] = useState('')

Lee SeoYeon's avatar
.    
Lee SeoYeon committed
20
21
22
    const user = isAuthenticated()

    async function getBookmark(user) {
Lee SeoYeon's avatar
.    
Lee SeoYeon committed
23
24
        try {
            setError('')
Lee SeoYeon's avatar
.    
Lee SeoYeon committed
25
26
            const response = await axios.post(`/api/users/bookmark/${user}`)
            setPage(response.data)
Lee SeoYeon's avatar
.    
Lee SeoYeon committed
27
28
        } catch (error) {
            catchErrors(error, setError)
Lee SeoYeon's avatar
.    
Lee SeoYeon committed
29
        }   
Lee SeoYeon's avatar
.    
Lee SeoYeon committed
30
31
    }

Lee SeoYeon's avatar
.    
Lee SeoYeon committed
32
33
34
35
36
    useEffect(() => {
        Bookmark(user)
    }, [user])


Lee SeoYeon's avatar
.    
Lee SeoYeon committed
37
38
39
40
41
42
43
44
45
46
47

    return (
        <Container>
            <Navbar bg="primary" variant="dark">
                <Navbar.Brand href="/">북마크</Navbar.Brand>
                <Nav className="mr-auto">
                    <Nav.Link href="/">Home</Nav.Link>
                </Nav>
            </Navbar>
                <Form>
                    <ListGroup>
Lee SeoYeon's avatar
.    
Lee SeoYeon committed
48
49
                        <ListGroup.Item value={page.bookmark}></ListGroup.Item>
                        <ListGroup.Item></ListGroup.Item>
Lee SeoYeon's avatar
.    
Lee SeoYeon committed
50
51
52
53
54
55
56
                    </ListGroup>
                </Form>
        </Container>
    )
}

export default Bookmark