diff --git a/src/App.js b/src/App.js index e6ff4387981eca0bb6ee897edda3bf7d1c95f015..ae69bc07283a3ecb03ddcc4c9584fe3fe4108c17 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 b75c11f0184ba76d5daa520185a2936467085e75..36a003129c7edf4f40b44971bb4e3cea8c9b2b43 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 af5990c8dc33cb40376617aae6c9619506f88bf9..c1510b45037acdc024ead08bb84fe7e43f48f69b 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 b6b366ad8bce272cde9e503fec259569d2997c68..9c8b61b6803de615fbe9b4485d8af15601548dac 100644 --- a/src/favorites.js +++ b/src/favorites.js @@ -73,3 +73,4 @@ export default Favorites; // </React.Fragment> // ); // } +