From d5e59f9975eccb44cf70b66e3463e0d9f92746f5 Mon Sep 17 00:00:00 2001 From: jeffvli Date: Wed, 1 Dec 2021 18:30:07 -0800 Subject: [PATCH] Improvements to album page - Link to album list - Album artist specified - Genres separated from artists - Mouse wheel horizontal scroll - Add link wrapper to enforce link max width --- src/components/layout/styled.tsx | 4 +- src/components/library/AlbumView.tsx | 184 +++++++++++++++++---------- src/components/shared/styled.ts | 16 ++- 3 files changed, 135 insertions(+), 69 deletions(-) diff --git a/src/components/layout/styled.tsx b/src/components/layout/styled.tsx index 6e1d3bb..1437ca6 100644 --- a/src/components/layout/styled.tsx +++ b/src/components/layout/styled.tsx @@ -242,10 +242,10 @@ export const PageHeaderSubtitleWrapper = styled.span` font-size: 14px; `; -export const PageHeaderSubtitleDataLine = styled.div<{ $top?: boolean }>` +export const PageHeaderSubtitleDataLine = styled.div<{ $top?: boolean; $overflow?: boolean }>` margin-top: ${(props) => (props.$top ? '0px' : '7px')}; white-space: nowrap; - overflow: auto; + overflow: ${(props) => (props.$overflow ? 'visible' : 'auto')}; ::-webkit-scrollbar { height: 4px; diff --git a/src/components/library/AlbumView.tsx b/src/components/library/AlbumView.tsx index 1f694dd..1e4f606 100644 --- a/src/components/library/AlbumView.tsx +++ b/src/components/library/AlbumView.tsx @@ -1,4 +1,4 @@ -import React from 'react'; +import React, { useRef } from 'react'; import _ from 'lodash'; import { nanoid } from 'nanoid/non-secure'; import { clipboard, shell } from 'electron'; @@ -45,7 +45,13 @@ import { getPlayedSongsNotification, isCached, } from '../../shared/utils'; -import { StyledButton, StyledPopover, StyledTagLink } from '../shared/styled'; +import { + LinkWrapper, + StyledButton, + StyledLink, + StyledPopover, + StyledTagLink, +} from '../shared/styled'; import { setActive } from '../../redux/albumSlice'; import { BlurredBackground, @@ -67,6 +73,8 @@ const AlbumView = ({ ...rest }: any) => { const config = useAppSelector((state) => state.config); const history = useHistory(); const queryClient = useQueryClient(); + const artistLineRef = useRef(); + const genreLineRef = useRef(); const { id } = useParams(); const albumId = rest.id ? rest.id : id; @@ -319,8 +327,21 @@ const AlbumView = ({ ...rest }: any) => { showTitleTooltip subtitle={
- - ALBUM • {data.songCount} songs • {formatDuration(data.duration)} + + history.push('/library/album')}>ALBUM{' '} + {data.albumArtist && ( + <> + by{' '} + + history.push(`/library/artist/${data.albumArtistId}`)} + > + {data.albumArtist} + + + + )}{' '} + • {data.songCount} songs, {formatDuration(data.duration)} {data.year && ( <> {' • '} @@ -328,31 +349,79 @@ const AlbumView = ({ ...rest }: any) => { )} - + { + if (!e.shiftKey) { + if (e.deltaY === 0) return; + const position = genreLineRef.current.scrollLeft; + genreLineRef.current.scrollTo({ + top: 0, + left: position + e.deltaY, + behavior: 'smooth', + }); + } + }} + > Added {formatDate(data.created)} - - - {data.artist.map((d: Artist) => { + {data.genre.map((d: Genre, i: number) => { return ( - { - if (!rest.isModal) { - history.push(`/library/artist/${d.id}`); - } else { - dispatch( - addModalPage({ - pageType: 'artist', - id: d.id, - }) - ); - } - }} - onKeyDown={(e: any) => { - if (e.key === ' ' || e.key === 'Enter') { - e.preventDefault(); + <> + {i === 0 && ' • '} + {i > 0 && ', '} + + { + if (!rest.isModal) { + dispatch(setActive({ ...album.active, filter: d.title })); + setTimeout(() => { + history.push(`/library/album?sortType=${d.title}`); + }, 50); + } + }} + onKeyDown={(e: any) => { + if (e.key === ' ' || e.key === 'Enter') { + e.preventDefault(); + if (!rest.isModal) { + dispatch(setActive({ ...album.active, filter: d.title })); + setTimeout(() => { + history.push(`/library/album?sortType=${d.title}`); + }, 50); + } + } + }} + > + {d.title} + + + + ); + })} + + { + if (!e.shiftKey) { + if (e.deltaY === 0) return; + const position = artistLineRef.current.scrollLeft; + artistLineRef.current.scrollTo({ + top: 0, + left: position + e.deltaY, + behavior: 'smooth', + }); + } + }} + > + {data.artist ? ( + data.artist.map((d: Artist) => { + return ( + { if (!rest.isModal) { history.push(`/library/artist/${d.id}`); } else { @@ -363,43 +432,30 @@ const AlbumView = ({ ...rest }: any) => { }) ); } - } - }} - > - {d.title} - - ); - })} - {data.genre.map((d: Genre) => { - return ( - { - if (!rest.isModal) { - dispatch(setActive({ ...album.active, filter: d.title })); - setTimeout(() => { - history.push(`/library/album?sortType=${d.title}`); - }, 50); - } - }} - onKeyDown={(e: any) => { - if (e.key === ' ' || e.key === 'Enter') { - e.preventDefault(); - if (!rest.isModal) { - dispatch(setActive({ ...album.active, filter: d.title })); - setTimeout(() => { - history.push(`/library/album?sortType=${d.title}`); - }, 50); + }} + onKeyDown={(e: any) => { + if (e.key === ' ' || e.key === 'Enter') { + e.preventDefault(); + if (!rest.isModal) { + history.push(`/library/artist/${d.id}`); + } else { + dispatch( + addModalPage({ + pageType: 'artist', + id: d.id, + }) + ); + } } - } - }} - > - {d.title} - - ); - })} + }} + > + {d.title} + + ); + }) + ) : ( + + )}
@@ -445,7 +501,7 @@ const AlbumView = ({ ...rest }: any) => { > ` + display: inline-block; + max-width: ${(props) => props.maxWidth}; + overflow: hidden; + white-space: nowrap; + text-overflow: ellipsis; + vertical-align: bottom; +`; + +export const StyledLink = styled.a<{ underline?: boolean }>` color: ${(props) => props.theme.colors.layout.page.color}; cursor: pointer; - text-decoration: underline; + text-decoration: ${(props) => (props.underline ? 'underline' : undefined)}; + font-weight: bold; &:hover { - color: ${(props) => props.theme.colors.button.link.colorHover}; + color: ${(props) => props.theme.colors.layout.page.color}; } &:focus-visible {