From e02c99954a85038e364a96a15ff1bb9030548cff Mon Sep 17 00:00:00 2001 From: Sander Vocke Date: Sun, 20 Sep 2020 23:07:18 +0200 Subject: [PATCH] Clicking on artist in results now opens its tab. --- client/src/components/MainWindow.tsx | 3 ++ client/src/components/tables/ResultsTable.tsx | 36 ++++++++++++++----- .../src/components/windows/ArtistWindow.tsx | 15 ++++++-- client/src/components/windows/QueryWindow.tsx | 11 +++--- 4 files changed, 50 insertions(+), 15 deletions(-) diff --git a/client/src/components/MainWindow.tsx b/client/src/components/MainWindow.tsx index 052a319..8983e3f 100644 --- a/client/src/components/MainWindow.tsx +++ b/client/src/components/MainWindow.tsx @@ -47,6 +47,7 @@ export function MainWindowReducer(state: MainWindowState, action: any) { activeTab: state.activeTab >= (newSize - 1) ? (newSize - 1) : state.activeTab, } case MainWindowStateActions.AddTab: + console.log("Add tab: ", action) return { ...state, tabStates: [...state.tabStates, action.tabState], @@ -98,11 +99,13 @@ export default function MainWindow(props: any) { return case WindowType.Artist: return default: throw new Error("Unimplemented window type"); diff --git a/client/src/components/tables/ResultsTable.tsx b/client/src/components/tables/ResultsTable.tsx index 3c6fb5e..81d8ea6 100644 --- a/client/src/components/tables/ResultsTable.tsx +++ b/client/src/components/tables/ResultsTable.tsx @@ -1,17 +1,21 @@ import React from 'react'; import { TableContainer, Table, TableHead, TableRow, TableCell, Paper, makeStyles, TableBody, Chip, Box, Button } from '@material-ui/core'; import stringifyList from '../../lib/stringifyList'; +import { MainWindowStateActions } from '../MainWindow'; +import { newWindowReducer, WindowType } from '../windows/Windows'; export interface SongGetters { getTitle: (song: any) => string, - getArtist: (song: any) => string, - getAlbum: (song: any) => string, - getTags: (song: any) => string[][], // Each tag is represented as a series of strings. + getArtistNames: (song: any) => string[], + getArtistIds: (song: any) => number[], + getAlbumNames: (song: any) => string[], + getTagNames: (song: any) => string[][], // Each tag is represented as a series of strings. } export interface IProps { songs: any[], songGetters: SongGetters, + mainDispatch: (action: any) => void, } export function SongTable(props: IProps) { @@ -36,9 +40,11 @@ export function SongTable(props: IProps) { {props.songs.map((song: any) => { const title = props.songGetters.getTitle(song); - const artist = props.songGetters.getArtist(song); - const album = props.songGetters.getAlbum(song); - const tags = props.songGetters.getTags(song).map((tag: string[]) => { + // TODO / FIXME: display artists and albums separately! + const artist = stringifyList(props.songGetters.getArtistNames(song)); + const mainArtistId = props.songGetters.getArtistIds(song)[0]; + const album = stringifyList(props.songGetters.getAlbumNames(song)); + const tags = props.songGetters.getTagNames(song).map((tag: string[]) => { return { return (idx === 0) ? e : " / " + e; @@ -46,6 +52,20 @@ export function SongTable(props: IProps) { }); + 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 classes = makeStyles({ button: { @@ -56,7 +76,7 @@ export function SongTable(props: IProps) { } })(); return -