Skip to content
Snippets Groups Projects
Commit 0759a131 authored by nahyun's avatar nahyun
Browse files

?

parent 9b73b379
No related branches found
No related tags found
No related merge requests found
Pipeline #8500 passed
...@@ -118,57 +118,57 @@ export default function App() { ...@@ -118,57 +118,57 @@ export default function App() {
// } // }
//버전3 - 연결시키기 위해 노력 - 최종 //버전3 - 연결시키기 위해 노력 - 최종
const handleOnLike = (item) => { // const handleOnLike = (item) => {
let favoriteItem = favorites.find((it) => it.collectionId === item.collectionId); // let favoriteItem = favorites.find((it) => it.collectionId === item.collectionId);
if (favoriteItem) { // if (favoriteItem) {
// // item.like = false;
// //favorite & search 둘다 삭제
// let a = searchResult.find((it) => it.collectionId === item.collectionId);
// if (a) {
// item.like = false; // item.like = false;
//favorite & search 둘다 삭제 // }
let a = searchResult.find((it) => it.collectionId === item.collectionId); // let b = favorites.filter((it) => it.collectionId !== item.collectionId);
if (a) { // setFavorites(b);
item.like = false;
}
let b = favorites.filter((it) => it.collectionId !== item.collectionId);
setFavorites(b);
axios.delete(`/likes/${item.collectionId}`) // axios.delete(`/likes/${item.collectionId}`)
.then((response) => { // .then((response) => {
console.log(response.data); // console.log(response.data);
}) // })
.catch((error) => { // .catch((error) => {
console.error('Error: ', error); // console.error('Error: ', error);
}) // })
} // }
else { // else {
let a = searchResult.find((it) => it.collectionId !== item.collectionId); // let a = searchResult.find((it) => it.collectionId !== item.collectionId);
if (a) { // if (a) {
item.like = true; // item.like = true;
} // }
setFavorites([...favorites, item]); // setFavorites([...favorites, item]);
//setFavorites([...favorites, { ...item, like: true }]); // //setFavorites([...favorites, { ...item, like: true }]);
//좋아요 아이템 spring 서버로 보내기
axios.post('/likes', {
collectionId: item.collectionId,
collectionType: item.collectionType,
artistId: item.artistId,
artistName: item.artistName,
artistViewUrl: item.artistViewUrl,
collectionName: item.collectionName,
collectionViewUrl: item.collectionViewUrl
}
// //좋아요 아이템 spring 서버로 보내기
// axios.post('/likes', {
// collectionId: item.collectionId,
// collectionType: item.collectionType,
// artistId: item.artistId,
// artistName: item.artistName,
// artistViewUrl: item.artistViewUrl,
// collectionName: item.collectionName,
// collectionViewUrl: item.collectionViewUrl
// }
)
.then((response) => { // )
console.log(response.data); // .then((response) => {
}) // console.log(response.data);
.catch((error) => { // })
console.error('Error:', error); // .catch((error) => {
}); // console.error('Error:', error);
} // });
// }
// const handleOnLike = (item) => { // const handleOnLike = (item) => {
// let favoriteItem = favorites.find((it) => it.collectionId === item.collectionId); // let favoriteItem = favorites.find((it) => it.collectionId === item.collectionId);
...@@ -236,6 +236,40 @@ export default function App() { ...@@ -236,6 +236,40 @@ export default function App() {
// }) // })
// } // }
// } // }
const handleOnLike = (item) => {
let favoriteItem = favorites.find(it => it.collectionId == item.collectionId)
if (favoriteItem) {
fetch(`/likes/${item.collectionId}`, {
method: 'DELETE',
headers: {},
})
.then(r => {
let i = searchResult.find(it => it.collectionId == item.collectionId)
if (i) {
item.like = false;
}
let remains = favorites.filter((it) => it.collectionId !== item.collectionId);
setFavorites(remains);
})
.catch(e => console.log('error when delete method >', e));
}
else {
fetch(`/likes`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(item)
})
.then(r => r.json())
.then(r => {
let i = searchResult.find(it => it.collectionId == item.collectionId)
if (i) {
item.like = true;
}
setFavorites([...favorites, item]);
})
.catch(e => console.log('error when post >', e));
}
}; };
return ( return (
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment