Commit f81deda0 authored by Lee SeoYeon's avatar Lee SeoYeon
Browse files

..

parent 7af468a7
This diff is collapsed.
...@@ -3,12 +3,11 @@ import { Alert, Col, Card, Container, Form, Row, Button, Nav, Navbar, ListGroup, ...@@ -3,12 +3,11 @@ import { Alert, Col, Card, Container, Form, Row, Button, Nav, Navbar, ListGroup,
import axios from "axios" import axios from "axios"
import catchErrors from './utils/catchErrors.js' import catchErrors from './utils/catchErrors.js'
import { isAuthenticated } from './utils/auth' import { isAuthenticated } from './utils/auth'
import { Redirect } from 'react-router-dom'
const INIT_PAGE = {
bookmark: ['제주도'],
bookmark: ['한라산'],
const INIT_PAGE = {
bookmark: ['성산일출봉', '제주도', '한라산', '주상절리', '오설록 티 뮤지엄'],
} }
const user = isAuthenticated() const user = isAuthenticated()
...@@ -16,22 +15,39 @@ const user = isAuthenticated() ...@@ -16,22 +15,39 @@ const user = isAuthenticated()
function Bookmark() { function Bookmark() {
const [page, setPage] = useState(INIT_PAGE) const [page, setPage] = useState(INIT_PAGE)
const [error, setError] = useState('') const [error, setError] = useState('')
const [success, setSuccess] = useState(false)
const [state, setState] = useState(false);
const user = isAuthenticated() const user = isAuthenticated()
async function getBookmark(user) { const userId = localStorage.getItem('loginStatus')
async function getBookmark( ) {
try { try {
setError('') setError('')
const response = await axios.post(`/api/users/bookmark/${user}`) console.log(page)
setPage(response.data) console.log(userId)
await axios.post(`/api/users/bookmark`, {bookmark: page, userId: userId})
} catch (error) { } catch (error) {
catchErrors(error, setError) catchErrors(error, setError)
} }
} }
useEffect(() => { // async function handleSubmit(e){
Bookmark(user) // setState(true); //버튼이 눌려서 handlesubmit이될때 setState값이 true로 바뀐다
}, [user]) // try { //respons 서버에 post로 요청하여 데이터를 받아온다
// const response = await axios.post('/api/users/bookmark', page)
// setSuccess(true)
// } catch (error) {
// console.log(error)
// catchErrors(error, setError)
// }
// }
// useEffect(() => {
// getBookmark(user)
// }, [user])
...@@ -42,11 +58,15 @@ function Bookmark() { ...@@ -42,11 +58,15 @@ function Bookmark() {
<Nav className="mr-auto"> <Nav className="mr-auto">
<Nav.Link href="/">Home</Nav.Link> <Nav.Link href="/">Home</Nav.Link>
</Nav> </Nav>
<Button type='submit' onClick={getBookmark}>저장</Button>
</Navbar> </Navbar>
<Form> <Form>
<ListGroup> <ListGroup>
<ListGroup.Item value={page.bookmark}></ListGroup.Item> <ListGroup.Item>{page.bookmark[0]}</ListGroup.Item>
<ListGroup.Item></ListGroup.Item> <ListGroup.Item>{page.bookmark[1]}</ListGroup.Item>
<ListGroup.Item>{page.bookmark[2]}</ListGroup.Item>
<ListGroup.Item>{page.bookmark[3]}</ListGroup.Item>
<ListGroup.Item>{page.bookmark[4]}</ListGroup.Item>
</ListGroup> </ListGroup>
</Form> </Form>
</Container> </Container>
......
...@@ -80,13 +80,6 @@ function Search(props) { ...@@ -80,13 +80,6 @@ function Search(props) {
async function handleSubmit(e){ async function handleSubmit(e){
setState(true); //버튼이 눌려서 handlesubmit이될때 setState값이 true로 바뀐다 setState(true); //버튼이 눌려서 handlesubmit이될때 setState값이 true로 바뀐다
try { //respons 서버에 post로 요청하여 데이터를 받아온다
const response = await axios.post('/api/users/bookmark', page)
setSuccess(true)
} catch (error) {
console.log(error)
catchErrors(error, setError)
}
} }
function paginate(items, pageNumber, itemNumber) { function paginate(items, pageNumber, itemNumber) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment