|
|
@ -1,17 +1,21 @@ |
|
|
|
import React from 'react'; |
|
|
|
import React from 'react'; |
|
|
|
import { TableContainer, Table, TableHead, TableRow, TableCell, Paper, makeStyles, TableBody, Chip, Box, Button } from '@material-ui/core'; |
|
|
|
import { TableContainer, Table, TableHead, TableRow, TableCell, Paper, makeStyles, TableBody, Chip, Box, Button } from '@material-ui/core'; |
|
|
|
import stringifyList from '../../lib/stringifyList'; |
|
|
|
import stringifyList from '../../lib/stringifyList'; |
|
|
|
|
|
|
|
import { MainWindowStateActions } from '../MainWindow'; |
|
|
|
|
|
|
|
import { newWindowReducer, WindowType } from '../windows/Windows'; |
|
|
|
|
|
|
|
|
|
|
|
export interface SongGetters { |
|
|
|
export interface SongGetters { |
|
|
|
getTitle: (song: any) => string, |
|
|
|
getTitle: (song: any) => string, |
|
|
|
getArtist: (song: any) => string, |
|
|
|
getArtistNames: (song: any) => string[], |
|
|
|
getAlbum: (song: any) => string, |
|
|
|
getArtistIds: (song: any) => number[], |
|
|
|
getTags: (song: any) => string[][], // Each tag is represented as a series of strings.
|
|
|
|
getAlbumNames: (song: any) => string[], |
|
|
|
|
|
|
|
getTagNames: (song: any) => string[][], // Each tag is represented as a series of strings.
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
export interface IProps { |
|
|
|
export interface IProps { |
|
|
|
songs: any[], |
|
|
|
songs: any[], |
|
|
|
songGetters: SongGetters, |
|
|
|
songGetters: SongGetters, |
|
|
|
|
|
|
|
mainDispatch: (action: any) => void, |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
export function SongTable(props: IProps) { |
|
|
|
export function SongTable(props: IProps) { |
|
|
@ -36,9 +40,11 @@ export function SongTable(props: IProps) { |
|
|
|
<TableBody> |
|
|
|
<TableBody> |
|
|
|
{props.songs.map((song: any) => { |
|
|
|
{props.songs.map((song: any) => { |
|
|
|
const title = props.songGetters.getTitle(song); |
|
|
|
const title = props.songGetters.getTitle(song); |
|
|
|
const artist = props.songGetters.getArtist(song); |
|
|
|
// TODO / FIXME: display artists and albums separately!
|
|
|
|
const album = props.songGetters.getAlbum(song); |
|
|
|
const artist = stringifyList(props.songGetters.getArtistNames(song)); |
|
|
|
const tags = props.songGetters.getTags(song).map((tag: string[]) => { |
|
|
|
const mainArtistId = props.songGetters.getArtistIds(song)[0]; |
|
|
|
|
|
|
|
const album = stringifyList(props.songGetters.getAlbumNames(song)); |
|
|
|
|
|
|
|
const tags = props.songGetters.getTagNames(song).map((tag: string[]) => { |
|
|
|
return <Box ml={0.5} mr={0.5}> |
|
|
|
return <Box ml={0.5} mr={0.5}> |
|
|
|
<Chip size="small" label={stringifyList(tag, undefined, (idx: number, e: string) => { |
|
|
|
<Chip size="small" label={stringifyList(tag, undefined, (idx: number, e: string) => { |
|
|
|
return (idx === 0) ? e : " / " + e; |
|
|
|
return (idx === 0) ? e : " / " + e; |
|
|
@ -46,6 +52,20 @@ export function SongTable(props: IProps) { |
|
|
|
</Box> |
|
|
|
</Box> |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const onClickArtist = () => { |
|
|
|
|
|
|
|
console.log("onClick!") |
|
|
|
|
|
|
|
props.mainDispatch({ |
|
|
|
|
|
|
|
type: MainWindowStateActions.AddTab, |
|
|
|
|
|
|
|
tabState: { |
|
|
|
|
|
|
|
artistId: mainArtistId, |
|
|
|
|
|
|
|
metadata: null, |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
tabLabel: "Artist " + mainArtistId, |
|
|
|
|
|
|
|
tabReducer: newWindowReducer[WindowType.Artist], |
|
|
|
|
|
|
|
tabType: WindowType.Artist, |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const TextCell = (props: any) => { |
|
|
|
const TextCell = (props: any) => { |
|
|
|
const classes = makeStyles({ |
|
|
|
const classes = makeStyles({ |
|
|
|
button: { |
|
|
|
button: { |
|
|
@ -56,7 +76,7 @@ export function SongTable(props: IProps) { |
|
|
|
} |
|
|
|
} |
|
|
|
})(); |
|
|
|
})(); |
|
|
|
return <TableCell padding="none" {...props}> |
|
|
|
return <TableCell padding="none" {...props}> |
|
|
|
<Button className={classes.button} fullWidth={true}> |
|
|
|
<Button className={classes.button} fullWidth={true} onClick={props._onClick}> |
|
|
|
<Box |
|
|
|
<Box |
|
|
|
width="100%" |
|
|
|
width="100%" |
|
|
|
display="flex" |
|
|
|
display="flex" |
|
|
@ -71,7 +91,7 @@ export function SongTable(props: IProps) { |
|
|
|
|
|
|
|
|
|
|
|
return <TableRow key={title}> |
|
|
|
return <TableRow key={title}> |
|
|
|
<TextCell align="left">{title}</TextCell> |
|
|
|
<TextCell align="left">{title}</TextCell> |
|
|
|
<TextCell align="left">{artist}</TextCell> |
|
|
|
<TextCell align="left" _onClick={onClickArtist}>{artist}</TextCell> |
|
|
|
<TextCell align="left">{album}</TextCell> |
|
|
|
<TextCell align="left">{album}</TextCell> |
|
|
|
<TableCell padding="none" align="left" width="25%"> |
|
|
|
<TableCell padding="none" align="left" width="25%"> |
|
|
|
<Box display="flex" alignItems="center"> |
|
|
|
<Box display="flex" alignItems="center"> |
|
|
|