From 7c61a57149153d0785d4a62b2fd352dc897ff5ea Mon Sep 17 00:00:00 2001 From: jeffvli Date: Mon, 11 Oct 2021 05:02:11 -0700 Subject: [PATCH] Set header images to cache --- src/components/layout/GenericPageHeader.tsx | 14 +++- src/components/library/AlbumView.tsx | 14 +++- src/components/library/ArtistView.tsx | 81 ++++++++++++++------- 3 files changed, 80 insertions(+), 29 deletions(-) diff --git a/src/components/layout/GenericPageHeader.tsx b/src/components/layout/GenericPageHeader.tsx index 0968b23..bab6a3c 100644 --- a/src/components/layout/GenericPageHeader.tsx +++ b/src/components/layout/GenericPageHeader.tsx @@ -1,9 +1,11 @@ import React from 'react'; +import { LazyLoadImage } from 'react-lazy-load-image-component'; import { useHistory } from 'react-router-dom'; import { Icon, Input, InputGroup } from 'rsuite'; import ViewTypeButtons from '../viewtypes/ViewTypeButtons'; import { StyledInputGroup } from '../shared/styled'; import { CoverArtWrapper, PageHeaderTitle } from './styled'; +import cacheImage from '../shared/cacheImage'; const GenericPageHeader = ({ image, @@ -20,6 +22,7 @@ const GenericPageHeader = ({ handleListClick, handleGridClick, viewTypeSetting, + cacheImages, }: any) => { const history = useHistory(); @@ -27,11 +30,20 @@ const GenericPageHeader = ({ <> {image && ( - header-img { + if (cacheImages.enabled) { + cacheImage( + `${cacheImages.cacheType}_${cacheImages.id}.jpg`, + image.replace(/size=\d+/, 'size=500') + ); + } + }} /> )} diff --git a/src/components/library/AlbumView.tsx b/src/components/library/AlbumView.tsx index 72799fc..016ddbd 100644 --- a/src/components/library/AlbumView.tsx +++ b/src/components/library/AlbumView.tsx @@ -1,4 +1,5 @@ import React, { useState } from 'react'; +import path from 'path'; import _ from 'lodash'; import settings from 'electron-settings'; import { ButtonToolbar, Tag } from 'rsuite'; @@ -34,6 +35,7 @@ import { TagLink } from './styled'; import { setStatus } from '../../redux/playerSlice'; import { addModalPage } from '../../redux/miscSlice'; import { notifyToast } from '../shared/toast'; +import { getImageCachePath, isCached } from '../../shared/utils'; interface AlbumParams { id: string; @@ -41,6 +43,7 @@ interface AlbumParams { const AlbumView = ({ ...rest }: any) => { const dispatch = useAppDispatch(); + const [cachePath] = useState(path.join(getImageCachePath(), '/')); const multiSelect = useAppSelector((state) => state.multiSelect); const playQueue = useAppSelector((state) => state.playQueue); const history = useHistory(); @@ -159,7 +162,16 @@ const AlbumView = ({ ...rest }: any) => { diff --git a/src/components/library/ArtistView.tsx b/src/components/library/ArtistView.tsx index 59fef48..e149438 100644 --- a/src/components/library/ArtistView.tsx +++ b/src/components/library/ArtistView.tsx @@ -1,6 +1,7 @@ /* eslint-disable import/no-cycle */ import React, { useState } from 'react'; import _ from 'lodash'; +import path from 'path'; import settings from 'electron-settings'; import { ButtonToolbar, Tag, Whisper, Button, Popover, TagGroup } from 'rsuite'; import { useQuery, useQueryClient } from 'react-query'; @@ -30,6 +31,7 @@ import { TagLink } from './styled'; import { addModalPage } from '../../redux/miscSlice'; import { appendPlayQueue, setPlayQueue } from '../../redux/playQueueSlice'; import { notifyToast } from '../shared/toast'; +import { getImageCachePath, isCached } from '../../shared/utils'; interface ArtistParams { id: string; @@ -39,6 +41,7 @@ const ArtistView = ({ ...rest }: any) => { const dispatch = useAppDispatch(); const queryClient = useQueryClient(); const history = useHistory(); + const [cachePath] = useState(path.join(getImageCachePath(), '/')); const [viewType, setViewType] = useState(settings.getSync('albumViewType') || 'list'); const { id } = useParams(); const artistId = rest.id ? rest.id : id; @@ -146,23 +149,36 @@ const ArtistView = ({ ...rest }: any) => { hideDivider header={ ]*>/, '') .replace('Read more on Last.fm', '')} placement="bottomStart" > - {artistInfo.biography + {artistInfo?.biography ?.replace(/<[^>]*>/, '') .replace('Read more on Last.fm', '') - ?.trim() !== '' - ? `${artistInfo.biography + ?.trim() + ? `${artistInfo?.biography ?.replace(/<[^>]*>/, '') .replace('Read more on Last.fm', '')}` : 'No artist biography found'} @@ -188,28 +204,39 @@ const ArtistView = ({ ...rest }: any) => { enterable speaker={ - - {artistInfo.similarArtist?.map((artist: any) => ( - - { - if (!rest.isModal) { - history.push(`/library/artist/${artist.id}`); - } else { - dispatch( - addModalPage({ - pageType: 'artist', - id: artist.id, - }) - ); - } - }} - > - {artist.name} - - - ))} - +
+
Related artists
+ + {artistInfo?.similarArtist?.map((artist: any) => ( + + { + if (!rest.isModal) { + history.push(`/library/artist/${artist.id}`); + } else { + dispatch( + addModalPage({ + pageType: 'artist', + id: artist.id, + }) + ); + } + }} + > + {artist.name} + + + ))} + +
+
+ shell.openExternal(artistInfo?.lastFmUrl)} + > + View on Last.FM +
} >