Skip to content
Snippets Groups Projects
Commit 35b64778 authored by nahyun's avatar nahyun
Browse files

parent 64be09d5
No related branches found
No related tags found
No related merge requests found
Pipeline #8491 passed
...@@ -14,6 +14,37 @@ export default function App() { ...@@ -14,6 +14,37 @@ export default function App() {
const [favorites, setFavorites] = React.useState([]); const [favorites, setFavorites] = React.useState([]);
//const [like, setLike] = React.useState([]); //const [like, setLike] = React.useState([]);
const fetchfunc = () => {
axios.get('http://localhost:8888/likes')
.then((response) => {
const data = response.data;
data.map(item => {
console.log(item);
handleOnLike(item);
})
//onLike(data);
//setFavorites(data);
console.log(data);
})
.catch((error) => {
console.error('Error:', error);
});
}
useEffect(() => {
// axios.get('http://localhost:8888/likes')
// .then((response) => {
// const data = response.data;
// //onLike(data);
// //setFavorites(data);
// console.log(data);
// })
// .catch((error) => {
// console.error('Error:', error);
// });
fetchfunc();
}, []);
const handleTabChange = (event, newValue) => { const handleTabChange = (event, newValue) => {
setCurrentTab(newValue); setCurrentTab(newValue);
} }
...@@ -100,7 +131,7 @@ export default function App() { ...@@ -100,7 +131,7 @@ export default function App() {
let b = favorites.filter((it) => it.collectionId !== item.collectionId); let b = favorites.filter((it) => it.collectionId !== item.collectionId);
setFavorites(b); setFavorites(b);
axios.delete(`/likes/${item.collectionId}`) axios.delete(`http://localhost:8888/likes/${item.collectionId}`)
.then((response) => { .then((response) => {
console.log(response.data); console.log(response.data);
}) })
...@@ -119,7 +150,7 @@ export default function App() { ...@@ -119,7 +150,7 @@ export default function App() {
//setFavorites([...favorites, { ...item, like: true }]); //setFavorites([...favorites, { ...item, like: true }]);
//좋아요 아이템 spring 서버로 보내기 //좋아요 아이템 spring 서버로 보내기
axios.post('/likes', { axios.post('http://localhost:8888/likes', {
collectionId: item.collectionId, collectionId: item.collectionId,
collectionType: item.collectionType, collectionType: item.collectionType,
artistId: item.artistId, artistId: item.artistId,
...@@ -209,7 +240,7 @@ export default function App() { ...@@ -209,7 +240,7 @@ export default function App() {
</Box> </Box>
{currentTab == 0 && <SearchPage list={searchResult} onSearch={setSearchResult} onLike={handleOnLike} />} {currentTab == 0 && <SearchPage list={searchResult} onSearch={setSearchResult} onLike={handleOnLike} />}
{currentTab == 1 && <Favorites list={favorites} onLike={handleOnLike} />} {currentTab == 1 && <Favorites list={favorites} onFavorite={setFavorites} onLike={handleOnLike} />}
{currentTab == 2 && {currentTab == 2 &&
<Typography align="center" variant="h2">Item Three</Typography>} <Typography align="center" variant="h2">Item Three</Typography>}
</React.Fragment> </React.Fragment>
......
...@@ -33,7 +33,7 @@ export default function SearchPage({ list, onSearch, onLike }) { ...@@ -33,7 +33,7 @@ export default function SearchPage({ list, onSearch, onLike }) {
// console.error('Error:', error); // console.error('Error:', error);
// }); // });
fetch(`/musicSearch/${(searchWord)}`, { fetch(`http://localhost:8888/musicSearch/${(searchWord)}`, {
method: 'GET', // HTTP 메서드는 GET입니다. method: 'GET', // HTTP 메서드는 GET입니다.
headers: {}, headers: {},
}) })
......
...@@ -5,19 +5,21 @@ import axios from 'axios'; ...@@ -5,19 +5,21 @@ import axios from 'axios';
import React, { useEffect } from 'react'; import React, { useEffect } from 'react';
import App from './App'; import App from './App';
const Favorites = ({ list, onLike }) => { const Favorites = ({ list, onSearch, onLike }) => {
const [Favorites, setFavorites] = React.useState([]); //const [Favorites, setFavorites] = React.useState([]);
useEffect(() => { // useEffect(() => {
axios.get('/likes') // axios.get('http://localhost:8888/likes')
.then((response) => { // .then((response) => {
const data = response.data; // const data = response.data;
setFavorites(data); // onLike(data);
}) // //setFavorites(data);
.catch((error) => { // console.log(data);
console.error('Error:', error); // })
}); // .catch((error) => {
}, []); // console.error('Error:', error);
// });
// }, []);
return ( return (
<React.Fragment> <React.Fragment>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment