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

새로고침 오류 정정

parent e3b5ea60
Branches
No related tags found
No related merge requests found
Pipeline #8505 passed
...@@ -271,8 +271,24 @@ export default function App() { ...@@ -271,8 +271,24 @@ export default function App() {
// .catch(e => console.log('error when post >', e)); // .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) => { const handleOnlike = (item) => {
let t = favoriteItem.find(it => it.collectionId == item.collectionId) let t = favorites.find(it => it.collectionId == item.collectionId)
if (t) { if (t) {
fetch(`/likes/${item.collectionId}`, { fetch(`/likes/${item.collectionId}`, {
...@@ -323,11 +339,10 @@ export default function App() { ...@@ -323,11 +339,10 @@ export default function App() {
</Tabs> </Tabs>
</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} 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>
) )
} }
...@@ -73,3 +73,4 @@ export default Favorites; ...@@ -73,3 +73,4 @@ export default Favorites;
// </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