Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
react-material
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
nahyun
react-material
Commits
9b73b379
Commit
9b73b379
authored
1 year ago
by
nahyun
Browse files
Options
Downloads
Patches
Plain Diff
middle
parent
35b64778
No related branches found
No related tags found
No related merge requests found
Pipeline
#8492
passed
1 year ago
Stage: deploy
Changes
2
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/App.js
+51
-35
51 additions, 35 deletions
src/App.js
src/favorites.js
+14
-4
14 additions, 4 deletions
src/favorites.js
with
65 additions
and
39 deletions
src/App.js
+
51
−
35
View file @
9b73b379
//
import React from 'react';
import
React
from
'
react
'
;
import
React
,
{
useEffect
}
from
'
react
'
;
//
import React, { useEffect } from 'react';
import
MusicList
from
'
./MusicList
'
;
import
MusicList
from
'
./MusicList
'
;
import
music_list
from
'
./data
'
;
import
music_list
from
'
./data
'
;
...
@@ -14,27 +14,14 @@ export default function App() {
...
@@ -14,27 +14,14 @@ 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
=
()
=>
{
// 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')
// axios.get('http://localhost:8888/likes')
// .then((response) => {
// .then((response) => {
// const data = response.data;
// const data = response.data;
// data.map(item => {
// console.log(item);
// handleOnLike(item);
// })
// //onLike(data);
// //onLike(data);
// //setFavorites(data);
// //setFavorites(data);
// console.log(data);
// console.log(data);
...
@@ -42,8 +29,21 @@ export default function App() {
...
@@ -42,8 +29,21 @@ export default function App() {
// .catch((error) => {
// .catch((error) => {
// console.error('Error:', error);
// console.error('Error:', error);
// });
// });
fetchfunc
();
// }
},
[]);
// 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
);
...
@@ -117,7 +117,7 @@ export default function App() {
...
@@ -117,7 +117,7 @@ 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
);
...
@@ -131,7 +131,7 @@ export default function App() {
...
@@ -131,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
(
`
http://localhost:8888
/likes/
${
item
.
collectionId
}
`
)
axios
.
delete
(
`/likes/
${
item
.
collectionId
}
`
)
.
then
((
response
)
=>
{
.
then
((
response
)
=>
{
console
.
log
(
response
.
data
);
console
.
log
(
response
.
data
);
})
})
...
@@ -150,7 +150,7 @@ export default function App() {
...
@@ -150,7 +150,7 @@ export default function App() {
//setFavorites([...favorites, { ...item, like: true }]);
//setFavorites([...favorites, { ...item, like: true }]);
//좋아요 아이템 spring 서버로 보내기
//좋아요 아이템 spring 서버로 보내기
axios
.
post
(
'
http://localhost:8888
/likes
'
,
{
axios
.
post
(
'
/likes
'
,
{
collectionId
:
item
.
collectionId
,
collectionId
:
item
.
collectionId
,
collectionType
:
item
.
collectionType
,
collectionType
:
item
.
collectionType
,
artistId
:
item
.
artistId
,
artistId
:
item
.
artistId
,
...
@@ -220,6 +220,22 @@ export default function App() {
...
@@ -220,6 +220,22 @@ export default function App() {
// it.collectionId === item.collectionId ? { ...it, like: !favoriteItem } : it
// it.collectionId === item.collectionId ? { ...it, like: !favoriteItem } : it
// );
// );
// setSearchResult(updatedSearchResult);
// setSearchResult(updatedSearchResult);
//고쳐보자..
// const handOnLike = (item) => {
// let favoriteitem = favorite.find(it => it.collectionId == item.collectionId)
// if (favoriteitem) {
// fetch(`/likes/${item.collectionId}`, {
// method: "Delete",
// headers: {},
// }).then((response) => {
// if(response.ok){
// let
// }
// })
// }
// }
};
};
return
(
return
(
...
@@ -240,7 +256,7 @@ export default function App() {
...
@@ -240,7 +256,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}
onFavorite={setFavorites}
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>
...
...
This diff is collapsed.
Click to expand it.
src/favorites.js
+
14
−
4
View file @
9b73b379
//
import React from 'react';
import
React
from
'
react
'
;
import
{
Typography
}
from
'
@mui/material
'
;
import
{
Typography
}
from
'
@mui/material
'
;
import
MusicList
from
'
./MusicList
'
;
import
MusicList
from
'
./MusicList
'
;
import
axios
from
'
axios
'
;
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
,
onSearch
,
onLike
})
=>
{
const
Favorites
=
({
list
,
onLike
})
=>
{
//
const [Favorites, setFavorites] = React.useState([]);
const
[
Favorites
,
setFavorites
]
=
React
.
useState
([]);
// useEffect(() => {
// useEffect(() => {
// axios.get('http://localhost:8888/likes')
// axios.get('http://localhost:8888/likes')
...
@@ -21,6 +21,16 @@ const Favorites = ({ list, onSearch, onLike }) => {
...
@@ -21,6 +21,16 @@ const Favorites = ({ list, onSearch, onLike }) => {
// });
// });
// }, []);
// }, []);
React
.
useEffect
(()
=>
{
fetch
(
`/likes`
,
{
method
:
'
GET
'
,
headers
:
{},
}).
then
((
response
)
=>
response
.
json
())
.
then
((
data
)
=>
{
setFavorites
(
data
);
}).
catch
((
e
)
=>
console
.
log
(
"
Error fetching favorites:
"
,
e
));
},
[]);
return
(
return
(
<
React
.
Fragment
>
<
React
.
Fragment
>
<
MusicList
list
=
{
list
}
onLike
=
{
onLike
}
/
>
<
MusicList
list
=
{
list
}
onLike
=
{
onLike
}
/
>
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment