Skip to content

Commit ef38366

Browse files
authored
Merge pull request #324 from prgrms-web-devcourse-final-project/feat/image-size
[feat] 이미지 크기를 명시하여 레이아웃 쉬프트 방지
2 parents 42e1cdb + ba84f86 commit ef38366

File tree

3 files changed

+15
-20
lines changed

3 files changed

+15
-20
lines changed

src/App.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { useSheetStore } from './store/sheetStore';
88
import KaKaoRedirection from '@/components/KaKaoRedirection';
99
import { useYotube } from '@/hooks/useYoutube';
1010
import PublicRoute from '@/routes/PublicRoute';
11-
import CardDetailModalTemp from '@/components/modalSheet/CardDetailModalTemp';
11+
1212
import {
1313
Home,
1414
Landing,
@@ -23,6 +23,7 @@ import {
2323
MyPage,
2424
UserPage,
2525
} from '@/pages';
26+
import CardDetailModal from '@/components/modalSheet/CardDetailModal';
2627

2728
function App() {
2829
const { isRequestSendingSheetOpen, isRequestReceivingSheetOpen } = useSheetStore();
@@ -42,19 +43,19 @@ function App() {
4243
{/* PrivateRoute 적용 */}
4344
<Route element={<PrivateRoute />}>
4445
<Route path="/home" element={<Home />}>
45-
<Route path=":id" element={<CardDetailModalTemp />} />
46+
<Route path=":id" element={<CardDetailModal />} />
4647
</Route>
4748
<Route path="/chat" element={<Chat />} />
4849
<Route path="/post" element={<Post />} />
4950
<Route path="/post/:postId/edit" element={<Post />} />
5051
<Route path="/chatroom/:chatRoomId" element={<ChatRoom />} />
5152
<Route path="/mypage" element={<MyPage />}>
52-
<Route path=":id" element={<CardDetailModalTemp />} />
53+
<Route path=":id" element={<CardDetailModal />} />
5354
</Route>
5455
<Route path="/mypage/edit" element={<EditProfile />} />
5556
<Route path="/mypage/blocklist" element={<BlockList />} />
5657
<Route path="/user/:userId" element={<UserPage />}>
57-
<Route path=":id" element={<CardDetailModalTemp />} />
58+
<Route path=":id" element={<CardDetailModal />} />
5859
</Route>
5960
</Route>
6061

src/components/ImageKitImg.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import defaultImage from '@assets/images/default.png';
2+
23
interface ImageKitImgProps {
34
src: string; // Spotify 이미지 URL
45
width: number;
@@ -20,6 +21,8 @@ export default function ImageKitImg({
2021
<img
2122
className={className}
2223
src={`https://ik.imagekit.io/${import.meta.env.VITE_IMAGEKIT_ID}/${imagePath}?tr=w-${width},h-${height}`}
24+
width={width}
25+
height={height}
2326
onError={(e) => {
2427
const target = e.target as HTMLImageElement;
2528
target.onerror = null; // 무한 루프 방지

src/components/modalSheet/CardDetailModalTemp.tsx renamed to src/components/modalSheet/CardDetailModal.tsx

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
import EmotionBadge from '@/components/EmotionBadge';
22
import ChatActionButtons from '@/components/modalSheet/ChatActionButtons';
3-
import defaultImage from '@assets/images/default.png';
43
import { useQuery } from '@tanstack/react-query';
54
import { getEmotionRecordById } from '@/apis/emotionRecord';
65
import { formatDate } from '@/utils/formatDate';
76
import ModalSheetLayoutTemp from '@/layouts/ModalSheetLayoutTemp';
87
import { useParams } from 'react-router';
98
import { Loading } from '@/components/loading';
9+
import ImageKitImg from '@/components/ImageKitImg';
1010

1111
interface CardDetailModalProps {}
1212

13-
function CardDetailModalTemp({}: CardDetailModalProps) {
13+
function CardDetailModal({}: CardDetailModalProps) {
1414
const id = useParams().id!;
1515

1616
const { data: record, isLoading } = useQuery({
@@ -27,7 +27,6 @@ function CardDetailModalTemp({}: CardDetailModalProps) {
2727
<div className="flex flex-col items-center gap-1">
2828
<div className="flex items-center gap-1 caption-r text-gray-60">
2929
<span>{record?.nickName}</span>
30-
{/* <img src={headsetIcon} alt="헤드셋 아이콘" /> */}
3130
</div>
3231
<div className="flex items-center gap-2">
3332
<span className=" font-light text-gray-60 text-[10px]">
@@ -39,15 +38,11 @@ function CardDetailModalTemp({}: CardDetailModalProps) {
3938

4039
<div className="flex flex-col gap-2 max-w-[250px]">
4140
<div className="flex flex-col items-center gap-2">
42-
<img
41+
<ImageKitImg
4342
src={record?.spotifyMusic.albumImage}
44-
alt="앨범 이미지"
45-
onError={(e) => {
46-
const target = e.target as HTMLImageElement;
47-
target.onerror = null; // 무한 루프 방지
48-
target.src = defaultImage; // 기본 이미지로 변경
49-
}}
50-
className="w-[80px] h-[80px] rounded-[8px]"
43+
height={80}
44+
width={80}
45+
className="rounded-lg"
5146
/>
5247
<div className="flex flex-col items-center min-w-0">
5348
<span className="overflow-hidden body-large-b text-ellipsis whitespace-nowrap">
@@ -75,8 +70,4 @@ function CardDetailModalTemp({}: CardDetailModalProps) {
7570
);
7671
}
7772

78-
export default CardDetailModalTemp;
79-
80-
// 사용예시
81-
82-
// <CardDetailModal recordId={selectedRecordId} isChatting={true} />;
73+
export default CardDetailModal;

0 commit comments

Comments
 (0)