Skip to content

Commit 78a84e6

Browse files
committed
refactor: preload image
1 parent 1ff5ca1 commit 78a84e6

File tree

3 files changed

+41
-15
lines changed

3 files changed

+41
-15
lines changed

next.config.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,27 +11,27 @@ const nextConfig = {
1111
styledComponents: true,
1212
},
1313

14-
// Uncoment to add domain whitelist
15-
// images: {
16-
// domains: [
17-
// 'res.cloudinary.com',
18-
// ],
19-
// },
20-
2114
// rewrites: {
2215
// beforeFiles: {
2316
// source: '/api/:path*',
2417
// destination: 'https://main.dmb5wiywaiaet.amplifyapp.com/api/:path*',
2518
// },
2619
// },
2720

21+
// domain whitelist
2822
images: {
2923
remotePatterns: [
3024
{
3125
protocol: 'https',
3226
hostname: 'avatars.githubusercontent.com',
3327
},
3428
],
29+
remotePatterns: [
30+
{
31+
protocol: 'https',
32+
hostname: 'roadmaker-images.s3.amazonaws.com',
33+
},
34+
],
3535
},
3636

3737
webpack(config) {
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
'use client';
2+
import { AspectRatio, Image } from '@mantine/core';
3+
4+
const FallbackImage = () => {
5+
return (
6+
<AspectRatio ratio={1920 / 1080}>
7+
<Image
8+
radius={'md'}
9+
src={null}
10+
alt={`이미지 없음`}
11+
fallbackSrc='https://placehold.co/600x400?text=No Image'
12+
/>
13+
</AspectRatio>
14+
);
15+
};
16+
export default FallbackImage;

src/components/shared/ItemCard.tsx

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
'use client';
2-
import { AspectRatio, Card, Image, Text, Title } from '@mantine/core';
2+
import { AspectRatio, Card, Text, Title } from '@mantine/core';
33
import styled from 'styled-components';
44

55
import { Post } from '@/types/post';
6+
import Image from 'next/image';
7+
import FallbackImage from './FallbackImage';
68

79
const ItemCard = ({
810
article,
@@ -23,13 +25,18 @@ const ItemCard = ({
2325
className='card'
2426
>
2527
<AspectRatio ratio={1920 / 1080}>
26-
<Image
27-
radius={'md'}
28-
src={article?.thumbnailUrl || null}
29-
alt={`${article?.thumbnailUrl} 이미지`}
30-
fallbackSrc='https://placehold.co/600x400?text=No Image'
31-
fetchPriority={'high'}
32-
/>
28+
{!article?.thumbnailUrl ? (
29+
<FallbackImage />
30+
) : (
31+
<Image
32+
src={`${article?.thumbnailUrl}`}
33+
alt={`${article?.thumbnailUrl} 이미지`}
34+
priority={true}
35+
width={100}
36+
height={100}
37+
className='item-card-img'
38+
/>
39+
)}
3340
</AspectRatio>
3441
<Text c='dimmed' size='xs' tt='uppercase' fw={700} mt='md'>
3542
{`${article?.createdAt}`}
@@ -89,4 +96,7 @@ export const Wrap = styled.div`
8996
.card-img {
9097
width: 6rem;
9198
}
99+
.item-card-img {
100+
border-radius: var(--mantine-radius-md);
101+
}
92102
`;

0 commit comments

Comments
 (0)