|
|
|
@ -21,8 +21,8 @@ function App() { |
|
|
|
|
name: "" |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
const fetchSongs = () => { |
|
|
|
|
fetch(serverApi.ListSongsEndpoint) |
|
|
|
|
const updateSongs = () => { |
|
|
|
|
return fetch(serverApi.ListSongsEndpoint) |
|
|
|
|
.then((response: any) => response.json()) |
|
|
|
|
.then((result: serverApi.ListSongsResponse) => { |
|
|
|
|
setSongs(result.map((item: serverApi.ListSongsResponseItem) => { |
|
|
|
@ -35,18 +35,29 @@ function App() { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const fetchArtists = () => { |
|
|
|
|
fetch(serverApi.ListArtistsEndpoint) |
|
|
|
|
.then((response: any) => response.json()) |
|
|
|
|
.then((result: serverApi.ListArtistsResponse) => { |
|
|
|
|
setArtists(result.map((item: serverApi.ListArtistsResponseItem) => { |
|
|
|
|
return { |
|
|
|
|
name: item.name, |
|
|
|
|
}; |
|
|
|
|
})); |
|
|
|
|
return fetch(serverApi.ListArtistsEndpoint) |
|
|
|
|
.then((response: any) => response.json()) |
|
|
|
|
.then((result: serverApi.ListArtistsResponse) => { |
|
|
|
|
return result.map((item: serverApi.ListArtistsResponseItem) => { |
|
|
|
|
return { |
|
|
|
|
name: item.name, |
|
|
|
|
id: item.id, |
|
|
|
|
}; |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const updateArtists = () => { |
|
|
|
|
return fetchArtists() |
|
|
|
|
.then((artists: any[]) => { |
|
|
|
|
setArtists(artists); |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const createSong = (p:SongProperties) => { |
|
|
|
|
if(!p.artistId) { |
|
|
|
|
throw "Undefined artist ID for song to be created."; |
|
|
|
|
} |
|
|
|
|
const request:serverApi.CreateSongRequest = { |
|
|
|
|
title: p.title, |
|
|
|
|
artistId: p.artistId, |
|
|
|
@ -56,7 +67,7 @@ function App() { |
|
|
|
|
headers: {'Content-Type': 'application/json'}, |
|
|
|
|
body: JSON.stringify(request) |
|
|
|
|
}; |
|
|
|
|
fetch(serverApi.CreateSongEndpoint, requestOpts) |
|
|
|
|
return fetch(serverApi.CreateSongEndpoint, requestOpts) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const createArtist = (p:ArtistProperties) => { |
|
|
|
@ -68,7 +79,7 @@ function App() { |
|
|
|
|
headers: {'Content-Type': 'application/json'}, |
|
|
|
|
body: JSON.stringify(request) |
|
|
|
|
}; |
|
|
|
|
fetch(serverApi.CreateArtistEndpoint, requestOpts) |
|
|
|
|
return fetch(serverApi.CreateArtistEndpoint, requestOpts) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const openCreateSongDialog = () => { |
|
|
|
@ -80,9 +91,9 @@ function App() { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const onSubmitCreateSongDialog = () => { |
|
|
|
|
createSong(songDialogProperties); |
|
|
|
|
fetchSongs(); |
|
|
|
|
setEditSongDialogOpen(false); |
|
|
|
|
createSong(songDialogProperties) |
|
|
|
|
.then(updateSongs) |
|
|
|
|
.then(() => { setEditSongDialogOpen(false); }) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const openCreateArtistDialog = () => { |
|
|
|
@ -93,13 +104,13 @@ function App() { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const onSubmitCreateArtistDialog = () => { |
|
|
|
|
createArtist(artistDialogProperties); |
|
|
|
|
fetchArtists(); |
|
|
|
|
setEditArtistDialogOpen(false); |
|
|
|
|
createArtist(artistDialogProperties) |
|
|
|
|
.then(updateArtists) |
|
|
|
|
.then(() => { setEditArtistDialogOpen(false); }) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
useEffect(fetchSongs, []); |
|
|
|
|
useEffect(fetchArtists, []); |
|
|
|
|
useEffect(() => { updateSongs(); }, []); |
|
|
|
|
useEffect(() => { updateArtists(); }, []); |
|
|
|
|
|
|
|
|
|
return ( |
|
|
|
|
<div style={{ maxWidth: '100%' }}> |
|
|
|
@ -119,6 +130,7 @@ function App() { |
|
|
|
|
onChangeSongProperties={(props:SongProperties) => setSongDialogProperties(props)} |
|
|
|
|
songProperties={songDialogProperties} |
|
|
|
|
onSubmit={onSubmitCreateSongDialog} |
|
|
|
|
artists={artists} |
|
|
|
|
/> |
|
|
|
|
<EditArtistDialog |
|
|
|
|
dialogOpen={editArtistDialogOpen} |
|
|
|
|