Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
R
react-material
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container 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
HyunjinNoh
react-material
Commits
a38a8e75
Commit
a38a8e75
authored
1 year ago
by
HyunjinNoh
Browse files
Options
Downloads
Patches
Plain Diff
재검색해도 좋아요 목록 유지까지 다 완료
parent
f61b24ec
No related branches found
No related tags found
No related merge requests found
Pipeline
#8134
passed
1 year ago
Stage: deploy
Changes
1
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/App.js
+12
-2
12 additions, 2 deletions
src/App.js
with
12 additions
and
2 deletions
src/App.js
+
12
−
2
View file @
a38a8e75
...
@@ -11,6 +11,7 @@ export default function App () {
...
@@ -11,6 +11,7 @@ export default function App () {
const
[
likes
,
setLikes
]
=
React
.
useState
({});
//좋아요결과
const
[
likes
,
setLikes
]
=
React
.
useState
({});
//좋아요결과
const
[
snackState
,
setSnackState
]
=
React
.
useState
({
open
:
false
,
msg
:
''
})
//스낵바열림결과
const
[
snackState
,
setSnackState
]
=
React
.
useState
({
open
:
false
,
msg
:
''
})
//스낵바열림결과
const
[
favorites
,
setFavorites
]
=
React
.
useState
([]);
//재검색해도 Favorites목록이 리셋되는 것을 막기 위해 Favorites 모아놓은 상태변수 만듦
const
handleTabChange
=
(
event
,
newValue
)
=>
{
//탭
const
handleTabChange
=
(
event
,
newValue
)
=>
{
//탭
setCurrentTab
(
newValue
);
setCurrentTab
(
newValue
);
...
@@ -19,6 +20,15 @@ export default function App () {
...
@@ -19,6 +20,15 @@ export default function App () {
const
toggleFavorite
=
(
id
,
name
)
=>
{
//좋아요와 스낵바 상태 업데이트
const
toggleFavorite
=
(
id
,
name
)
=>
{
//좋아요와 스낵바 상태 업데이트
setLikes
(
prevLikes
=>
({...
prevLikes
,
[
id
]:
!
prevLikes
[
id
]}));
//기존의 모든 키-값 쌍을 복사한다음 뒤에 써져있는대로 업데이트함
setLikes
(
prevLikes
=>
({...
prevLikes
,
[
id
]:
!
prevLikes
[
id
]}));
//기존의 모든 키-값 쌍을 복사한다음 뒤에 써져있는대로 업데이트함
setSnackState
({
open
:
true
,
msg
:
`
${
name
}
is clicked`
})
setSnackState
({
open
:
true
,
msg
:
`
${
name
}
is clicked`
})
if
(
likes
[
id
])
{
//이미 좋아요를 한 item이라면
setFavorites
(
prevFavorites
=>
prevFavorites
.
filter
(
item
=>
item
.
collectionId
!==
id
));
}
else
{
//그게 아니라서 굳이 신경쓸 필요 없으면
const
selectedItem
=
searchResult
.
find
(
item
=>
item
.
collectionId
===
id
);
if
(
selectedItem
)
{
setFavorites
(
prevFavorites
=>
[...
prevFavorites
,
selectedItem
]);
}
}
}
}
const
handleSnackbarClose
=
(
event
,
reason
)
=>
{
//스낵바 닫기
const
handleSnackbarClose
=
(
event
,
reason
)
=>
{
//스낵바 닫기
...
@@ -51,7 +61,7 @@ export default function App () {
...
@@ -51,7 +61,7 @@ export default function App () {
{currentTab == 1 &&
{currentTab == 1 &&
<>
<>
<Typography align = "center" variant = "h5"> Favorites </Typography>
<Typography align = "center" variant = "h5"> Favorites </Typography>
<Favorites list = {
searchResult
} likes = {likes} toggleFavorite = {toggleFavorite}/>
<Favorites list = {
favorites
} likes = {likes} toggleFavorite = {toggleFavorite}/>
</>}
</>}
{currentTab == 2 && <Typography align = "center" variant = "h5"> More Contents </Typography>}
{currentTab == 2 && <Typography align = "center" variant = "h5"> More Contents </Typography>}
<SnackMsg open = {snackState.open} message = {snackState.msg} onClose = {handleSnackbarClose}/>
<SnackMsg open = {snackState.open} message = {snackState.msg} onClose = {handleSnackbarClose}/>
...
...
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