-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
29 changed files
with
438 additions
and
493 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import { useNavigate } from 'react-router-dom'; | ||
import { useEffect, useState } from 'react'; | ||
import { useQuery } from '@tanstack/react-query'; | ||
import useFetch from 'commons/apis/useFetch'; | ||
import { ProfileListProps } from '../profileListType'; | ||
import ProfileListSkeleton from './ProfileListSkeleton'; | ||
import VProfileList from './VProfileList'; | ||
|
||
const ProfileList = (prop: { prop: string }) => { | ||
const [currentPage, setCurrentPage] = useState(1); // 현재 페이지 상태 | ||
const navigate = useNavigate(); | ||
// 페이지 변경 함수 | ||
const handlePageChange = (page: number) => { | ||
setCurrentPage(page); | ||
navigate(`/profile/${prop.prop}/${page}`); | ||
}; | ||
const word = prop.prop === 'urgent' ? 'sos' : prop.prop; | ||
console.log(word); | ||
|
||
const [list, setList] = useState<ProfileListProps | null>(null); | ||
|
||
const { data, isLoading, isError } = useQuery({ | ||
queryKey: ['list', currentPage], | ||
queryFn: () => useFetch(`/pet/profiles/${word}?page=${currentPage}`), | ||
}); | ||
|
||
useEffect(() => { | ||
if (!isLoading && !isError && data) { | ||
const pageData = { | ||
currentPage: data.pageNumber, // 현재 페이지 상태를 전달 | ||
lastPage: data.totalPages, | ||
maxLength: 7, | ||
setCurrentPage: handlePageChange, | ||
}; | ||
|
||
const listData = data.sosList ? data.sosList : data.newList; | ||
|
||
const listProps: ProfileListProps = { | ||
pageProps: pageData, | ||
listProps: listData, | ||
}; | ||
|
||
setList(listProps); | ||
} | ||
}, [data, isLoading, isError]); | ||
|
||
if (isLoading) { | ||
return <ProfileListSkeleton prop={prop.prop} />; | ||
} | ||
|
||
if (isError) { | ||
return <div>Error: {isError}</div>; | ||
} | ||
|
||
if (list) { | ||
const title = | ||
prop.prop === 'urgent' ? '긴급 도움이 필요해요' : '신규 애니모리 친구들'; | ||
return <VProfileList profileProps={list} title={title} />; | ||
} | ||
|
||
return null; | ||
}; | ||
export default ProfileList; |
46 changes: 0 additions & 46 deletions
46
src/pages/profileList/components/ProfileListHomeSkeleton.tsx
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
const ProfileListSkeleton = ({ prop }: { prop: string }) => { | ||
const title = | ||
prop === 'urgent' ? '긴급 도움이 필요해요' : '신규 애니모리 친구들'; | ||
const num = prop === 'home' ? '4' : '8'; | ||
return ( | ||
<div className="mx-16 sm:mx-32 lg:mx-64 my-14"> | ||
<h2 className="flex w-full font-bold text-xl sm:text-2xl items-center whitespace-nowrap"> | ||
{title} | ||
</h2> | ||
<div className="grid grid-cols-1 gap-1 md:grid-cols-2 my-3 w-full whitespace-nowrap"> | ||
{[...Array(parseInt(num, 10))].map((n, index) => { | ||
return ( | ||
<div | ||
key={index} | ||
className="w-64 h-28 bg-gray-200 m-2 flex items-center gap-6 ml-20" | ||
/> | ||
); | ||
})} | ||
</div> | ||
{prop === 'home' && ( | ||
<> | ||
<h2 className="flex w-full font-bold text-xl sm:text-2xl mt-10 mb-5 items-center whitespace-nowrap"> | ||
{title} | ||
</h2> | ||
<div className="grid grid-cols-1 gap-1 md:grid-cols-2 my-3 w-full whitespace-nowrap"> | ||
{[...Array(parseInt(num, 10))].map((n, index) => { | ||
return ( | ||
<div | ||
key={index} | ||
className="w-64 h-28 bg-gray-200 m-2 flex items-center gap-6 ml-20" | ||
/> | ||
); | ||
})} | ||
</div> | ||
</> | ||
)} | ||
</div> | ||
); | ||
}; | ||
|
||
export default ProfileListSkeleton; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import Pagination from 'commons/components/VPagenation'; | ||
import ProfileCard from './ProfileCard'; | ||
import { ProfileListProps } from '../profileListType'; | ||
|
||
const VProfileList = ({ | ||
profileProps, | ||
title, | ||
}: { | ||
profileProps: ProfileListProps; | ||
title: string; | ||
}) => { | ||
return ( | ||
<div className="mx-16 sm:mx-32 lg:mx-64 my-14"> | ||
<h2 className="flex w-full font-bold text-xl sm:text-2xl mb-5 items-center whitespace-nowrap"> | ||
{title} | ||
</h2> | ||
<div className="grid grid-cols-1 gap-1 md:grid-cols-2 my-1 w-full whitespace-nowrap"> | ||
{profileProps.listProps.map((item, index) => ( | ||
<ProfileCard | ||
key={index} | ||
status={ | ||
item.adoptionStatus | ||
? item.adoptionStatus | ||
: item.protectionExpirationDate | ||
} | ||
{...item} | ||
/> | ||
))} | ||
</div> | ||
<div className="flex justify-center mt-7 mb-11 sm:mb-28"> | ||
<Pagination | ||
currentPage={profileProps.pageProps.currentPage} | ||
lastPage={profileProps.pageProps.lastPage} | ||
maxLength={7} | ||
setCurrentPage={profileProps.pageProps.setCurrentPage} | ||
/> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default VProfileList; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.