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
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
nahyun
react-material
Commits
0759a131
Commit
0759a131
authored
1 year ago
by
nahyun
Browse files
Options
Downloads
Patches
Plain Diff
?
parent
9b73b379
Branches
Branches containing commit
No related tags found
No related merge requests found
Pipeline
#8500
passed
1 year ago
Stage: deploy
Changes
1
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/App.js
+145
-111
145 additions, 111 deletions
src/App.js
with
145 additions
and
111 deletions
src/App.js
+
145
−
111
View file @
0759a131
...
...
@@ -118,57 +118,57 @@ export default function App() {
// }
//버전3 - 연결시키기 위해 노력 - 최종
const
handleOnLike
=
(
item
)
=>
{
let
favoriteItem
=
favorites
.
find
((
it
)
=>
it
.
collectionId
===
item
.
collectionId
);
//
const handleOnLike = (item) => {
//
let favoriteItem = favorites.find((it) => it.collectionId === item.collectionId);
if
(
favoriteItem
)
{
// if (favoriteItem) {
// // item.like = false;
// //favorite & search 둘다 삭제
// let a = searchResult.find((it) => it.collectionId === item.collectionId);
// if (a) {
// 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
);
// }
// let b = favorites.filter((it) => it.collectionId !== item.collectionId);
// setFavorites(b);
axios
.
delete
(
`/likes/
${
item
.
collectionId
}
`
)
.
then
((
response
)
=>
{
console
.
log
(
response
.
data
);
})
.
catch
((
error
)
=>
{
console
.
error
(
'
Error:
'
,
error
);
})
}
//
axios.delete(`/likes/${item.collectionId}`)
//
.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
]);
//
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
,
artistName
:
item
.
artistName
,
artistViewUrl
:
item
.
artistViewUrl
,
collectionName
:
item
.
collectionName
,
collectionViewUrl
:
item
.
collectionViewUrl
}
// //setFavorites([...favorites, { ...item, like: true }]);
// //좋아요 아이템 spring 서버로 보내기
// axios.post('/likes', {
// collectionId: item.collectionId,
// collectionType: item.collectionType,
// artistId: item.artistId,
// artistName: item.artistName,
// artistViewUrl: item.artistViewUrl,
// collectionName: item.collectionName,
// collectionViewUrl: item.collectionViewUrl
// }
)
.
then
((
response
)
=>
{
console
.
log
(
response
.
data
);
})
.
catch
((
error
)
=>
{
console
.
error
(
'
Error:
'
,
error
);
});
}
// )
// .then((response) => {
// console.log(response.data);
// })
// .catch((error) => {
// console.error('Error:', error);
// });
// }
// const handleOnLike = (item) => {
// let favoriteItem = favorites.find((it) => it.collectionId === item.collectionId);
...
...
@@ -236,6 +236,40 @@ export default function App() {
// })
// }
// }
const
handleOnLike
=
(
item
)
=>
{
let
favoriteItem
=
favorites
.
find
(
it
=>
it
.
collectionId
==
item
.
collectionId
)
if
(
favoriteItem
)
{
fetch
(
`/likes/
${
item
.
collectionId
}
`
,
{
method
:
'
DELETE
'
,
headers
:
{},
})
.
then
(
r
=>
{
let
i
=
searchResult
.
find
(
it
=>
it
.
collectionId
==
item
.
collectionId
)
if
(
i
)
{
item
.
like
=
false
;
}
let
remains
=
favorites
.
filter
((
it
)
=>
it
.
collectionId
!==
item
.
collectionId
);
setFavorites
(
remains
);
})
.
catch
(
e
=>
console
.
log
(
'
error when delete method >
'
,
e
));
}
else
{
fetch
(
`/likes`
,
{
method
:
'
POST
'
,
headers
:
{
'
Content-Type
'
:
'
application/json
'
},
body
:
JSON
.
stringify
(
item
)
})
.
then
(
r
=>
r
.
json
())
.
then
(
r
=>
{
let
i
=
searchResult
.
find
(
it
=>
it
.
collectionId
==
item
.
collectionId
)
if
(
i
)
{
item
.
like
=
true
;
}
setFavorites
([...
favorites
,
item
]);
})
.
catch
(
e
=>
console
.
log
(
'
error when post >
'
,
e
));
}
};
return
(
...
...
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