Skip to content

Commit 52e7e89

Browse files
committed
[WRFE-66](style): 이벤트 핸들러 외부화, 조건부 렌더링 개선(3항 연산자 분리)
1 parent 18eca5a commit 52e7e89

File tree

2 files changed

+19
-11
lines changed

2 files changed

+19
-11
lines changed

apps/front/wraffle-webview/app/category/page.tsx

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use client';
22

33
import {useSearchParams} from 'next/navigation';
4-
import {useEffect, useState} from 'react';
4+
import {useEffect, useState, Suspense} from 'react';
55
import {categories} from '@/entities/category';
66
import type {CategoryItem} from '@/entities/category/type';
77
import {Header} from '@/shared/ui';
@@ -73,7 +73,6 @@ const CategoryPage = () => {
7373
const categoryName = searchParams.get('view');
7474

7575
const [selectedCategory, setSelectedCategory] = useState<number | null>(null);
76-
const [isLoading, setIsLoading] = useState(true);
7776

7877
const currentCategory = categoryName
7978
? categories.find(category => category.name === categoryName)
@@ -97,7 +96,6 @@ const CategoryPage = () => {
9796
if (currentCategory) {
9897
setSelectedCategory(0);
9998
}
100-
setTimeout(() => setIsLoading(false), 1000); // 로딩 시뮬레이션
10199
}, [currentCategory]);
102100

103101
const filteredProducts =
@@ -154,11 +152,15 @@ const CategoryPage = () => {
154152
className='grid justify-center gap-[20px]'
155153
style={{gridTemplateColumns: 'repeat(auto-fit, 160px)'}}
156154
>
157-
{isLoading ? (
158-
<Typography size='h5' className='text-gray-500'>
159-
로딩 중...
160-
</Typography>
161-
) : filteredProducts.length > 0 ? (
155+
<Suspense
156+
fallback={
157+
<Typography size='h5' className='text-gray-500'>
158+
로딩 중...
159+
</Typography>
160+
}
161+
></Suspense>
162+
{/*filteredProducts 배열이 비어 있지 않은 경우*/}
163+
{filteredProducts.length > 0 &&
162164
filteredProducts.map(product => (
163165
<RaffleCard
164166
key={product.id}
@@ -169,8 +171,9 @@ const CategoryPage = () => {
169171
isBookmarked={product.isBookmarked}
170172
hashtags={product.hashtags}
171173
/>
172-
))
173-
) : (
174+
))}
175+
{/*filteredProducts 배열이 비어 있는 경우*/}
176+
{filteredProducts.length === 0 && (
174177
<Typography size='h5' className='text-gray-500'>
175178
상품 추가 예정입니다.
176179
</Typography>

apps/front/wraffle-webview/src/features/get-category/ui/CategoryButton.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,15 @@ interface CategoryButtonProps {
1010

1111
const CategoryButton = ({category}: CategoryButtonProps) => {
1212
const router = useRouter();
13+
14+
const goCategory = () => {
15+
router.push(`/category/${category.id}`);
16+
};
17+
1318
return (
1419
<button
1520
className='h-[74px] w-[72px] rounded-full border border-[#F4F4F5] bg-[#FAFAFA] px-2 py-3'
16-
onClick={() => router.push(`/category/${category.id}`)}
21+
onClick={goCategory}
1722
>
1823
<Typography size='p2' className='break-keep text-center'>
1924
{category.name}

0 commit comments

Comments
 (0)