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
a1956127
Commit
a1956127
authored
1 year ago
by
nahyun
Browse files
Options
Downloads
Patches
Plain Diff
finish
parent
68de4d38
No related branches found
No related tags found
No related merge requests found
Pipeline
#8432
passed
1 year ago
Stage: deploy
Changes
3
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/App.js
+104
-5
104 additions, 5 deletions
src/App.js
src/SearchPage.js
+1
-1
1 addition, 1 deletion
src/SearchPage.js
src/snackbar.js
+6
-6
6 additions, 6 deletions
src/snackbar.js
with
111 additions
and
12 deletions
src/App.js
+
104
−
5
View file @
a1956127
...
@@ -34,7 +34,45 @@ export default function App() {
...
@@ -34,7 +34,45 @@ export default function App() {
// }
// }
// };
// };
//버전2
//버전2 - 돌아가긴 함. (최종 버전 spring 병합이 안됌)
// const handleOnLike = (item) => {
// let favoriteItem = favorites.find((it) => it.collectionId === item.collectionId);
// if (favoriteItem) {
// // item.like = false;
// //favorite & search 둘다 삭제
// let a = searchResult.find((it) => it.collectionId === item.collectionId);
// if (a) {
// item.like = false;
// }
// let b = favorites.filter((it) => it.collectionId !== item.collectionId);
// setFavorites(b);
// }
// else {
// let a = searchResult.find((it) => it.collectionId === item.collectionId);
// if (a) {
// item.like = true;
// }
// setFavorites([...favorites, item]);
// //setFavorites([...favorites, { ...item, like: true }]);
// //좋아요 아이템 spring 서버로 보내기
// axios.post('/likes', {
// collectionId: item.collectionId,
// collectionType: item.collectionType,
// artistId: item.artistId
// }
// )
// .then((response) => {
// console.log(response.data);
// })
// .catch((error) => {
// console.error('Error:', error);
// });
// }
//버전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
);
...
@@ -47,9 +85,18 @@ export default function App() {
...
@@ -47,9 +85,18 @@ 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
(
`/likes/
${
item
.
collectionId
}
`
)
.
then
((
response
)
=>
{
console
.
log
(
response
.
data
);
})
.
catch
((
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
;
}
}
...
@@ -58,9 +105,15 @@ export default function App() {
...
@@ -58,9 +105,15 @@ export default function App() {
//setFavorites([...favorites, { ...item, like: true }]);
//setFavorites([...favorites, { ...item, like: true }]);
//좋아요 아이템 spring 서버로 보내기
//좋아요 아이템 spring 서버로 보내기
axios
.
post
(
'
/likes
'
,
{
collectionId
:
item
.
collectionId
},
axios
.
post
(
'
/likes
'
,
{
{
collectionType
:
item
.
collectionType
},
collectionId
:
item
.
collectionId
,
{
artistId
:
item
.
artistId
}
collectionType
:
item
.
collectionType
,
artistId
:
item
.
artistId
,
artistName
:
item
.
artistName
,
artistViewUrl
:
item
.
artistViewUrl
,
collectionName
:
item
.
collectionName
,
collectionViewUrl
:
item
.
collectionViewUrl
}
)
)
.
then
((
response
)
=>
{
.
then
((
response
)
=>
{
console
.
log
(
response
.
data
);
console
.
log
(
response
.
data
);
...
@@ -70,6 +123,52 @@ export default function App() {
...
@@ -70,6 +123,52 @@ export default function App() {
});
});
}
}
// const handleOnLike = (item) => {
// let favoriteItem = favorites.find((it) => it.collectionId === item.collectionId);
// if (favoriteItem) {
// let a = searchResult.find((it) => it.collectionId === item.collectionId);
// if (a) {
// item.like = false;
// }
// let updatedFavorites = favorites.filter((it) => it.collectionId !== item.collectionId);
// setFavorites(updatedFavorites);
// // 좋아요 아이템 spring 서버로 보내기
// axios.post('/likes', {
// collectionId: item.collectionId,
// collectionType: item.collectionType,
// artistId: item.artistId
// })
// .then((response) => {
// console.log(response.data);
// })
// .catch((error) => {
// console.error('Error:', error);
// });
// } else {
// let a = searchResult.find((it) => it.collectionId === item.collectionId);
// if (a) {
// item.like = true;
// }
// setFavorites([...favorites, item]);
// // 좋아요 아이템 spring 서버로 보내기
// axios.post('/likes', {
// collectionId: item.collectionId,
// collectionType: item.collectionType,
// artistId: item.artistId
// })
// .then((response) => {
// console.log(response.data);
// })
// .catch((error) => {
// console.error('Error:', error);
// });
// }
// };
// const updatedSearchResult = searchResult.map((it) =>
// const updatedSearchResult = searchResult.map((it) =>
// it.collectionId === item.collectionId ? { ...it, like: !favoriteItem } : it
// it.collectionId === item.collectionId ? { ...it, like: !favoriteItem } : it
// );
// );
...
...
This diff is collapsed.
Click to expand it.
src/SearchPage.js
+
1
−
1
View file @
a1956127
...
@@ -33,7 +33,7 @@ export default function SearchPage({ list, onSearch, onLike }) {
...
@@ -33,7 +33,7 @@ export default function SearchPage({ list, onSearch, onLike }) {
// console.error('Error:', error);
// console.error('Error:', error);
// });
// });
fetch
(
`/musicSearch/
${
encodeURIComponent
(
searchWord
)}
`
,
{
fetch
(
`/musicSearch/
${(
searchWord
)}
`
,
{
method
:
'
GET
'
,
// HTTP 메서드는 GET입니다.
method
:
'
GET
'
,
// HTTP 메서드는 GET입니다.
headers
:
{},
headers
:
{},
})
})
...
...
This diff is collapsed.
Click to expand it.
src/snackbar.js
+
6
−
6
View file @
a1956127
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