Skip to content

Commit

Permalink
Merge pull request #108 from CheckIt-v3/fix/#107
Browse files Browse the repository at this point in the history
[Fix/#107] 무한 스크롤 에러 수정
  • Loading branch information
egg-silver authored Sep 24, 2024
2 parents 935672d + bba65cb commit b4c72d2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
1 change: 1 addition & 0 deletions src/components/Header/MyHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const MyHeader: FC<{ onSearch: (query: string) => void }> = ({ onSearch }) => {
// 서버에서 로그아웃이 성공하면 로컬 스토리지에서 토큰을 삭제하고 홈페이지로 이동
localStorage.removeItem('accessToken')
localStorage.removeItem('refreshToken')
localStorage.removeItem('userName')
navigate('/')
} else {
// 서버에서 로그아웃이 실패하면 에러 처리
Expand Down
22 changes: 11 additions & 11 deletions src/components/Tab/Pannels/WishList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const WishList = () => {
const [hasMore, setHasMore] = useState<boolean>(true)
const access = localStorage.getItem('accessToken')
const { setSelectedBook } = useMyContext()
const [isLoading, _] = useState(true)
const [isLoading, setIsLoading] = useState(true)
const navigate = useNavigate()

const Toast = Swal.mixin({
Expand All @@ -37,23 +37,22 @@ const WishList = () => {
},
})

// 찜한 책 api 요청
useEffect(() => {
getWishList()
}, [])

// 책 목록 가져오기
const getWishList = async () => {
try {
const response = await baseInstance.get(`/readings?pageNumber=${page}&status=LIKE`, {
headers: { Authorization: `Bearer ${access}` },
})
const wishBooks = response.data.bookInfos.content
if (response.data.bookInfos.empty) {
// console.log(wishBooks);

if (response.data.bookInfos.last) {
setHasMore(false)
} else {
const newBooks = wishBooks.map((book: any) => ({ ...book, isLiked: true }))
setBooks((prevBooks) => [...prevBooks, ...newBooks])
setIsLoading(false)
}
const newBooks = wishBooks.map((book: any) => ({ ...book, isLiked: true }))
setBooks((prevBooks) => [...prevBooks, ...newBooks])
console.log(books)
} catch (error) {
console.log(error)
}
Expand All @@ -66,6 +65,7 @@ const WishList = () => {

const setTarget = useInfiniteScroll({ hasMore, onLoadMore: loadMore })

// 좋아요 토글
const toggleWhishList = async (book: BookType) => {
setSelectedBook(book)

Expand Down Expand Up @@ -97,7 +97,7 @@ const WishList = () => {

return (
<div className="w-full">
{books.length === 0 && isLoading ? (
{books.length === 0 ? (
<div className="w-full mt-10 flex flex-col justify-center items-center h-dvh">
<Lottie
animationData={Empty}
Expand Down

0 comments on commit b4c72d2

Please sign in to comment.