Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🎉 찜 페이지 목록 구현 #68

Merged
merged 7 commits into from
Nov 13, 2023
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
51 changes: 51 additions & 0 deletions src/app/(root)/(routes)/mydibs/my-dibs-list/MyDibsList.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
'use client'

import { useEffect, useRef, Fragment } from 'react'
import TradeStatusCard from '@/components/domain/card/trade-status-card'
import { useMyDibsQuery } from '@/hooks/api/queries/useMyDibsQuery'
import { useIntersectionObserver } from '@/hooks/useIntersectionObserver'
import { Item } from '@/types'

const MyDibsList = () => {
const { data, fetchNextPage, isFetchingNextPage } = useMyDibsQuery()
console.log(data)

const lastElementRef = useRef<HTMLDivElement | null>(null)
const entry = useIntersectionObserver(lastElementRef, { threshold: 1.0 })

useEffect(() => {
if (isFetchingNextPage) {
return
}

if (entry?.isIntersecting) {
fetchNextPage()
}
}, [entry?.isIntersecting, fetchNextPage, isFetchingNextPage])

const hasData = data?.pages[0].length !== 0
const pages = data?.pages
return (
<>
<div className="flex flex-col items-center mt-6">
{hasData
? pages?.map((currentPage, pageIndex) => (
<Fragment key={pageIndex}>
{currentPage.map((item: Item) => (
<TradeStatusCard
key={item.cardId}
item={item}
className="mb-6"
/>
))}
</Fragment>
))
: '데이터가 없습니다.'}
{isFetchingNextPage && '데이터 불러오는 중'}
</div>

<div ref={lastElementRef} />
</>
)
}
export default MyDibsList
3 changes: 3 additions & 0 deletions src/app/(root)/(routes)/mydibs/my-dibs-list/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import MyDibsList from './MyDibsList'

export default MyDibsList
13 changes: 13 additions & 0 deletions src/app/(root)/(routes)/mydibs/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import PageTitle from '@/components/domain/page-title'
import MyDibsList from './my-dibs-list'

const MyDibsPage = () => {
return (
<>
<PageTitle title="찜 목록" />
<MyDibsList />
</>
)
}

export default MyDibsPage
12 changes: 10 additions & 2 deletions src/components/domain/card/trade-status-card/TradeStatusCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,15 @@ const TradeAvailableBadge = () => <Badge variant={'primary'}>거래가능</Badge
const ReservedBadge = () => <Badge variant={'secondary'}>예약중</Badge>

const TradeStatusCard = ({
item: { cardId, image, cardTitle, status, itemName, priceRange, createdAt },
item: {
cardId,
thumbNail,
cardTitle,
status,
itemName,
priceRange,
createdAt,
},
className,
}: TradeStatusCardProps) => {
return (
Expand All @@ -31,7 +39,7 @@ const TradeStatusCard = ({
>
<div className="h-full w-32 relative">
<CardImage
src={image}
src={thumbNail}
alt="이미지가 없습니다."
layout="fill"
objectFit="cover"
Expand Down
4 changes: 2 additions & 2 deletions src/components/ui/Card/Card.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ export const Trade: Story = {
createdAt: '2023-11-01T08:08:00',
modifiedAt: '2023-11-01T08:08:00',
dibCount: 19,
priceRange: '10만원대',
image:
priceRange: '10000-50000',
thumbNail:
'https://cdn.cetizen.com/CDN/market/market_large_crop/202203/20220318/220318152808_1_2913635.jpg',
status: 'TRADE_AVAILABLE',
}}
Expand Down
1 change: 1 addition & 0 deletions src/config/apiEndPoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const ApiEndPoint = {
suggestions: (itemId: number) => `/${itemId}/available-cards`,
putUserProfile: () => '/users/profile-image',
putUserNickname: () => '/users/nickname',
getMyDibs: (cursorId: number) => `/api/v1/dibs/?cursorId=${cursorId}`,
} as const

export default ApiEndPoint
16 changes: 16 additions & 0 deletions src/hooks/api/queries/useMyDibsQuery.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { useInfiniteQuery } from '@tanstack/react-query'
import { getMyDibs } from '@/services/item/item'

export const useMyDibsQuery = () => {
return useInfiniteQuery({
queryKey: ['myDibs'],
queryFn: async ({ pageParam = 0 }) => await getMyDibs(pageParam),
initialPageParam: 0,
getNextPageParam: (lastPage, allPages, lastPageParam) => {
if (lastPage.length === 0) {
return undefined
}
return lastPageParam + 1
},
})
}
85 changes: 42 additions & 43 deletions src/lib/msw/mocks/data/items.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
"modifiedAt": "2023-11-01T08:08:00",
"dibCount": 19,
"priceRange": "10000-50000",
"image": "https://cdn.cetizen.com/CDN/market/market_large_crop/202203/20220318/220318152808_1_2913635.jpg",
"status": "TRADE_AVAILABLE"
"thumbNail": "https://cdn.cetizen.com/CDN/market/market_large_crop/202203/20220318/220318152808_1_2913635.jpg",
juyeon-park marked this conversation as resolved.
Show resolved Hide resolved
"status": "EXCHANGEABLE"
},
{
"cardId": 2,
Expand All @@ -18,7 +18,7 @@
"modifiedAt": "2023-11-01T08:08:00",
"dibCount": 18,
"priceRange": "10만원대",
"image": "https://cdn.cetizen.com/CDN/market/market_large_crop/202203/20220318/220318152808_1_2913635.jpg",
"thumbNail": "https://cdn.cetizen.com/CDN/market/market_large_crop/202203/20220318/220318152808_1_2913635.jpg",
"status": "RESERVED"
},
{
Expand All @@ -29,8 +29,8 @@
"modifiedAt": "2023-11-01T08:08:00",
"dibCount": 17,
"priceRange": "20만원대",
"image": "https://cdn.cetizen.com/CDN/market/market_large_crop/202203/20220318/220318152808_1_2913635.jpg",
"status": "TRADE_AVAILABLE"
"thumbNail": "https://cdn.cetizen.com/CDN/market/market_large_crop/202203/20220318/220318152808_1_2913635.jpg",
"status": "EXCHANGEABLE"
},
{
"cardId": 4,
Expand All @@ -40,8 +40,8 @@
"modifiedAt": "2023-11-01T08:08:00",
"dibCount": 19,
"priceRange": "10000-50000",
"image": "https://cdn.cetizen.com/CDN/market/market_large_crop/202203/20220318/220318152808_1_2913635.jpg",
"status": "TRADE_AVAILABLE"
"thumbNail": "https://cdn.cetizen.com/CDN/market/market_large_crop/202203/20220318/220318152808_1_2913635.jpg",
"status": "EXCHANGEABLE"
},
{
"cardId": 5,
Expand All @@ -51,8 +51,8 @@
"modifiedAt": "2023-11-01T08:08:00",
"dibCount": 18,
"priceRange": "10만원대",
"image": "https://cdn.cetizen.com/CDN/market/market_large_crop/202203/20220318/220318152808_1_2913635.jpg",
"status": "TRADE_AVAILABLE"
"thumbNail": "https://cdn.cetizen.com/CDN/market/market_large_crop/202203/20220318/220318152808_1_2913635.jpg",
"status": "EXCHANGEABLE"
},
{
"cardId": 6,
Expand All @@ -73,8 +73,8 @@
"modifiedAt": "2023-11-01T08:08:00",
"dibCount": 19,
"priceRange": "10000-50000",
"image": "https://cdn.cetizen.com/CDN/market/market_large_crop/202203/20220318/220318152808_1_2913635.jpg",
"status": "TRADE_AVAILABLE"
"thumbNail": "https://cdn.cetizen.com/CDN/market/market_large_crop/202203/20220318/220318152808_1_2913635.jpg",
"status": "EXCHANGEABLE"
},
{
"cardId": 8,
Expand All @@ -95,8 +95,8 @@
"modifiedAt": "2023-11-01T08:08:00",
"dibCount": 17,
"priceRange": "20만원대",
"image": "https://cdn.cetizen.com/CDN/market/market_large_crop/202203/20220318/220318152808_1_2913635.jpg",
"status": "TRADE_AVAILABLE"
"thumbNail": "https://cdn.cetizen.com/CDN/market/market_large_crop/202203/20220318/220318152808_1_2913635.jpg",
"status": "EXCHANGEABLE"
},
{
"cardId": 10,
Expand All @@ -106,8 +106,8 @@
"modifiedAt": "2023-11-01T08:08:00",
"dibCount": 19,
"priceRange": "10000-50000",
"image": "https://cdn.cetizen.com/CDN/market/market_large_crop/202203/20220318/220318152808_1_2913635.jpg",
"status": "TRADE_AVAILABLE"
"thumbNail": "https://cdn.cetizen.com/CDN/market/market_large_crop/202203/20220318/220318152808_1_2913635.jpg",
"status": "EXCHANGEABLE"
},
{
"cardId": 11,
Expand All @@ -117,8 +117,8 @@
"modifiedAt": "2023-11-01T08:08:00",
"dibCount": 18,
"priceRange": "10만원대",
"image": "https://cdn.cetizen.com/CDN/market/market_large_crop/202203/20220318/220318152808_1_2913635.jpg",
"status": "TRADE_AVAILABLE"
"thumbNail": "https://cdn.cetizen.com/CDN/market/market_large_crop/202203/20220318/220318152808_1_2913635.jpg",
"status": "EXCHANGEABLE"
},
{
"cardId": 12,
Expand All @@ -128,8 +128,8 @@
"modifiedAt": "2023-11-01T08:08:00",
"dibCount": 17,
"priceRange": "20만원대",
"image": "https://cdn.cetizen.com/CDN/market/market_large_crop/202203/20220318/220318152808_1_2913635.jpg",
"status": "TRADE_AVAILABLE"
"thumbNail": "https://cdn.cetizen.com/CDN/market/market_large_crop/202203/20220318/220318152808_1_2913635.jpg",
"status": "EXCHANGEABLE"
},
{
"cardId": 13,
Expand All @@ -139,8 +139,8 @@
"modifiedAt": "2023-11-01T08:08:00",
"dibCount": 19,
"priceRange": "10000-50000",
"image": "https://cdn.cetizen.com/CDN/market/market_large_crop/202203/20220318/220318152808_1_2913635.jpg",
"status": "TRADE_AVAILABLE"
"thumbNail": "https://cdn.cetizen.com/CDN/market/market_large_crop/202203/20220318/220318152808_1_2913635.jpg",
"status": "EXCHANGEABLE"
},
{
"cardId": 14,
Expand All @@ -150,7 +150,7 @@
"modifiedAt": "2023-11-01T08:08:00",
"dibCount": 18,
"priceRange": "10만원대",
"image": "https://cdn.cetizen.com/CDN/market/market_large_crop/202203/20220318/220318152808_1_2913635.jpg",
"thumbNail": "https://cdn.cetizen.com/CDN/market/market_large_crop/202203/20220318/220318152808_1_2913635.jpg",
"status": "RESERVED"
},
{
Expand All @@ -161,8 +161,8 @@
"modifiedAt": "2023-11-01T08:08:00",
"dibCount": 17,
"priceRange": "20만원대",
"image": "https://cdn.cetizen.com/CDN/market/market_large_crop/202203/20220318/220318152808_1_2913635.jpg",
"status": "TRADE_AVAILABLE"
"thumbNail": "https://cdn.cetizen.com/CDN/market/market_large_crop/202203/20220318/220318152808_1_2913635.jpg",
"status": "EXCHANGEABLE"
},
{
"cardId": 16,
Expand All @@ -172,8 +172,8 @@
"modifiedAt": "2023-11-01T08:08:00",
"dibCount": 19,
"priceRange": "10000-50000",
"image": "https://cdn.cetizen.com/CDN/market/market_large_crop/202203/20220318/220318152808_1_2913635.jpg",
"status": "TRADE_AVAILABLE"
"thumbNail": "https://cdn.cetizen.com/CDN/market/market_large_crop/202203/20220318/220318152808_1_2913635.jpg",
"status": "EXCHANGEABLE"
},
{
"cardId": 17,
Expand All @@ -183,19 +183,18 @@
"modifiedAt": "2023-11-01T08:08:00",
"dibCount": 18,
"priceRange": "10만원대",
"image": "https://cdn.cetizen.com/CDN/market/market_large_crop/202203/20220318/220318152808_1_2913635.jpg",
"status": "TRADE_AVAILABLE"
},
{
"cardId": 18,
"cardTitle": "아이폰 18 팝니다",
"itemName": "아이폰 18",
"createdAt": "2023-11-01T08:08:00",
"modifiedAt": "2023-11-01T08:08:00",
"dibCount": 17,
"priceRange": "20만원대",
"image": "https://cdn.cetizen.com/CDN/market/market_large_crop/202203/20220318/220318152808_1_2913635.jpg",
"status": "TRADE_AVAILABLE"
"thumbNail": "https://cdn.cetizen.com/CDN/market/market_large_crop/202203/20220318/220318152808_1_2913635.jpg",
"status": "EXCHANGEABLE"
},{
"cardId": 18,
"cardTitle": "아이폰 17 팝니다",
"itemName": "아이폰 17",
"createdAt": "2023-11-01T08:08:00",
"modifiedAt": "2023-11-01T08:08:00",
"dibCount": 18,
"priceRange": "10만원대",
"thumbNail": "https://cdn.cetizen.com/CDN/market/market_large_crop/202203/20220318/220318152808_1_2913635.jpg",
"status": "EXCHANGEABLE"
},
{
"cardId": 19,
Expand All @@ -216,8 +215,8 @@
"modifiedAt": "2023-11-01T08:08:00",
"dibCount": 18,
"priceRange": "10만원대",
"image": "https://cdn.cetizen.com/CDN/market/market_large_crop/202203/20220318/220318152808_1_2913635.jpg",
"status": "TRADE_AVAILABLE"
"thumbNail": "https://cdn.cetizen.com/CDN/market/market_large_crop/202203/20220318/220318152808_1_2913635.jpg",
"status": "EXCHANGEABLE"
},
{
"cardId": 21,
Expand All @@ -227,7 +226,7 @@
"modifiedAt": "2023-11-01T08:08:00",
"dibCount": 17,
"priceRange": "20만원대",
"image": "https://cdn.cetizen.com/CDN/market/market_large_crop/202203/20220318/220318152808_1_2913635.jpg",
"status": "TRADE_AVAILABLE"
"thumbNail": "https://cdn.cetizen.com/CDN/market/market_large_crop/202203/20220318/220318152808_1_2913635.jpg",
"status": "EXCHANGEABLE"
}
]
Loading