From fa4776e6dc9ee7be0a9d1a6aaa2208ade4afae22 Mon Sep 17 00:00:00 2001 From: NaHyun22 <nhle0217@ajou.ac.kr> Date: Sun, 6 Aug 2023 12:06:23 +0900 Subject: [PATCH] =?UTF-8?q?=EC=83=88=EB=A1=9C=EA=B3=A0=EC=B9=A8=20?= =?UTF-8?q?=EC=98=A4=EB=A5=98=20=EC=A0=95=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/App.js | 21 ++++++++++++++++++--- src/MusicList.js | 2 +- src/SearchPage.js | 2 +- src/favorites.js | 1 + 4 files changed, 21 insertions(+), 5 deletions(-) diff --git a/src/App.js b/src/App.js index e6ff438..ae69bc0 100644 --- a/src/App.js +++ b/src/App.js @@ -271,8 +271,24 @@ export default function App() { // .catch(e => console.log('error when post >', e)); // } + React.useEffect(() => { + const getLikesData = async () => { + try { + const res = await axios.get("http://localhost:8888/likes"); + const temp = res.data.map((item) => ({ ...item, like: true })); + setFavorites(temp); + //setFavorites(res.data); + + } catch (e) { + console.log(e); + } + }; + + getLikesData(); + }, []); + const handleOnlike = (item) => { - let t = favoriteItem.find(it => it.collectionId == item.collectionId) + let t = favorites.find(it => it.collectionId == item.collectionId) if (t) { fetch(`/likes/${item.collectionId}`, { @@ -323,11 +339,10 @@ export default function App() { </Tabs> </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 == 2 && <Typography align="center" variant="h2">Item Three</Typography>} </React.Fragment> ) } - diff --git a/src/MusicList.js b/src/MusicList.js index b75c11f..36a0031 100644 --- a/src/MusicList.js +++ b/src/MusicList.js @@ -62,4 +62,4 @@ export default function MusicList({ list, onLike }) { })} </div> ); -} \ No newline at end of file +} diff --git a/src/SearchPage.js b/src/SearchPage.js index af5990c..c1510b4 100644 --- a/src/SearchPage.js +++ b/src/SearchPage.js @@ -81,4 +81,4 @@ export default function SearchPage({ list, onSearch, onLike }) { <MusicList list={list} onLike={onLike} /> </React.Fragment> ) -} \ No newline at end of file +} diff --git a/src/favorites.js b/src/favorites.js index b6b366a..9c8b61b 100644 --- a/src/favorites.js +++ b/src/favorites.js @@ -73,3 +73,4 @@ export default Favorites; // </React.Fragment> // ); // } + -- GitLab