Bookmark.js 1.53 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
    name: '',
    bookmark: []
Lee SeoYeon's avatar
.    
Lee SeoYeon committed
11
12
}

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

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

Lee SeoYeon's avatar
.    
Lee SeoYeon committed
19
20
21
22
    async function handleSubmit(event) {
        event.preventDefault()
        try {
            setError('')
Lee SeoYeon's avatar
.    
Lee SeoYeon committed
23
            const response = await axios.post('/api/users/bookmark',page)
Lee SeoYeon's avatar
.    
Lee SeoYeon committed
24
            console.log(page)
Lee SeoYeon's avatar
.    
Lee SeoYeon committed
25
26
27
28
            // setUser(INIT_USER)
        } catch (error) {
            console.log(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
                        <ListGroup.Item action href="">북마크1</ListGroup.Item>
Lee SeoYeon's avatar
.    
Lee SeoYeon committed
49
50
51
52
53
54
55
56
                        <ListGroup.Item>북마크2</ListGroup.Item>
                    </ListGroup>
                </Form>
        </Container>
    )
}

export default Bookmark