|
|
@ -1,5 +1,5 @@ |
|
|
|
import React, { useEffect, useState, useReducer } from 'react'; |
|
|
|
import React, { useEffect, useState, useReducer } from 'react'; |
|
|
|
import { Box, Typography, IconButton, Button, CircularProgress } from '@material-ui/core'; |
|
|
|
import { Box, Typography, IconButton, CircularProgress } from '@material-ui/core'; |
|
|
|
import PersonIcon from '@material-ui/icons/Person'; |
|
|
|
import PersonIcon from '@material-ui/icons/Person'; |
|
|
|
import * as serverApi from '../../../api'; |
|
|
|
import * as serverApi from '../../../api'; |
|
|
|
import { WindowState } from '../Windows'; |
|
|
|
import { WindowState } from '../Windows'; |
|
|
@ -12,7 +12,6 @@ import { QueryLeafBy, QueryLeafOp } from '../../../lib/query/Query'; |
|
|
|
import { queryArtists, querySongs } from '../../../lib/backend/queries'; |
|
|
|
import { queryArtists, querySongs } from '../../../lib/backend/queries'; |
|
|
|
import { songGetters } from '../../../lib/songGetters'; |
|
|
|
import { songGetters } from '../../../lib/songGetters'; |
|
|
|
import { useParams } from 'react-router'; |
|
|
|
import { useParams } from 'react-router'; |
|
|
|
var _ = require('lodash'); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export type ArtistMetadata = serverApi.ArtistDetails; |
|
|
|
export type ArtistMetadata = serverApi.ArtistDetails; |
|
|
|
export type ArtistMetadataChanges = serverApi.ModifyArtistRequest; |
|
|
|
export type ArtistMetadataChanges = serverApi.ModifyArtistRequest; |
|
|
@ -81,40 +80,40 @@ export function ArtistWindowControlled(props: { |
|
|
|
state: ArtistWindowState, |
|
|
|
state: ArtistWindowState, |
|
|
|
dispatch: (action: any) => void, |
|
|
|
dispatch: (action: any) => void, |
|
|
|
}) { |
|
|
|
}) { |
|
|
|
let metadata = props.state.metadata; |
|
|
|
let { metadata, id: artistId, pendingChanges, songsByArtist } = props.state; |
|
|
|
let pendingChanges = props.state.pendingChanges; |
|
|
|
let { dispatch } = props; |
|
|
|
|
|
|
|
|
|
|
|
// Effect to get the artist's metadata.
|
|
|
|
// Effect to get the artist's metadata.
|
|
|
|
useEffect(() => { |
|
|
|
useEffect(() => { |
|
|
|
getArtistMetadata(props.state.id) |
|
|
|
getArtistMetadata(artistId) |
|
|
|
.then((m: ArtistMetadata) => { |
|
|
|
.then((m: ArtistMetadata) => { |
|
|
|
props.dispatch({ |
|
|
|
dispatch({ |
|
|
|
type: ArtistWindowStateActions.SetMetadata, |
|
|
|
type: ArtistWindowStateActions.SetMetadata, |
|
|
|
value: m |
|
|
|
value: m |
|
|
|
}); |
|
|
|
}); |
|
|
|
}) |
|
|
|
}) |
|
|
|
}, [metadata?.name]); |
|
|
|
}, [artistId, dispatch]); |
|
|
|
|
|
|
|
|
|
|
|
// Effect to get the artist's songs.
|
|
|
|
// Effect to get the artist's songs.
|
|
|
|
useEffect(() => { |
|
|
|
useEffect(() => { |
|
|
|
if (props.state.songsByArtist) { return; } |
|
|
|
if (songsByArtist) { return; } |
|
|
|
|
|
|
|
|
|
|
|
(async () => { |
|
|
|
(async () => { |
|
|
|
const songs = await querySongs({ |
|
|
|
const songs = await querySongs({ |
|
|
|
query: { |
|
|
|
query: { |
|
|
|
a: QueryLeafBy.ArtistId, |
|
|
|
a: QueryLeafBy.ArtistId, |
|
|
|
b: props.state.id, |
|
|
|
b: artistId, |
|
|
|
leafOp: QueryLeafOp.Equals, |
|
|
|
leafOp: QueryLeafOp.Equals, |
|
|
|
}, |
|
|
|
}, |
|
|
|
offset: 0, |
|
|
|
offset: 0, |
|
|
|
limit: -1, |
|
|
|
limit: -1, |
|
|
|
}); |
|
|
|
}); |
|
|
|
props.dispatch({ |
|
|
|
dispatch({ |
|
|
|
type: ArtistWindowStateActions.SetSongs, |
|
|
|
type: ArtistWindowStateActions.SetSongs, |
|
|
|
value: songs, |
|
|
|
value: songs, |
|
|
|
}); |
|
|
|
}); |
|
|
|
})(); |
|
|
|
})(); |
|
|
|
}, [props.state.songsByArtist]); |
|
|
|
}, [songsByArtist, dispatch, artistId]); |
|
|
|
|
|
|
|
|
|
|
|
const [editingName, setEditingName] = useState<string | null>(null); |
|
|
|
const [editingName, setEditingName] = useState<string | null>(null); |
|
|
|
const name = <Typography variant="h4"><EditableText |
|
|
|
const name = <Typography variant="h4"><EditableText |
|
|
@ -137,7 +136,7 @@ export function ArtistWindowControlled(props: { |
|
|
|
const storeLinks = metadata?.storeLinks && metadata?.storeLinks.map((link: string) => { |
|
|
|
const storeLinks = metadata?.storeLinks && metadata?.storeLinks.map((link: string) => { |
|
|
|
const store = whichStore(link); |
|
|
|
const store = whichStore(link); |
|
|
|
return store && <a |
|
|
|
return store && <a |
|
|
|
href={link} target="_blank" |
|
|
|
href={link} target="_blank" rel="noopener noreferrer" |
|
|
|
> |
|
|
|
> |
|
|
|
<IconButton><StoreLinkIcon |
|
|
|
<IconButton><StoreLinkIcon |
|
|
|
whichStore={store} |
|
|
|
whichStore={store} |
|
|
|