Browse Source

fix props, lazyload on scrolling menu

master
jeffvli 3 years ago
parent
commit
35b12a24f4
  1. 16
      src/components/card/Card.tsx
  2. 36
      src/components/card/styled.tsx
  3. 3
      src/components/scrollingmenu/ScrollingMenu.tsx
  4. 14
      src/components/shared/cacheImage.ts

16
src/components/card/Card.tsx

@ -76,8 +76,8 @@ const Card = ({
}; };
return ( return (
<StyledPanel tabIndex={0} bordered shaded cardSize={size}> <StyledPanel tabIndex={0} bordered shaded cardsize={size} {...rest}>
<Overlay cardSize={size}> <Overlay cardsize={size}>
{lazyLoad ? ( {lazyLoad ? (
<LazyCardImg <LazyCardImg
src={ src={
@ -94,7 +94,7 @@ const Card = ({
alt="img" alt="img"
effect="opacity" effect="opacity"
onClick={handleClick} onClick={handleClick}
cardSize={size} cardsize={size}
afterLoad={() => { afterLoad={() => {
cacheImage( cacheImage(
`${rest.details.cacheType}_${rest.details.id}.jpg`, `${rest.details.cacheType}_${rest.details.id}.jpg`,
@ -108,7 +108,7 @@ const Card = ({
src={rest.coverArt} src={rest.coverArt}
alt="img" alt="img"
onClick={handleClick} onClick={handleClick}
cardSize={size} cardsize={size}
/> />
)} )}
@ -121,13 +121,13 @@ const Card = ({
/> />
)} )}
</Overlay> </Overlay>
<InfoPanel cardSize={size}> <InfoPanel cardsize={size}>
<InfoSpan> <InfoSpan>
<CardTitleButton <CardTitleButton
appearance="link" appearance="link"
size="sm" size="sm"
onClick={handleClick} onClick={handleClick}
cardSize={size} cardsize={size}
> >
{rest.title} {rest.title}
</CardTitleButton> </CardTitleButton>
@ -138,12 +138,12 @@ const Card = ({
appearance="link" appearance="link"
size="xs" size="xs"
onClick={handleSubClick} onClick={handleSubClick}
cardSize={size} cardsize={size}
> >
{rest.subtitle} {rest.subtitle}
</CardSubtitleButton> </CardSubtitleButton>
) : ( ) : (
<CardSubtitle cardSize={size}>{rest.subtitle}</CardSubtitle> <CardSubtitle cardsize={size}>{rest.subtitle}</CardSubtitle>
)} )}
</InfoSpan> </InfoSpan>
</InfoPanel> </InfoPanel>

36
src/components/card/styled.tsx

@ -3,32 +3,32 @@ import styled from 'styled-components';
import { LazyLoadImage } from 'react-lazy-load-image-component'; import { LazyLoadImage } from 'react-lazy-load-image-component';
interface Card { interface Card {
cardSize: number; cardsize: number;
} }
/* const getCardSize = (props: any) => { /* const getcardsize = (props: any) => {
return props.cardSize === 'xs' return props.cardsize === 'xs'
? props.theme.cardXs ? props.theme.cardXs
: props.cardSize === 'sm' : props.cardsize === 'sm'
? props.theme.cardSm ? props.theme.cardSm
: props.cardSize === 'md' : props.cardsize === 'md'
? props.theme.cardMd ? props.theme.cardMd
: props.cardSize === 'lg' : props.cardsize === 'lg'
? props.theme.cardLg ? props.theme.cardLg
: props.theme.cardSm; : props.theme.cardSm;
}; */ }; */
export const StyledPanel = styled(Panel)<Card>` export const StyledPanel = styled(Panel)<Card>`
text-align: center; text-align: center;
width: ${(props) => props.cardSize + 2}; width: ${(props) => props.cardsize + 2};
height: ${(props) => props.cardSize + 55}; height: ${(props) => props.cardsize + 55};
&:hover { &:hover {
border: 1px solid ${(props) => props.theme.main}; border: 1px solid ${(props) => props.theme.main};
} }
`; `;
export const InfoPanel = styled(Panel)<Card>` export const InfoPanel = styled(Panel)<Card>`
width: ${(props) => props.cardSize}; width: ${(props) => props.cardsize};
`; `;
export const InfoSpan = styled.div` export const InfoSpan = styled.div`
@ -45,13 +45,13 @@ export const CardTitleButton = styled(CardButton)`
padding-top: 5px; padding-top: 5px;
padding-bottom: 2px; padding-bottom: 2px;
color: ${(props) => props.theme.titleText}; color: ${(props) => props.theme.titleText};
width: ${(props) => props.cardSize}; width: ${(props) => props.cardsize};
`; `;
export const CardSubtitleButton = styled(CardButton)` export const CardSubtitleButton = styled(CardButton)`
padding-bottom: 5px; padding-bottom: 5px;
color: ${(props) => props.theme.subtitleText}; color: ${(props) => props.theme.subtitleText};
width: ${(props) => props.cardSize}; width: ${(props) => props.cardsize};
`; `;
export const CardSubtitle = styled.div<Card>` export const CardSubtitle = styled.div<Card>`
@ -60,24 +60,24 @@ export const CardSubtitle = styled.div<Card>`
white-space: nowrap; white-space: nowrap;
overflow: hidden; overflow: hidden;
text-overflow: ellipsis; text-overflow: ellipsis;
width: ${(props) => props.cardSize}; width: ${(props) => props.cardsize};
`; `;
export const CardImg = styled.img<Card>` export const CardImg = styled.img<Card>`
height: ${(props) => props.cardSize}; height: ${(props) => props.cardsize};
width: ${(props) => props.cardSize}; width: ${(props) => props.cardsize};
`; `;
export const LazyCardImg = styled(LazyLoadImage)<Card>` export const LazyCardImg = styled(LazyLoadImage)<Card>`
height: ${(props) => props.cardSize}; height: ${(props) => props.cardsize};
width: ${(props) => props.cardSize}; width: ${(props) => props.cardsize};
`; `;
export const Overlay = styled.div<Card>` export const Overlay = styled.div<Card>`
background-color: #1a1d24; background-color: #1a1d24;
position: relative; position: relative;
height: ${(props) => props.cardSize}; height: ${(props) => props.cardsize};
width: ${(props) => props.cardSize}; width: ${(props) => props.cardsize};
&:hover { &:hover {
background-color: #000; background-color: #000;
opacity: 0.5; opacity: 0.5;

3
src/components/scrollingmenu/ScrollingMenu.tsx

@ -64,6 +64,9 @@ const ScrollingMenu = ({
playClick={{ type: 'album', id: item.id }} playClick={{ type: 'album', id: item.id }}
hasHoverButtons hasHoverButtons
size={cardSize} size={cardSize}
details={{ cacheType: 'album', ...item }}
lazyLoad
style={{ margin: '0px 5px 0px 5px' }}
/> />
))} ))}
</ScrollMenu> </ScrollMenu>

14
src/components/shared/cacheImage.ts

@ -55,10 +55,16 @@ const cacheImage = (fileName: string, url: string, cacheType: string) => {
// Check if an existing cached image exists // Check if an existing cached image exists
if (!fs.existsSync(cachedImgPath) && !fs.existsSync(tempImgPath)) { if (!fs.existsSync(cachedImgPath) && !fs.existsSync(tempImgPath)) {
if (!options.url.includes('placeholder')) { if (!options.url.includes('placeholder')) {
download try {
.image(options) download
.then(() => fs.renameSync(tempImgPath, cachedImgPath)) .image(options)
.catch((err: any) => console.log(err)); .then(() => fs.renameSync(tempImgPath, cachedImgPath))
.catch((err: any) => console.log(err));
} finally {
if (fs.existsSync(tempImgPath)) {
fs.rmSync(tempImgPath);
}
}
} }
} }
}; };

Loading…
Cancel
Save