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
759b0f6e
Commit
759b0f6e
authored
1 year ago
by
HyunjinNoh
Browse files
Options
Downloads
Patches
Plain Diff
before excercise
parent
d7d85d91
No related branches found
No related tags found
No related merge requests found
Pipeline
#7879
passed
1 year ago
Stage: deploy
Changes
4
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
src/App.js
+20
-4
20 additions, 4 deletions
src/App.js
src/MusicList.js
+11
-4
11 additions, 4 deletions
src/MusicList.js
src/SearchPage.js
+34
-0
34 additions, 0 deletions
src/SearchPage.js
src/SnackMsg.js
+17
-0
17 additions, 0 deletions
src/SnackMsg.js
with
82 additions
and
8 deletions
src/App.js
+
20
−
4
View file @
759b0f6e
import
React
from
'
react
'
;
import
React
from
'
react
'
;
import
{
Typography
,
AppBar
}
from
'
@mui/material
'
;
import
MusicList
from
'
./MusicList
'
;
import
MusicList
from
'
./MusicList
'
;
import
music_list
from
'
./data
'
;
import
music_list
from
'
./data
'
;
import
{
Box
,
Tabs
,
Tab
,
Typography
,
AppBar
,
CssBaseline
}
from
'
@mui/material
'
;
import
SearchPage
from
'
./SearchPage
'
;
export
default
function
App
()
{
export
default
function
App
()
{
const
[
currentTab
,
setCurrentTab
]
=
React
.
useState
(
0
);
const
[
searchResul
,
setSearchResult
]
=
React
.
useState
([]);
const
handleTabChange
=
(
event
,
newValue
)
=>
{
setCurrentTab
(
newValue
);
}
return
(
return
(
<
React
.
Fragment
>
<
React
.
Fragment
>
<
AppBar
positions
=
"
fixed
"
>
<
AppBar
positions
=
"
fixed
"
>
...
@@ -11,8 +18,17 @@ export default function App () {
...
@@ -11,8 +18,17 @@ export default function App () {
</AppBar>
</AppBar>
<div style = {{height: 60, width:
'
100
%
'
}}></div>
<div style = {{height: 60, width:
'
100
%
'
}}></div>
<MusicList list = {music_list}></MusicList>
<Box sx = {{borderBottom: 1, borderColor:
'
divider
'
}}>
<Tabs value = {currentTab} onChange = {handleTabChange} aria-label = "basic tabs" centered>
<Tab label = "Search Music" value = {0}/>
<Tab label = "Favorites" value = {1}/>
<Tab label = "More Contents" value = {2}/>
</Tabs>
</Box>
{currentTab == 0 && <SearchPage list = {searchResult} onSearch = {setSearchResult}/>}
{currentTab == 1 && <Typography align = "center" variant = "h2"> Item Two </Typography>}
{currentTab == 2 && <Typography align = "center" variant = "h2"> Item Three </Typography>}
</React.Fragment>
</React.Fragment>
)
)
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
src/MusicList.js
+
11
−
4
View file @
759b0f6e
...
@@ -18,14 +18,20 @@ const styles = {
...
@@ -18,14 +18,20 @@ const styles = {
};
};
export
default
function
MusicList
({
list
})
{
export
default
function
MusicList
({
list
})
{
const
[
likes
,
setLikes
]
=
React
.
useState
({});
const
[
likes
,
setLikes
]
=
React
.
useState
({});
let
[
snackState
,
setSnackState
]
=
React
.
useState
({
open
:
false
,
msg
:
''
})
const
toggleFavorite
=
(
id
)
=>
()
=>
{
const
toggleFavorite
=
(
id
)
=>
()
=>
{
setLikes
({...
likes
,
[
id
]:
!
likes
[
id
]});
setLikes
({...
likes
,
[
id
]:
!
likes
[
id
]});
setSnackState
({...
snackState
,
open
:
true
,
msg
:
`
${
id
}
is clicked`
})
}
const
handleSnackbarClose
=
(
event
,
reason
)
=>
{
if
(
reason
===
'
clickaway
'
){
return
;
}
setSnackState
({
open
:
false
,
msg
:
''
});
}
}
return
(
return
(
<
div
>
<
div
>
{
list
.
results
.
map
(
item
=>
{
{
list
.
map
(
item
=>
{
return
(
return
(
<
Card
sx
=
{
styles
.
card
}
key
=
{(
item
.
collectionId
)}
>
<
Card
sx
=
{
styles
.
card
}
key
=
{(
item
.
collectionId
)}
>
<
CardContent
>
<
CardContent
>
...
@@ -33,13 +39,14 @@ export default function MusicList ({list}) {
...
@@ -33,13 +39,14 @@ export default function MusicList ({list}) {
<
Typography
variant
=
"
subtitle2
"
>
{
item
.
colletcionCensoredName
}
<
/Typography
>
<
Typography
variant
=
"
subtitle2
"
>
{
item
.
colletcionCensoredName
}
<
/Typography
>
<
/CardContent
>
<
/CardContent
>
<
CardActions
>
<
CardActions
>
<
IconButton
onClick
=
{
toggleFavorite
(
item
.
collection
Id
)}
>
<
IconButton
onClick
=
{
toggleFavorite
(
item
.
collection
Name
)}
>
{(
likes
[
item
.
collectionId
]
===
true
)
?
<
Favorite
/>
:
<
FavoriteBorder
/>
}
{(
likes
[
item
.
collectionId
]
===
true
)
?
<
Favorite
/>
:
<
FavoriteBorder
/>
}
<
/IconButton
>
<
/IconButton
>
<
/CardActions
>
<
/CardActions
>
<
/Card
>
<
/Card
>
)
)
})}
})}
<
SnackMsg
open
=
{
snackState
.
open
}
message
=
{
snackState
.
msg
}
onClose
=
{
handleSnackbarClose
}
/
>
<
/div
>
<
/div
>
);
);
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
src/SearchPage.js
0 → 100644
+
34
−
0
View file @
759b0f6e
import
React
from
'
react
'
;
import
{
Button
,
TextField
}
from
'
@mui/material
'
;
import
MusicList
from
'
./MusicList
'
;
export
default
function
SearchPage
({
list
,
onSearch
})
{
const
[
searchWord
,
setSearchWord
]
=
React
.
useState
(
''
);
const
handleSearch
=
(
event
)
=>
{
event
.
preventDefault
();
console
.
log
(
searchWord
);
setSearchWord
(
''
);
fetch
(
`http://itunes.apple.com/search?term=
${
searchWord
}
&entity=album`
)
.
then
(
r
=>
r
.
json
()).
then
(
r
=>
{
console
.
log
(
r
);
onSearch
(
r
.
results
);
setSearchWord
(
''
);
}).
catch
(
e
=>
console
.
log
(
'
error when search musician
'
));
}
const
handleSearchTextChange
=
(
event
)
=>
{
setSearchWord
(
event
.
target
.
value
);
}
return
(
<
React
.
Fragment
>
<
form
style
=
{{
display
:
'
flex
'
,
marginTop
:
20
,
marginBottom
:
15
}}
>
<
div
style
=
{{
display
:
'
flex
'
,
marginLeft
:
'
auto
'
,
marginRight
:
'
auto
'
}}
>
<
TextField
varient
=
"
outlined
"
label
=
"
Music Album Search
"
type
=
"
search
"
style
=
{{
width
:
450
}}
onChange
=
{
handleSearchTextChange
}
value
=
{
searchWord
}
><
/TextField
>
<
Button
varient
=
"
contained
"
collor
=
"
primary
"
type
=
"
submit
"
onClick
=
{
handleSearch
}
style
=
{{
marginLeft
:
20
}}
>
Search
<
/Button
>
<
/div
>
<
/form
>
<
MusicList
list
=
{
list
}
><
/MusicList
>
<
/React.Fragment
>
)
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
src/SnackMsg.js
0 → 100644
+
17
−
0
View file @
759b0f6e
import
React
from
'
react
'
;
import
{
Snackbar
}
from
'
@mui/material
'
;
const
SnackMsg
=
(
props
)
=>
{
return
(
<
Snackbar
open
=
{
props
.
open
}
anchorOrigin
=
{{
vertical
:
'
Bottom
'
,
horizontal
:
'
right
'
}}
autoHideDuration
=
{
3000
}
onClose
=
{
props
.
onClose
}
message
=
{
props
.
message
}
>
<
/Snackbar
>
);
}
export
default
SnackMsg
;
\ 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