Better tab labels. Tab icons.

pull/20/head
Sander Vocke 5 years ago
parent e02c99954a
commit 4c4fe78258
  1. 18
      client/src/components/MainWindow.tsx
  2. 11
      client/src/components/appbar/AddTabMenu.tsx
  3. 6
      client/src/components/tables/ResultsTable.tsx
  4. 3
      client/src/components/windows/ArtistWindow.tsx
  5. 3
      client/src/components/windows/QueryWindow.tsx
  6. 9
      client/src/components/windows/Windows.tsx

@ -18,7 +18,6 @@ const darkTheme = createMuiTheme({
}); });
export interface MainWindowState { export interface MainWindowState {
tabLabels: string[],
tabStates: any[], tabStates: any[],
tabReducers: Reducer<any, any>[], tabReducers: Reducer<any, any>[],
tabTypes: WindowType[], tabTypes: WindowType[],
@ -41,7 +40,6 @@ export function MainWindowReducer(state: MainWindowState, action: any) {
return { return {
...state, ...state,
tabStates: state.tabStates.filter((i: any, idx: number) => idx != action.idx), tabStates: state.tabStates.filter((i: any, idx: number) => idx != action.idx),
tabLabels: state.tabLabels.filter((i: any, idx: number) => idx != action.idx),
tabReducers: state.tabReducers.filter((i: any, idx: number) => idx != action.idx), tabReducers: state.tabReducers.filter((i: any, idx: number) => idx != action.idx),
tabTypes: state.tabTypes.filter((i: any, idx: number) => idx != action.idx), tabTypes: state.tabTypes.filter((i: any, idx: number) => idx != action.idx),
activeTab: state.activeTab >= (newSize - 1) ? (newSize - 1) : state.activeTab, activeTab: state.activeTab >= (newSize - 1) ? (newSize - 1) : state.activeTab,
@ -51,7 +49,6 @@ export function MainWindowReducer(state: MainWindowState, action: any) {
return { return {
...state, ...state,
tabStates: [...state.tabStates, action.tabState], tabStates: [...state.tabStates, action.tabState],
tabLabels: [...state.tabLabels, action.tabLabel],
tabReducers: [...state.tabReducers, action.tabReducer], tabReducers: [...state.tabReducers, action.tabReducer],
tabTypes: [...state.tabTypes, action.tabType], tabTypes: [...state.tabTypes, action.tabType],
} }
@ -71,15 +68,10 @@ export function MainWindowReducer(state: MainWindowState, action: any) {
export default function MainWindow(props: any) { export default function MainWindow(props: any) {
const [state, dispatch] = useReducer(MainWindowReducer, { const [state, dispatch] = useReducer(MainWindowReducer, {
tabLabels: ["Query"],
tabStates: [ tabStates: [
{ newWindowState[WindowType.Query]()
editingQuery: false,
query: null,
resultsForQuery: null,
},
], ],
tabReducers: [QueryWindowReducer], tabReducers: [newWindowReducer[WindowType.Query]],
tabTypes: [WindowType.Query], tabTypes: [WindowType.Query],
activeTab: 0 activeTab: 0
}) })
@ -92,7 +84,6 @@ export default function MainWindow(props: any) {
idx: i idx: i
}); });
} }
console.log("state", state);
switch (state.tabTypes[i]) { switch (state.tabTypes[i]) {
case WindowType.Query: case WindowType.Query:
@ -112,10 +103,12 @@ export default function MainWindow(props: any) {
} }
}); });
console.log("State:", state)
return <ThemeProvider theme={darkTheme}> return <ThemeProvider theme={darkTheme}>
<CssBaseline /> <CssBaseline />
<AppBar <AppBar
tabLabels={state.tabLabels} tabLabels={state.tabStates.map((s: any) => s.tabLabel)}
selectedTab={state.activeTab} selectedTab={state.activeTab}
setSelectedTab={(t: number) => dispatch({ type: MainWindowStateActions.SetActiveTab, value: t })} setSelectedTab={(t: number) => dispatch({ type: MainWindowStateActions.SetActiveTab, value: t })}
onCloseTab={(t: number) => dispatch({ type: MainWindowStateActions.CloseTab, idx: t })} onCloseTab={(t: number) => dispatch({ type: MainWindowStateActions.CloseTab, idx: t })}
@ -123,7 +116,6 @@ export default function MainWindow(props: any) {
dispatch({ dispatch({
type: MainWindowStateActions.AddTab, type: MainWindowStateActions.AddTab,
tabState: newWindowState[w.windowType](), tabState: newWindowState[w.windowType](),
tabLabel: w.title,
tabReducer: newWindowReducer[w.windowType], tabReducer: newWindowReducer[w.windowType],
tabType: w.windowType, tabType: w.windowType,
}) })

@ -3,7 +3,6 @@ import { WindowType } from '../windows/Windows';
import { Menu, MenuItem } from '@material-ui/core'; import { Menu, MenuItem } from '@material-ui/core';
export interface NewTabProps { export interface NewTabProps {
title: string,
windowType: WindowType, windowType: WindowType,
} }
@ -21,17 +20,13 @@ export default function AddTabMenu(props: IProps) {
onClose={props.onClose} onClose={props.onClose}
> >
<MenuItem disabled={true}>New Tab</MenuItem> <MenuItem disabled={true}>New Tab</MenuItem>
{([ <MenuItem
WindowType.Query,
WindowType.Artist
]).map((v: WindowType) => <MenuItem
onClick={() => { onClick={() => {
props.onClose(); props.onClose();
props.onCreateTab({ props.onCreateTab({
title: v, windowType: WindowType.Query,
windowType: v,
}) })
}} }}
>{v}</MenuItem>)} >{WindowType.Query}</MenuItem>
</Menu> </Menu>
} }

@ -3,6 +3,7 @@ import { TableContainer, Table, TableHead, TableRow, TableCell, Paper, makeStyle
import stringifyList from '../../lib/stringifyList'; import stringifyList from '../../lib/stringifyList';
import { MainWindowStateActions } from '../MainWindow'; import { MainWindowStateActions } from '../MainWindow';
import { newWindowReducer, WindowType } from '../windows/Windows'; import { newWindowReducer, WindowType } from '../windows/Windows';
import PersonIcon from '@material-ui/icons/Person';
export interface SongGetters { export interface SongGetters {
getTitle: (song: any) => string, getTitle: (song: any) => string,
@ -41,8 +42,10 @@ export function SongTable(props: IProps) {
{props.songs.map((song: any) => { {props.songs.map((song: any) => {
const title = props.songGetters.getTitle(song); const title = props.songGetters.getTitle(song);
// TODO / FIXME: display artists and albums separately! // TODO / FIXME: display artists and albums separately!
const artist = stringifyList(props.songGetters.getArtistNames(song)); const artistNames = props.songGetters.getArtistNames(song);
const artist = stringifyList(artistNames);
const mainArtistId = props.songGetters.getArtistIds(song)[0]; const mainArtistId = props.songGetters.getArtistIds(song)[0];
const mainArtistName = artistNames[0];
const album = stringifyList(props.songGetters.getAlbumNames(song)); const album = stringifyList(props.songGetters.getAlbumNames(song));
const tags = props.songGetters.getTagNames(song).map((tag: string[]) => { 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}>
@ -57,6 +60,7 @@ export function SongTable(props: IProps) {
props.mainDispatch({ props.mainDispatch({
type: MainWindowStateActions.AddTab, type: MainWindowStateActions.AddTab,
tabState: { tabState: {
tabLabel: <><PersonIcon/>{mainArtistName}</>,
artistId: mainArtistId, artistId: mainArtistId,
metadata: null, metadata: null,
}, },

@ -2,12 +2,13 @@ import React, { useEffect } from 'react';
import { Box, Typography } from '@material-ui/core'; import { Box, Typography } 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';
export interface ArtistMetadata { export interface ArtistMetadata {
name: string, name: string,
} }
export interface ArtistWindowState { export interface ArtistWindowState extends WindowState {
artistId: number, artistId: number,
metadata: ArtistMetadata | null, metadata: ArtistMetadata | null,
} }

@ -7,6 +7,7 @@ import { SongTable } from '../tables/ResultsTable';
import stringifyList from '../../lib/stringifyList'; import stringifyList from '../../lib/stringifyList';
import { getArtists, getSongTitles, getAlbums, getTags } from '../../lib/query/Getters'; import { getArtists, getSongTitles, getAlbums, getTags } from '../../lib/query/Getters';
import { grey } from '@material-ui/core/colors'; import { grey } from '@material-ui/core/colors';
import { WindowState } from './Windows';
var _ = require('lodash'); var _ = require('lodash');
const darkTheme = createMuiTheme({ const darkTheme = createMuiTheme({
@ -23,7 +24,7 @@ export interface ResultsForQuery {
results: any[], results: any[],
}; };
export interface QueryWindowState { export interface QueryWindowState extends WindowState {
editingQuery: boolean, editingQuery: boolean,
query: QueryElem | null, query: QueryElem | null,
resultsForQuery: ResultsForQuery | null, resultsForQuery: ResultsForQuery | null,

@ -1,12 +1,17 @@
import React from 'react';
import { QueryWindowReducer, QueryWindowState } from "./QueryWindow"; import { QueryWindowReducer, QueryWindowState } from "./QueryWindow";
import { ArtistWindowReducer, ArtistWindowState } from "./ArtistWindow"; import { ArtistWindowReducer, ArtistWindowState } from "./ArtistWindow";
import SearchIcon from '@material-ui/icons/Search';
import PersonIcon from '@material-ui/icons/Person';
export enum WindowType { export enum WindowType {
Query = "Query", Query = "Query",
Artist = "Artist", Artist = "Artist",
} }
export type WindowState = QueryWindowState | ArtistWindowState; export interface WindowState {
tabLabel: string,
}
export const newWindowReducer = { export const newWindowReducer = {
[WindowType.Query]: QueryWindowReducer, [WindowType.Query]: QueryWindowReducer,
@ -16,6 +21,7 @@ export const newWindowReducer = {
export const newWindowState = { export const newWindowState = {
[WindowType.Query]: () => { [WindowType.Query]: () => {
return { return {
tabLabel: <><SearchIcon/>Query</>,
editingQuery: false, editingQuery: false,
query: null, query: null,
resultsForQuery: null, resultsForQuery: null,
@ -23,6 +29,7 @@ export const newWindowState = {
}, },
[WindowType.Artist]: () => { [WindowType.Artist]: () => {
return { return {
tabLabel: <><PersonIcon/>Artist</>,
artistId: 1, artistId: 1,
metadata: null, metadata: null,
} }

Loading…
Cancel
Save