Fix tabs bug.

pull/20/head
Sander Vocke 5 years ago
parent 0dc6b889bb
commit ab33cdf527
  1. 13
      client/src/components/appbar/AppBar.tsx
  2. 41
      client/src/components/tables/ResultsTable.tsx
  3. 2
      client/src/components/windows/AlbumWindow.tsx
  4. 2
      client/src/components/windows/ArtistWindow.tsx
  5. 12
      client/src/components/windows/QueryWindow.tsx
  6. 2
      client/src/components/windows/SongWindow.tsx
  7. 2
      client/src/components/windows/TagWindow.tsx

@ -18,7 +18,6 @@ export interface TabProps {
export function Tab(props: any) { export function Tab(props: any) {
const { onClose, label, ...restProps } = props; const { onClose, label, ...restProps } = props;
const [hover, setHover] = useState<boolean>(false);
const labelElem = <Box const labelElem = <Box
display="flex" display="flex"
@ -26,7 +25,7 @@ export function Tab(props: any) {
justifyContent="center" justifyContent="center"
> >
{label} {label}
{hover && <Box ml={1}> <Box ml={1}>
<IconButton <IconButton
size="small" size="small"
color="inherit" color="inherit"
@ -34,12 +33,10 @@ export function Tab(props: any) {
> >
<CloseIcon /> <CloseIcon />
</IconButton> </IconButton>
</Box>} </Box>
</Box>; </Box>;
return <MuiTab return <MuiTab
onMouseEnter={() => setHover(true)}
onMouseLeave={() => setHover(false)}
label={labelElem} label={labelElem}
{...restProps} {...restProps}
/> />
@ -75,9 +72,9 @@ export default function AppBar(props: IProps) {
</Box> </Box>
</MuiAppBar> </MuiAppBar>
<AddTabMenu <AddTabMenu
anchorEl={addMenuAnchorEl} anchorEl={addMenuAnchorEl}
onClose={onCloseAddMenu} onClose={onCloseAddMenu}
onCreateTab={onAddTab} onCreateTab={onAddTab}
/> />
</> </>
} }

@ -6,6 +6,7 @@ import { newWindowReducer, WindowType } from '../windows/Windows';
import PersonIcon from '@material-ui/icons/Person'; import PersonIcon from '@material-ui/icons/Person';
import AlbumIcon from '@material-ui/icons/Album'; import AlbumIcon from '@material-ui/icons/Album';
import AudiotrackIcon from '@material-ui/icons/Audiotrack'; import AudiotrackIcon from '@material-ui/icons/Audiotrack';
import LocalOfferIcon from '@material-ui/icons/LocalOffer';
export interface SongGetters { export interface SongGetters {
getTitle: (song: any) => string, getTitle: (song: any) => string,
@ -15,6 +16,7 @@ export interface SongGetters {
getAlbumNames: (song: any) => string[], getAlbumNames: (song: any) => string[],
getAlbumIds: (song: any) => number[], getAlbumIds: (song: any) => number[],
getTagNames: (song: any) => string[][], // Each tag is represented as a series of strings. getTagNames: (song: any) => string[][], // Each tag is represented as a series of strings.
getTagIds: (song: any) => number[][], // Each tag is represented as a series of ids.
} }
export interface IProps { export interface IProps {
@ -55,19 +57,13 @@ export function SongTable(props: IProps) {
const mainAlbumName = albumNames[0]; const mainAlbumName = albumNames[0];
const mainAlbumId = props.songGetters.getAlbumIds(song)[0]; const mainAlbumId = props.songGetters.getAlbumIds(song)[0];
const songId = props.songGetters.getId(song); const songId = props.songGetters.getId(song);
const tags = props.songGetters.getTagNames(song).map((tag: string[]) => { const tagIds = props.songGetters.getTagIds(song);
return <Box ml={0.5} mr={0.5}>
<Chip size="small" label={stringifyList(tag, undefined, (idx: number, e: string) => {
return (idx === 0) ? e : " / " + e;
})} />
</Box>
});
const onClickArtist = () => { const onClickArtist = () => {
props.mainDispatch({ props.mainDispatch({
type: MainWindowStateActions.AddTab, type: MainWindowStateActions.AddTab,
tabState: { tabState: {
tabLabel: <><PersonIcon/>{mainArtistName}</>, tabLabel: <><PersonIcon />{mainArtistName}</>,
artistId: mainArtistId, artistId: mainArtistId,
metadata: null, metadata: null,
}, },
@ -80,7 +76,7 @@ export function SongTable(props: IProps) {
props.mainDispatch({ props.mainDispatch({
type: MainWindowStateActions.AddTab, type: MainWindowStateActions.AddTab,
tabState: { tabState: {
tabLabel: <><AlbumIcon/>{mainAlbumName}</>, tabLabel: <><AlbumIcon />{mainAlbumName}</>,
albumId: mainAlbumId, albumId: mainAlbumId,
metadata: null, metadata: null,
}, },
@ -93,7 +89,7 @@ export function SongTable(props: IProps) {
props.mainDispatch({ props.mainDispatch({
type: MainWindowStateActions.AddTab, type: MainWindowStateActions.AddTab,
tabState: { tabState: {
tabLabel: <><AudiotrackIcon/>{title}</>, tabLabel: <><AudiotrackIcon />{title}</>,
songId: songId, songId: songId,
metadata: null, metadata: null,
}, },
@ -102,6 +98,31 @@ export function SongTable(props: IProps) {
}) })
} }
const onClickTag = (id: number, name: string) => {
props.mainDispatch({
type: MainWindowStateActions.AddTab,
tabState: {
tabLabel: <><LocalOfferIcon />{name}</>,
tagId: id,
metadata: null,
},
tabReducer: newWindowReducer[WindowType.Tag],
tabType: WindowType.Tag,
})
}
const tags = props.songGetters.getTagNames(song).map((tag: string[], i: number) => {
const fullTag = stringifyList(tag, undefined, (idx: number, e: string) => {
return (idx === 0) ? e : " / " + e;
})
return <Box ml={0.5} mr={0.5}>
<Chip size="small"
label={fullTag}
onClick={() => onClickTag(tagIds[i][tagIds[i].length-1], fullTag)}
/>
</Box>
});
const TextCell = (props: any) => { const TextCell = (props: any) => {
const classes = makeStyles({ const classes = makeStyles({
button: { button: {

@ -81,7 +81,7 @@ export default function AlbumWindow(props: IProps) {
value: m value: m
}); });
}) })
}, []); }, [props.state.metadata?.name]);
return <Box width="100%" justifyContent="center" display="flex" flexWrap="wrap"> return <Box width="100%" justifyContent="center" display="flex" flexWrap="wrap">
<Box <Box

@ -81,7 +81,7 @@ export default function ArtistWindow(props: IProps) {
value: m value: m
}); });
}) })
}, []); }, [props.state.metadata?.name]);
return <Box width="100%" justifyContent="center" display="flex" flexWrap="wrap"> return <Box width="100%" justifyContent="center" display="flex" flexWrap="wrap">
<Box <Box

@ -88,7 +88,17 @@ export default function QueryWindow(props: IProps) {
} }
return song.tags.map((tag: any) => resolveTag(tag)); return song.tags.map((tag: any) => resolveTag(tag));
} },
getTagIds: (song: any) => {
// Recursively resolve the id.
const resolveTag = (tag: any) => {
var r = [tag.tagId];
if (tag.parent) { r.unshift(resolveTag(tag.parent)); }
return r;
}
return song.tags.map((tag: any) => resolveTag(tag));
},
} }
const doQuery = async (_query: QueryElem) => { const doQuery = async (_query: QueryElem) => {

@ -81,7 +81,7 @@ export default function SongWindow(props: IProps) {
value: m value: m
}); });
}) })
}, []); }, [props.state.metadata?.title]);
return <Box width="100%" justifyContent="center" display="flex" flexWrap="wrap"> return <Box width="100%" justifyContent="center" display="flex" flexWrap="wrap">
<Box <Box

@ -81,7 +81,7 @@ export default function TagWindow(props: IProps) {
value: m value: m
}); });
}) })
}, []); }, [props.state.metadata?.name]);
return <Box width="100%" justifyContent="center" display="flex" flexWrap="wrap"> return <Box width="100%" justifyContent="center" display="flex" flexWrap="wrap">
<Box <Box

Loading…
Cancel
Save