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
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Admin message
During summer vacation, Gitlab will be restart frequently. Use it carefully.
Show more breadcrumbs
HyunjinNoh
react-material
Commits
33604124
Commit
33604124
authored
Jul 15, 2023
by
HyunjinNoh
Browse files
Options
Downloads
Patches
Plain Diff
일단 Favorite 잘 작동 안 되는 상태
parent
39b1ee99
Branches
Branches containing commit
No related tags found
No related merge requests found
Pipeline
#8128
passed
Jul 15, 2023
Stage: deploy
Changes
4
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
src/App.js
+1
-1
1 addition, 1 deletion
src/App.js
src/Favorites.js
+14
-0
14 additions, 0 deletions
src/Favorites.js
src/MusicList.js
+9
-4
9 additions, 4 deletions
src/MusicList.js
src/SearchPage.js
+34
-1
34 additions, 1 deletion
src/SearchPage.js
with
58 additions
and
6 deletions
src/App.js
+
1
−
1
View file @
33604124
...
...
@@ -27,7 +27,7 @@ export default function App () {
</Box>
{currentTab == 0 && <SearchPage list = {searchResult} onSearch = {setSearchResult}/>}
{currentTab == 1 && <Typography align = "center" variant = "h2">
Item Two
</Typography>}
{currentTab == 1 && <Typography align = "center" variant = "h2">
Favorites
</Typography>}
{currentTab == 2 && <Typography align = "center" variant = "h2"> Item Three </Typography>}
</React.Fragment>
)
...
...
This diff is collapsed.
Click to expand it.
src/Favorites.js
+
14
−
0
View file @
33604124
...
...
@@ -3,4 +3,18 @@
2. SearchPage에서 가수 2~3명의 음악을 검색하고, 좋아요를 클릭하고,
Favorites 페이지를 보았을 때, 여러 가수들의 노래들이 표시되어야 하고,
Favorites에서 좋아요를 다시 클릭하면, 그 음악이 사라져야 합니다.
3. 상태변수 likes는 SearchPage와 Favorites에 공유되어야 한다.
4. 상태변수 likes를 어느 컴포넌트에 두어야 하며, MusicList, SearchPage, Favorites 컴포넌트의 props는 어떠한 형태로 전달되어야 하는가?
*/
import
React
from
'
react
'
;
import
MusicList
from
'
./MusicList
'
;
const
Favorites
=
({
list
,
likes
,
onToggleFavorite
})
=>
{
return
(
<
div
>
<
MusicList
list
=
{
list
}
likes
=
{
likes
}
onToggleFavorite
=
{
onToggleFavorite
}
/
>
<
/div
>
);
};
export
default
Favorites
;
This diff is collapsed.
Click to expand it.
src/MusicList.js
+
9
−
4
View file @
33604124
import
React
from
'
react
'
;
import
SnackMsg
from
'
./SnackMsg
'
;
import
{
Card
,
CardContent
,
CardActions
,
Typography
,
IconButton
}
from
'
@mui/material
'
;
import
{
Favorite
,
FavoriteBorder
}
from
'
@mui/icons-material
'
;
const
styles
=
{
content
:
{},
layout
:
{
...
...
@@ -16,19 +18,22 @@ const styles = {
marginRight
:
'
auto
'
,
},
};
export
default
function
MusicList
({
list
})
{
const
[
likes
,
setLikes
]
=
React
.
useState
({});
export
default
function
MusicList
({
list
,
likes
,
onToggleFavorite
})
{
//여기
//
const [likes, setLikes] = React.useState({});
//SearchPage.js로 옮겨짐
let
[
snackState
,
setSnackState
]
=
React
.
useState
({
open
:
false
,
msg
:
''
})
const
toggleFavorite
=
(
id
,
name
)
=>
()
=>
{
/*
const toggleFavorite = (id, name) => () => {//SearchPage.js로 옮겨짐
setLikes({...likes, [id]: !likes[id]});
setSnackState({...snackState, open: true, msg: `${name} is clicked`})
}
*/
const
handleSnackbarClose
=
(
event
,
reason
)
=>
{
if
(
reason
===
'
clickaway
'
){
return
;
}
setSnackState
({
open
:
false
,
msg
:
''
});
}
return
(
<
div
>
{
list
.
map
(
item
=>
{
...
...
@@ -39,7 +44,7 @@ export default function MusicList ({list}) {
<
Typography
variant
=
"
subtitle2
"
>
{
item
.
colletcionCensoredName
}
<
/Typography
>
<
/CardContent
>
<
CardActions
>
<
IconButton
onClick
=
{
t
oggleFavorite
(
item
.
collectionId
,
item
.
collectionCensoredName
)}
>
<
IconButton
onClick
=
{
onT
oggleFavorite
(
item
.
collectionId
,
item
.
collectionCensoredName
)}
>
{(
likes
[
item
.
collectionId
]
===
true
)
?
<
Favorite
/>
:
<
FavoriteBorder
/>
}
<
/IconButton
>
<
/CardActions
>
...
...
This diff is collapsed.
Click to expand it.
src/SearchPage.js
+
34
−
1
View file @
33604124
import
React
from
'
react
'
;
import
MusicList
from
'
./MusicList.js
'
;
import
Favorites
from
'
./Favorites.js
'
;
//여기
import
{
Button
,
TextField
}
from
'
@mui/material
'
;
export
default
function
SearchPage
({
list
,
onSearch
})
{
const
[
searchWord
,
setSearchWord
]
=
React
.
useState
(
''
);
const
[
likes
,
setLikes
]
=
React
.
useState
({});
//여기
let
[
snackState
,
setSnackState
]
=
React
.
useState
({
open
:
false
,
msg
:
''
});
//여기
const
handleSearch
=
(
event
)
=>
{
event
.
preventDefault
();
...
...
@@ -20,6 +23,34 @@ export default function SearchPage ({list, onSearch}) {
const
handleSearchTextChange
=
(
event
)
=>
{
setSearchWord
(
event
.
target
.
value
);
}
const
toggleFavorite
=
(
id
,
name
)
=>
()
=>
{
setLikes
({...
likes
,
[
id
]:
!
likes
[
id
]});
setSnackState
({...
snackState
,
open
:
true
,
msg
:
`
${
name
}
is clicked`
})
}
/*
let [snackState, setSnackState] = React.useState({open: false, msg:''})
const toggleFavorite = (id, name) => () => {
setLikes({...likes, [id]: !likes[id]});
setSnackState({...snackState, open: true, msg: `${name} is clicked`})
}
*/
/*
const handleToggleFavorite = (id, name) => () => {//여기
setLikes((prevLikes) => {
const updatedLikes = { ...prevLikes };
if (updatedLikes[id]) {
delete updatedLikes[id];
} else {
updatedLikes[id] = true;
}
return updatedLikes;
});
};
*/
return
(
<
React
.
Fragment
>
<
form
style
=
{{
display
:
'
flex
'
,
marginTop
:
20
,
marginBottom
:
15
}}
>
...
...
@@ -28,7 +59,9 @@ export default function SearchPage ({list, onSearch}) {
<
Button
varient
=
"
contained
"
collor
=
"
primary
"
type
=
"
submit
"
onClick
=
{
handleSearch
}
style
=
{{
marginLeft
:
20
}}
>
Search
<
/Button
>
<
/div
>
<
/form
>
<
MusicList
list
=
{
list
}
><
/MusicList
>
<
MusicList
list
=
{
list
}
likes
=
{
likes
}
onToggleFavorite
=
{
toggleFavorite
}
><
/MusicList
>
<
Favorites
list
=
{
list
}
likes
=
{
likes
}
onToggleFavorite
=
{
toggleFavorite
}
><
/Favorites
>
<
/React.Fragment
>
)
//MusicList랑 Favorites 수정함
}
\ No newline at end of file
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