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 4 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
47 changes: 47 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,47 @@
'use client'

import { useEffect, useRef, Fragment } from 'react'
import TradeStateCard from '@/components/domain/card/trade-state-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])

return (
<>
<div className="flex flex-col items-center">
{data?.pages.map((group, i) => (
<Fragment key={i}>
{group.map((item: Item) => (
<TradeStateCard
key={item.cardId}
item={item}
className="mb-6 w-[80%]"
juyeon-park marked this conversation as resolved.
Show resolved Hide resolved
/>
))}
</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
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ type TradeStateMap = {
}

const TradeStateCard = ({
item: { image, cardTitle, status, itemName, priceRange, createdAt },
item: { thumbNail, cardTitle, status, itemName, priceRange, createdAt },
className,
}: TradeStateCardProps) => {
const tradeStateMap: TradeStateMap = {
Expand All @@ -48,7 +48,7 @@ const TradeStateCard = ({
>
<div className="h-full w-32 relative">
<CardImage
src={image}
src={thumbNail}
alt="이미지가 없습니다."
layout="fill"
objectFit="cover"
Expand Down
2 changes: 1 addition & 1 deletion src/components/ui/Card/Card.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export const Trade: Story = {
modifiedAt: '2023-11-01T08:08:00',
dibCount: 19,
priceRange: '10000-50000',
image:
thumbNail:
'https://cdn.cetizen.com/CDN/market/market_large_crop/202203/20220318/220318152808_1_2913635.jpg',
status: 'EXCHANGEABLE',
}}
Expand Down
1 change: 1 addition & 0 deletions src/config/apiEndPoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,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
},
})
}
36 changes: 18 additions & 18 deletions src/lib/msw/mocks/data/items.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"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",
"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"
},
{
Expand All @@ -20,7 +20,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 @@ -32,7 +32,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",
"thumbNail": "https://cdn.cetizen.com/CDN/market/market_large_crop/202203/20220318/220318152808_1_2913635.jpg",
"status": "EXCHANGEABLE"
},
{
Expand All @@ -44,7 +44,7 @@
"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",
"thumbNail": "https://cdn.cetizen.com/CDN/market/market_large_crop/202203/20220318/220318152808_1_2913635.jpg",
"status": "EXCHANGEABLE"
},
{
Expand All @@ -56,7 +56,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": "EXCHANGEABLE"
},
{
Expand All @@ -80,7 +80,7 @@
"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",
"thumbNail": "https://cdn.cetizen.com/CDN/market/market_large_crop/202203/20220318/220318152808_1_2913635.jpg",
"status": "EXCHANGEABLE"
},
{
Expand All @@ -104,7 +104,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",
"thumbNail": "https://cdn.cetizen.com/CDN/market/market_large_crop/202203/20220318/220318152808_1_2913635.jpg",
"status": "EXCHANGEABLE"
},
{
Expand All @@ -116,7 +116,7 @@
"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",
"thumbNail": "https://cdn.cetizen.com/CDN/market/market_large_crop/202203/20220318/220318152808_1_2913635.jpg",
"status": "EXCHANGEABLE"
},
{
Expand All @@ -128,7 +128,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": "EXCHANGEABLE"
},
{
Expand All @@ -140,7 +140,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",
"thumbNail": "https://cdn.cetizen.com/CDN/market/market_large_crop/202203/20220318/220318152808_1_2913635.jpg",
"status": "EXCHANGEABLE"
},
{
Expand All @@ -152,7 +152,7 @@
"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",
"thumbNail": "https://cdn.cetizen.com/CDN/market/market_large_crop/202203/20220318/220318152808_1_2913635.jpg",
"status": "EXCHANGEABLE"
},
{
Expand All @@ -164,7 +164,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 @@ -176,7 +176,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",
"thumbNail": "https://cdn.cetizen.com/CDN/market/market_large_crop/202203/20220318/220318152808_1_2913635.jpg",
"status": "EXCHANGEABLE"
},
{
Expand All @@ -188,7 +188,7 @@
"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",
"thumbNail": "https://cdn.cetizen.com/CDN/market/market_large_crop/202203/20220318/220318152808_1_2913635.jpg",
"status": "EXCHANGEABLE"
},
{
Expand All @@ -200,7 +200,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": "EXCHANGEABLE"
},
{
Expand All @@ -212,7 +212,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",
"thumbNail": "https://cdn.cetizen.com/CDN/market/market_large_crop/202203/20220318/220318152808_1_2913635.jpg",
"status": "EXCHANGEABLE"
},
{
Expand All @@ -236,7 +236,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": "EXCHANGEABLE"
},
{
Expand All @@ -248,7 +248,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",
"thumbNail": "https://cdn.cetizen.com/CDN/market/market_large_crop/202203/20220318/220318152808_1_2913635.jpg",
"status": "EXCHANGEABLE"
}
]
Loading