Skip to content

Commit

Permalink
fix: 이미지 로드동안 스켈레톤 유지시키기 (#666)
Browse files Browse the repository at this point in the history
  • Loading branch information
shackstack authored Dec 29, 2023
1 parent cf6eb1b commit 12ef742
Showing 1 changed file with 21 additions and 7 deletions.
28 changes: 21 additions & 7 deletions frontend/src/components/@common/WaterMarkImage/WaterMarkImage.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { useState } from 'react';
import { styled, css } from 'styled-components';
import { BORDER_RADIUS, FONT_SIZE, paintSkeleton } from '~/styles/common';
import { getImgUrl } from '~/utils/image';
Expand All @@ -10,6 +11,8 @@ interface WaterMarkImageProps {
}

function WaterMarkImage({ waterMark, imageUrl, type, sns }: WaterMarkImageProps) {
const [isImageLoading, setIsImageLoading] = useState<boolean>(true);

const onClickWaterMark = (e: React.MouseEvent) => {
e.stopPropagation();

Expand All @@ -18,11 +21,16 @@ function WaterMarkImage({ waterMark, imageUrl, type, sns }: WaterMarkImageProps)
};

return (
<StyledWaterMarkImage type={type}>
<StyledWaterMarkImage type={type} isImageLoading={isImageLoading}>
<picture>
<source type="images/webp" srcSet={getImgUrl(imageUrl, 'webp')} />
<source type="images/jpeg" srcSet={getImgUrl(imageUrl, 'jpeg')} />
<StyledImage src={getImgUrl(imageUrl, 'webp')} alt="음식점" loading="lazy" />
<StyledImage
src={getImgUrl(imageUrl, 'webp')}
alt="음식점"
loading="lazy"
onLoad={() => setIsImageLoading(false)}
/>
</picture>
{waterMark && (
<StyledWaterMark onClick={onClickWaterMark} aria-hidden="true">
Expand All @@ -45,15 +53,21 @@ const styledImgCssVariable = css`
height: 100%;
`;

const StyledWaterMarkImage = styled.div<{ type: 'list' | 'map' }>`
${paintSkeleton}
const StyledWaterMarkImage = styled.div<{ type: 'list' | 'map'; isImageLoading: boolean }>`
${({ isImageLoading }) =>
isImageLoading &&
css`
${paintSkeleton}
background: none;
`}
position: relative;
overflow: hidden;
border-radius: ${BORDER_RADIUS.md};
width: 100%;
min-width: 100%;
border-radius: ${BORDER_RADIUS.md};
${({ type }) => (type === 'list' ? `padding-top: 95%;` : `padding-top: 65%;`)}
scroll-snap-align: start;
Expand All @@ -64,7 +78,7 @@ const StyledImage = styled.img`
${styledImgCssVariable}
`;

const StyledWaterMark = styled.div`
const StyledWaterMark = styled.div.attrs({})`
position: absolute;
top: 1%;
left: 1%;
Expand Down

0 comments on commit 12ef742

Please sign in to comment.