Skip to content

Commit

Permalink
🎉 로딩 구현 및 제안 가능한 카드 get 요청 버그 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
juyeon-park committed Nov 27, 2023
1 parent c527402 commit cc5f7b5
Show file tree
Hide file tree
Showing 11 changed files with 64 additions and 48 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-hook-form": "^7.47.0",
"react-lottie-player": "^1.5.5",
"sharp": "^0.32.6",
"swiper": "^11.0.3",
"tailwind-merge": "^1.14.0",
Expand Down
21 changes: 19 additions & 2 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions public/loading.json

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,16 @@ import Image from 'next/image'
import SuggestCard from '@/components/domain/card/suggest-card'
import { Tabs, TabsTrigger, TabsList, TabsContent } from '@/components/ui/tabs'
import Assets from '@/config/assets'
import { AvailableCardSuggestionListRes } from '@/services/suggestion/suggestion'
import useSuggestionsQuery from '@/hooks/api/queries/useSuggestionsQuery'

type SuggestListProps = {
suggestionData: AvailableCardSuggestionListRes[]
pokeAvailable: boolean
toCardId: number
}

/**
* TODO : 스크롤바 디자인 수정
*/
const SuggestList = ({
suggestionData,
pokeAvailable,
toCardId,
}: SuggestListProps) => {
const SuggestList = ({ pokeAvailable, toCardId }: SuggestListProps) => {
const { data: suggestions } = useSuggestionsQuery(toCardId)

return (
<Tabs defaultValue="OFFER">
<TabsList>
Expand All @@ -28,7 +22,7 @@ const SuggestList = ({
<TabsContent
key={type}
value={type}
className="flex flex-col data-[state=inactive]:hidden h-[402px] overflow-y-auto"
className="flex flex-col data-[state=inactive]:hidden h-[402px] overflow-y-auto pr-2"
>
{!pokeAvailable && type === 'POKE' ? (
<div className="flex flex-col items-center justify-start gap-4 p-8">
Expand All @@ -43,8 +37,8 @@ const SuggestList = ({
</p>
</div>
) : (
suggestionData
.filter((v) => v.suggestionInfo.suggestionType === type)
suggestions
?.filter((v) => v.suggestionInfo.suggestionType === type)
.map((v) => (
<SuggestCard
key={v.cardInfo.cardId}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import { useState } from 'react'
import { StaticImageData } from 'next/image'
import { useRouter } from 'next/navigation'
import NoData from '@/components/domain/no-data'
import Button from '@/components/ui/button'
import {
Dialog,
Expand All @@ -14,7 +13,6 @@ import {
import Assets from '@/config/assets'
import { PRICE_RANGE_OBJS, TRADE_TYPE_OBJS } from '@/constants/card'
import { useAuth } from '@/contexts/AuthProvider'
import useSuggestionsQuery from '@/hooks/api/queries/useSuggestionsQuery'
import { TradeTypeObjs } from '@/types/card'
import { getValueByKey } from '@/utils/getValueByKey'
import SuggestList from './SuggestList'
Expand Down Expand Up @@ -82,7 +80,6 @@ const TradeSection = ({
setOpen(true)
}
}
const { data: suggestions } = useSuggestionsQuery(cardId, isMyItem)

return (
<section className="flex flex-col gap-2 w-full pt-4">
Expand All @@ -106,19 +103,7 @@ const TradeSection = ({
<DialogHeader>
<DialogTitle>제안 가능한 내 물건 보기</DialogTitle>
</DialogHeader>
{suggestions?.length === 0 ? (
<NoData
title="제안 가능한 내 물건이 없습니다."
onClickButton={() => router.push('/cards/new')}
buttonContent="물건 등록하러 가기"
/>
) : (
<SuggestList
toCardId={cardId}
pokeAvailable={pokeAvailable}
suggestionData={suggestions}
/>
)}
<SuggestList toCardId={cardId} pokeAvailable={pokeAvailable} />
</DialogContent>
</Dialog>
</section>
Expand Down
12 changes: 1 addition & 11 deletions src/app/(root)/(routes)/cards/[cardId]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
'use client'

import { useRouter } from 'next/navigation'
import NoData from '@/components/domain/no-data'
import Slider from '@/components/domain/slider'
import { useAuth } from '@/contexts/AuthProvider'
import useCardInfoQuery from '@/hooks/api/queries/useCardInfoQuery'
Expand All @@ -17,14 +15,12 @@ type CardPageProps = {

const CardPage = ({ params }: CardPageProps) => {
const { isLoggedIn } = useAuth()
const router = useRouter()
const { data } = useCardInfoQuery(Number(params.cardId), isLoggedIn)
const cardData = data?.data
console.log(cardData)

return (
<main className="flex-col min-h-screen bg-background-color">
{cardData ? (
{cardData && (
<>
<Slider
imageData={cardData.cardInfo.images}
Expand All @@ -50,12 +46,6 @@ const CardPage = ({ params }: CardPageProps) => {
/>
</div>
</>
) : (
<NoData
title="물건 정보가 없습니다."
buttonContent="뒤로가기"
onClickButton={() => router.back()}
/>
)}
</main>
)
Expand Down
25 changes: 25 additions & 0 deletions src/app/loading.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
'use client'

import Lottie from 'react-lottie-player'
import lottieJson from '../../public/loading.json'

const Loading = () => {
return (
<div className="w-full h-screen text-center">
<div className="flex flex-col items-center w-[320px] h-[360px] absolute left-1/2 translate-y-[50%] translate-x-[-50%] ">
<Lottie
loop
animationData={lottieJson}
play
style={{
width: '100%',
height: '100%',
}}
/>
<p className="font- text-[20px]">잠시만 기다려 주세요.</p>
</div>
</div>
)
}

export default Loading
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import Loading from '@/app/loading'

type ExceptionBoundaryProps = {
isLoading: boolean
isError: boolean
Expand All @@ -14,7 +16,7 @@ const ExceptionBoundary: React.FC<ExceptionBoundaryProps> = ({
children,
}: ExceptionBoundaryProps) => {
if (isLoading) {
return <div>로딩 중...</div>
return <Loading />
}

if (isError) {
Expand Down
1 change: 1 addition & 0 deletions src/contexts/TanstackQueryContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const TanstackQueryGlobalConfig = {
queries: {
retry: 3,
retryDelay: 1000,
suspense: true,
},
},
}
Expand Down
3 changes: 1 addition & 2 deletions src/hooks/api/queries/useSuggestionsQuery.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { useQuery } from '@tanstack/react-query'
import { getAvailableCardSuggestionList } from '@/services/suggestion/suggestion'

const useSuggestionsQuery = (cardId: number, isMyItem: boolean) => {
const useSuggestionsQuery = (cardId: number) => {
return useQuery({
queryKey: [cardId, 'suggestions'] as const,
queryFn: () => getAvailableCardSuggestionList(cardId),
enabled: !isMyItem,
})
}

Expand Down
7 changes: 4 additions & 3 deletions src/services/suggestion/suggestion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ import { DirectionType, Suggestion, SuggestionType } from '@/types/suggestion'
import apiClient from '../apiClient'

export type AvailableCardSuggestionListRes = {
cardInfo: Card
suggestionInfo: Suggestion
code: string
message: string
data: { cardList: { cardInfo: Card; suggestionInfo: Suggestion }[] }
}

const getAvailableCardSuggestionList = async (cardId: number) => {
const response = await apiClient.get(
const response: AvailableCardSuggestionListRes = await apiClient.get(
ApiEndPoint.getAvailableCardSuggestionList(cardId),
)
return response.data.cardList
Expand Down

0 comments on commit cc5f7b5

Please sign in to comment.