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
TaeWook Kim
react-material
Commits
a5dca052
Commit
a5dca052
authored
1 year ago
by
TaeWook Kim
Browse files
Options
Downloads
Patches
Plain Diff
3
parent
11b1bb92
No related branches found
No related tags found
1 merge request
!1
3
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
src/App.js
+47
-53
47 additions, 53 deletions
src/App.js
src/Favorites.js
+31
-36
31 additions, 36 deletions
src/Favorites.js
src/MusicList.js
+43
-49
43 additions, 49 deletions
src/MusicList.js
src/SearchPage.js
+42
-33
42 additions, 33 deletions
src/SearchPage.js
with
163 additions
and
171 deletions
src/App.js
+
47
−
53
View file @
a5dca052
import
React
from
'
react
'
;
import
React
,
{
useState
}
from
'
react
'
;
import
SearchPage
from
'
./SearchPage
'
;
import
SearchPage
from
'
./SearchPage
'
;
import
Favorites
from
'
./Favorites
'
;
import
Favorites
from
'
./Favorites
'
;
import
{
Box
,
Tabs
,
Tab
,
Typography
,
AppBar
,
CssBaseline
}
from
'
@mui/material
'
;
import
{
Box
,
Tabs
,
Tab
,
Typography
,
AppBar
,
CssBaseline
}
from
'
@mui/material
'
;
const
TABS
=
[
{
label
:
'
Search Music
'
,
component
:
SearchPage
},
{
label
:
'
Favorites
'
,
component
:
Favorites
},
{
label
:
'
More Contents
'
,
component
:
()
=>
<
Typography
align
=
"
center
"
variant
=
"
h2
"
>
Item
Three
<
/Typography> }
,
];
export
default
function
App
()
{
export
default
function
App
()
{
const
[
currentTab
,
setCurrentTab
]
=
React
.
useState
(
0
);
const
[
currentTab
,
setCurrentTab
]
=
useState
(
0
);
const
[
searchResult
,
setSearchResult
]
=
React
.
useState
([]);
const
[
searchResult
,
setSearchResult
]
=
useState
([]);
const
[
likes
,
setLikes
]
=
React
.
useState
({});
const
[
likes
,
setLikes
]
=
useState
({});
const
[
favoriteList
,
setFavoriteList
]
=
React
.
useState
([]);
const
[
favoriteList
,
setFavoriteList
]
=
useState
([]);
const
handleTabChange
=
(
event
,
newValue
)
=>
{
const
handleTabChange
=
(
event
,
newValue
)
=>
{
setCurrentTab
(
newValue
);
setCurrentTab
(
newValue
);
...
@@ -18,48 +24,36 @@ export default function App() {
...
@@ -18,48 +24,36 @@ export default function App() {
};
};
const
handleLikes
=
(
id
)
=>
{
const
handleLikes
=
(
id
)
=>
{
const
updatedLikes
=
{
...
likes
,
[
id
]:
!
likes
[
id
]
};
setLikes
((
prevLikes
)
=>
({
...
prevLikes
,
[
id
]:
!
prevLikes
[
id
]
}));
setLikes
(
updatedLikes
);
};
};
const
removeFromFavoriteList
=
(
id
)
=>
{
const
removeFromFavoriteList
=
(
id
)
=>
{
setFavoriteList
((
prevList
)
=>
prevList
.
filter
((
item
)
=>
item
.
collectionId
!==
id
));
setFavoriteList
((
prevList
)
=>
prevList
.
filter
((
item
)
=>
item
.
collectionId
!==
id
));
};
};
const
TabComponent
=
TABS
[
currentTab
].
component
;
return
(
return
(
<
React
.
Fragment
>
<
React
.
Fragment
>
<
CssBaseline
/>
<
AppBar
position
=
"
fixed
"
>
<
AppBar
position
=
"
fixed
"
>
<
Typography
align
=
"
center
"
variant
=
"
h3
"
color
=
"
inherit
"
>
Tae
Wook
'
s Favorite Music</Typography>
<
Typography
align
=
"
center
"
variant
=
"
h3
"
color
=
"
inherit
"
>
Tae
Wook
'
s Favorite Music</Typography>
</AppBar>
</AppBar>
<div style={{ height: 60, width:
'
100
%
'
}}></div>
<div style={{ height: 60, width:
'
100
%
'
}}></div>
<Box sx={{ borderBottom: 1, borderColor:
'
divider
'
}}>
<Box sx={{ borderBottom: 1, borderColor:
'
divider
'
}}>
<Tabs value={currentTab} onChange={handleTabChange} aria-label="basic tabs" centered>
<Tabs value={currentTab} onChange={handleTabChange} aria-label="basic tabs" centered>
<Tab label="Search Music" value={0} />
{TABS.map((tab, index) => <Tab key={index} label={tab.label} value={index} />)}
<Tab label="Favorites" value={1} />
<Tab label="More Contents" value={2} />
</Tabs>
</Tabs>
</Box>
</Box>
{currentTab === 0 && (
<TabComponent
<SearchPage
list={searchResult}
list={searchResult}
onSearch={setSearchResult}
onSearch={setSearchResult}
favoriteList={favoriteList}
favoriteList={favoriteList}
addToFavoriteList={addToFavoriteList}
addToFavoriteList={addToFavoriteList}
likes={likes}
likes={likes}
handleLikes={handleLikes}
handleLikes={handleLikes}
/>
)}
{currentTab === 1 && (
<Favorites
favoriteList={favoriteList}
addToFavoriteList={addToFavoriteList}
likes={likes}
handleLikes={handleLikes}
removeFromFavoriteList={removeFromFavoriteList}
removeFromFavoriteList={removeFromFavoriteList}
/>
/>
)}
{currentTab === 2 && <Typography align="center" variant="h2"> Item Three</Typography>}
</React.Fragment>
</React.Fragment>
);
);
}
}
This diff is collapsed.
Click to expand it.
src/Favorites.js
+
31
−
36
View file @
a5dca052
...
@@ -3,11 +3,6 @@ import { Card, CardContent, CardActions, IconButton, Typography } from '@mui/mat
...
@@ -3,11 +3,6 @@ import { Card, CardContent, CardActions, IconButton, Typography } from '@mui/mat
import
{
Favorite
,
FavoriteBorder
}
from
'
@mui/icons-material
'
;
import
{
Favorite
,
FavoriteBorder
}
from
'
@mui/icons-material
'
;
const
styles
=
{
const
styles
=
{
content
:
{},
layout
:
{
display
:
'
flex
'
,
justifyContent
:
'
center
'
},
card
:
{
card
:
{
minWidth
:
275
,
minWidth
:
275
,
maxWidth
:
600
,
maxWidth
:
600
,
...
@@ -26,7 +21,7 @@ export default function Favorites({ favoriteList, likes, handleLikes, removeFrom
...
@@ -26,7 +21,7 @@ export default function Favorites({ favoriteList, likes, handleLikes, removeFrom
handleLikes
(
id
);
handleLikes
(
id
);
};
};
const
filteredFavoriteList
=
favoriteList
.
filter
((
item
)
=>
favoriteLikes
[
item
.
collectionId
]
===
true
);
const
filteredFavoriteList
=
favoriteList
.
filter
((
item
)
=>
favoriteLikes
[
item
.
collectionId
]);
return
(
return
(
<
div
>
<
div
>
...
...
This diff is collapsed.
Click to expand it.
src/MusicList.js
+
43
−
49
View file @
a5dca052
import
React
from
'
react
'
;
import
React
from
'
react
'
;
import
{
Card
,
CardContent
,
CardActions
,
IconButton
,
Typography
}
from
'
@mui/material
'
;
import
{
Card
,
CardContent
,
CardActions
,
IconButton
,
Typography
}
from
'
@mui/material
'
;
import
{
Favorite
,
FavoriteBorder
,
Preview
}
from
'
@mui/icons-material
'
;
import
{
Favorite
,
FavoriteBorder
}
from
'
@mui/icons-material
'
;
import
SnackMsg
from
'
./Snackbar
'
;
import
SnackMsg
from
'
./Snackbar
'
;
const
styles
=
{
const
styles
=
{
content
:
{},
layout
:
{
display
:
'
flex
'
,
justifyContent
:
'
center
'
},
card
:
{
card
:
{
minWidth
:
275
,
minWidth
:
275
,
maxWidth
:
600
,
maxWidth
:
600
,
...
@@ -19,11 +14,10 @@ const styles = {
...
@@ -19,11 +14,10 @@ const styles = {
};
};
export
default
function
MusicList
({
list
,
favoriteList
,
addToFavoriteList
,
likes
,
handleLikes
})
{
export
default
function
MusicList
({
list
,
favoriteList
,
addToFavoriteList
,
likes
,
handleLikes
})
{
le
t
[
snackState
,
setSnackState
]
=
React
.
useState
({
open
:
false
,
msg
:
''
});
cons
t
[
snackState
,
setSnackState
]
=
React
.
useState
({
open
:
false
,
msg
:
''
});
const
toggleFavorite
=
(
id
,
name
)
=>
()
=>
{
const
toggleFavorite
=
(
id
,
name
)
=>
()
=>
{
const
updatedLikes
=
{
...
likes
,
[
id
]:
!
likes
[
id
]
};
const
updatedLikes
=
{
...
likes
,
[
id
]:
!
likes
[
id
]
};
handleLikes
(
id
);
handleLikes
(
id
);
setSnackState
({
...
snackState
,
open
:
true
,
msg
:
`
${
name
}
is clicked`
});
setSnackState
({
...
snackState
,
open
:
true
,
msg
:
`
${
name
}
is clicked`
});
...
@@ -55,9 +49,9 @@ export default function MusicList({ list, favoriteList, addToFavoriteList, likes
...
@@ -55,9 +49,9 @@ export default function MusicList({ list, favoriteList, addToFavoriteList, likes
<
/CardContent
>
<
/CardContent
>
<
CardActions
>
<
CardActions
>
<
IconButton
onClick
=
{
toggleFavorite
(
item
.
collectionId
,
item
.
collectionName
)}
>
<
IconButton
onClick
=
{
toggleFavorite
(
item
.
collectionId
,
item
.
collectionName
)}
>
{
likes
[
item
.
collectionId
]
===
true
?
<
Favorite
/>
:
<
FavoriteBorder
/>
}
{
likes
[
item
.
collectionId
]
?
<
Favorite
/>
:
<
FavoriteBorder
/>
}
<
SnackMsg
open
=
{
snackState
.
open
}
message
=
{
snackState
.
msg
}
onClose
=
{
handleSnackbarClose
}
/
>
<
/IconButton
>
<
/IconButton
>
<
SnackMsg
open
=
{
snackState
.
open
}
message
=
{
snackState
.
msg
}
onClose
=
{
handleSnackbarClose
}
/
>
<
/CardActions
>
<
/CardActions
>
<
/Card
>
<
/Card
>
);
);
...
...
This diff is collapsed.
Click to expand it.
src/SearchPage.js
+
42
−
33
View file @
a5dca052
...
@@ -7,35 +7,44 @@ export default function SearchPage({list, onSearch, favoriteList, addToFavoriteL
...
@@ -7,35 +7,44 @@ export default function SearchPage({list, onSearch, favoriteList, addToFavoriteL
const
handleSearch
=
(
event
)
=>
{
const
handleSearch
=
(
event
)
=>
{
event
.
preventDefault
();
event
.
preventDefault
();
console
.
log
(
searchWord
);
setSearchWord
(
''
);
fetch
(
`http://itunes.apple.com/search?term=
${
searchWord
}
&entity=album`
)
fetch
(
`http://itunes.apple.com/search?term=
${
searchWord
}
&entity=album`
)
.
then
(
r
=>
r
.
json
()).
then
(
r
=>
{
.
then
((
response
)
=>
response
.
json
())
console
.
log
(
r
);
.
then
((
data
)
=>
{
onSearch
(
r
.
results
);
console
.
log
(
data
);
onSearch
(
data
.
results
);
setSearchWord
(
''
);
setSearchWord
(
''
);
}).
catch
(
e
=>
console
.
log
(
'
error when search musician
'
));
})
}
.
catch
((
error
)
=>
console
.
error
(
'
Error when searching for musicians
'
,
error
));
};
const
handleSearchTextChange
=
(
event
)
=>
{
const
handleSearchTextChange
=
(
event
)
=>
{
setSearchWord
(
event
.
target
.
value
);
setSearchWord
(
event
.
target
.
value
);
}
}
;
return
(
return
(
<
React
.
Fragment
>
<
React
.
Fragment
>
<
form
style
=
{{
display
:
'
flex
'
,
marginTop
:
20
,
marginBottom
:
15
}}
>
<
form
style
=
{{
display
:
'
flex
'
,
marginTop
:
20
,
marginBottom
:
15
}}
>
<
div
style
=
{{
display
:
'
flex
'
,
marginLeft
:
'
auto
'
,
marginRight
:
'
auto,
'
}}
>
<
div
style
=
{{
display
:
'
flex
'
,
marginLeft
:
'
auto
'
,
marginRight
:
'
auto
'
}}
>
<
TextField
variant
=
'
outlined
'
label
=
"
Music Album Search
"
type
=
'
search
'
style
=
{{
width
:
450
}}
<
TextField
onChange
=
{
handleSearchTextChange
}
value
=
{
searchWord
}
>
variant
=
'
outlined
'
<
/TextField
>
label
=
"
Music Album Search
"
<
Button
variant
=
"
contained
"
color
=
"
primary
"
type
=
'
search
'
type
=
"
submit
"
onClick
=
{
handleSearch
}
style
=
{{
width
:
450
}}
style
=
{{
marginLeft
:
20
}}
>
onChange
=
{
handleSearchTextChange
}
value
=
{
searchWord
}
/
>
<
Button
variant
=
"
contained
"
color
=
"
primary
"
type
=
"
submit
"
onClick
=
{
handleSearch
}
style
=
{{
marginLeft
:
20
}}
>
Search
Search
<
/Button
>
<
/Button
>
<
/div
>
<
/div
>
<
/form
>
<
/form
>
<
MusicList
list
=
{
list
}
favoriteList
=
{
favoriteList
}
addToFavoriteList
=
{
addToFavoriteList
}
likes
=
{
likes
}
handleLikes
=
{
handleLikes
}
><
/MusicList
>
<
MusicList
list
=
{
list
}
favoriteList
=
{
favoriteList
}
addToFavoriteList
=
{
addToFavoriteList
}
likes
=
{
likes
}
handleLikes
=
{
handleLikes
}
/
>
<
/React.Fragment
>
<
/React.Fragment
>
)
)
;
}
}
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