Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 11 additions & 45 deletions src/app/products/[productId]/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -244,25 +244,19 @@ export default function ProductDetailScreen({
showToastRef.current = showToast;
}, [showToast]);

const displaySellerBio = productData?.seller?.bio ?? "정보없음";
const sellerBio = auctionDetail?.seller?.bio ?? productData?.seller?.bio;
const displaySellerBio =
sellerBio == null || sellerBio.trim() === "" ? "정보없음" : sellerBio;
Comment on lines +248 to +249

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

삼항 연산자와 trim()을 사용한 빈 문자열 검사 로직은 ?. 연산자와 || 연산자를 활용하여 훨씬 간결하고 가독성 좋게 작성할 수 있습니다. sellerBio?.trim() || "정보없음"과 같이 작성하면 동일한 동작을 하면서도 코드가 명확해집니다.

Suggested change
const displaySellerBio =
sellerBio == null || sellerBio.trim() === "" ? "정보없음" : sellerBio;
const displaySellerBio = sellerBio?.trim() || "정보없음";
References
  1. 가독성을 고려하여 코드를 작성해야 합니다. (link)

const sellerRating =
auctionDetail?.seller?.rating ?? productData?.seller?.rating;

const displaySellerRating =
productData?.seller?.rating == null
? "정보없음"
: productData.seller.rating.toFixed(1);
sellerRating == null ? "정보없음" : sellerRating.toFixed(1);
const displaySellerWarning =
productData?.seller?.warningCount == null
? "정보없음"
: `${productData.seller.warningCount}회`;
const displaySellerAddress = displayLocation;
const sellerRecentSales = productData?.seller?.recentSales ?? [];

function formatSellerRecentSalePrice(price?: number | null) {
if (price == null) {
return "정보없음";
}

return `${price.toLocaleString()}원`;
}

useEffect(() => {
if (regularPrice != null) {
Expand Down Expand Up @@ -753,7 +747,7 @@ export default function ProductDetailScreen({
<span>
{displaySellerRating === "정보없음"
? "정보없음"
: `${displaySellerRating} (거래 ${sellerRecentSales.length}건)`}
: displaySellerRating}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

displaySellerRating 변수는 이미 위에서 sellerRating == null ? "정보없음" : sellerRating.toFixed(1)로 정의되어 항상 문자열 값을 가집니다. 따라서 여기서 다시 한번 "정보없음" 여부를 체크하는 삼항 연산자(748~750라인)는 불필요하며, 단순히 {displaySellerRating}만 렌더링하도록 단순화하여 가독성을 높일 수 있습니다.

References
  1. 가독성을 고려하여 중복되거나 불필요한 로직을 단순화해야 합니다. (link)

</span>
</div>
</div>
Expand Down Expand Up @@ -947,9 +941,6 @@ export default function ProductDetailScreen({
</div>
<div>
<h3 className="text-xl font-bold">{displaySellerName}</h3>
<p className="text-sm text-gray-500 mt-1">
{displaySellerBio}
</p>
</div>
</div>

Expand Down Expand Up @@ -978,34 +969,9 @@ export default function ProductDetailScreen({
</div>

<div className="space-y-3">
<h4 className="font-bold text-sm">상대 판매내역 (최근 3건)</h4>
<div className="space-y-2">
{sellerRecentSales.length === 0 ? (
<div className="p-3 bg-gray-50 rounded-xl text-sm text-gray-500">
정보없음
</div>
) : (
sellerRecentSales.map((item, idx) => (
<div
key={idx}
className="flex items-center justify-between p-3 bg-gray-50 rounded-xl"
>
<span className="text-sm font-medium text-gray-800">
{item.title ?? "정보없음"}
</span>
<div className="text-right">
<p className="text-xs font-bold">
{formatSellerRecentSalePrice(item.price)}
</p>
<p
className={`text-[10px] ${item.status === "판매완료" ? "text-gray-400" : "text-blue-500"}`}
>
{item.status ?? "정보없음"}
</p>
</div>
</div>
))
)}
<h4 className="font-bold text-sm">소개글</h4>
<div className="rounded-xl bg-gray-50 p-4 text-sm leading-relaxed text-gray-600">
{displaySellerBio}
</div>
</div>

Expand Down
2 changes: 2 additions & 0 deletions src/services/auction/detail/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ export interface AuctionDetailSeller {
memberId: number;
nickname: string;
profileImageUrl: string | null;
rating?: number | null;
bio?: string | null;
}

export interface AuctionDetailResponse {
Expand Down
Loading