-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fix: mypage> friendslist -> friendship 네이밍 변경 * chore: buildQuery function 추가 * feat: useBaseInfiniteQuery hook 생성 * feat: 친구 목록 조회 API 연동 * feat: useObserver hook 추가, 무한 스크롤 적용 * docs: pr template 수정, deploy.sh 공백 제거 * feat: returnProfileImg function 생성 * feat: next.config.js image url setting * fix: 친구 목록 프로필 이미지 적용, isFetchingNextPage 에 따라 로딩스피너 추가
- Loading branch information
1 parent
6fb9b42
commit 7ca37c5
Showing
17 changed files
with
255 additions
and
50 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,8 @@ | ||
## 요구사항 | ||
|
||
이슈번호: [Jira 이슈번호](Jira 이슈링크) | ||
|
||
## 작업내용 | ||
|
||
- | ||
|
||
## 테스트 결과 또는 방법 | ||
- |
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 |
---|---|---|
|
@@ -3,6 +3,4 @@ | |
echo "> FE 배포" | ||
|
||
cd /home/ubuntu/fridge-link-deploy | ||
pm2 restart all | ||
|
||
|
||
pm2 restart all |
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 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 @@ | ||
export { default as useGetFriendships } from './useGetFriendships'; |
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,14 @@ | ||
import type { FriendshipData, FriendshipSortType } from '@/types/friendship'; | ||
|
||
import { queryKeys } from '../queryKeys'; | ||
import { useBaseInfiniteQuery } from '../useBaseInfiniteQuery'; | ||
|
||
const useGetFriendships = ({ sort }: { sort: FriendshipSortType }) => { | ||
return useBaseInfiniteQuery<FriendshipData[]>({ | ||
queryKey: queryKeys.FRIENDSHIPS(sort), | ||
url: '/friendship', | ||
sort, | ||
}); | ||
}; | ||
|
||
export default useGetFriendships; |
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 |
---|---|---|
@@ -1,7 +1,10 @@ | ||
import type { FriendshipSortType } from '@/types/friendship'; | ||
|
||
export const queryKeys = { | ||
INGREDIENT: (id?: number) => (id ? ['ingredient', id] : ['ingredient']), | ||
KAKAO: () => ['kakao'], | ||
SHARES: () => ['shares'], | ||
FRIENDSHIPS: (sort: FriendshipSortType) => ['friendship', sort], | ||
} as const; | ||
|
||
export type QueryKeys = (typeof queryKeys)[keyof typeof queryKeys]; |
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,50 @@ | ||
import type { ApiResponseType, InfiniteQueryResult } from '@/types/query'; | ||
import type { QueryFunctionContext, QueryKey } from '@tanstack/react-query'; | ||
|
||
import axiosInstance from '@/api/axiosInstance'; | ||
import { buildQuery } from '@/utils/buildQuery'; | ||
import { useInfiniteQuery } from '@tanstack/react-query'; | ||
|
||
export const getNextOffset = <T>(data: InfiniteQueryResult<T>) => { | ||
return data.last ? undefined : data.pageable.pageNumber + 1; | ||
}; | ||
|
||
export const useBaseInfiniteQuery = <T>({ | ||
queryKey, | ||
url, | ||
size, | ||
sort, | ||
}: { | ||
queryKey: QueryKey; | ||
url: string; | ||
size?: number; | ||
sort?: string; | ||
}) => { | ||
const INITIAL_PAGE_PARAM = 0; | ||
const DEFAULT_SIZE = 10; | ||
|
||
const fetchData = async <T>( | ||
context: QueryFunctionContext<QueryKey, number>, | ||
) => { | ||
const { pageParam = 0 } = context; | ||
|
||
const queryParamString = buildQuery({ | ||
page: pageParam, | ||
size: size ?? DEFAULT_SIZE, | ||
sort, | ||
}); | ||
|
||
const URL = `${url}?${queryParamString}`; | ||
const response = | ||
await axiosInstance.get<ApiResponseType<InfiniteQueryResult<T>>>(URL); | ||
return response.data.data; | ||
}; | ||
|
||
return useInfiniteQuery({ | ||
queryKey, | ||
queryFn: async (context: QueryFunctionContext<QueryKey, number>) => | ||
await fetchData<T>(context), | ||
initialPageParam: INITIAL_PAGE_PARAM, | ||
getNextPageParam: (res) => getNextOffset<T>(res), | ||
}); | ||
}; |
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,35 @@ | ||
import type { RefObject } from 'react'; | ||
import { useEffect } from 'react'; | ||
|
||
export const useObserver = ({ | ||
target, | ||
onIntersect, | ||
root = null, | ||
rootMargin = '1px', | ||
threshold = 0, | ||
}: { | ||
target: RefObject<HTMLDivElement>; | ||
onIntersect: IntersectionObserverCallback; | ||
root?: Element | Document | null; | ||
rootMargin?: string; | ||
threshold?: number | number[]; | ||
}) => { | ||
useEffect(() => { | ||
let observer: IntersectionObserver | undefined; | ||
|
||
if (target?.current !== null) { | ||
observer = new IntersectionObserver(onIntersect, { | ||
root, | ||
rootMargin, | ||
threshold, | ||
}); | ||
observer.observe(target.current); | ||
} | ||
|
||
return () => { | ||
if (typeof observer !== 'undefined') { | ||
observer.disconnect(); | ||
} | ||
}; | ||
}, [target, rootMargin, threshold, onIntersect, root]); | ||
}; |
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 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,7 @@ | ||
export interface FriendshipData { | ||
userId: number; | ||
nickname: string; | ||
ingredientCount: number; | ||
} | ||
|
||
export type FriendshipSortType = 'nickname' | 'createdAt'; |
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,33 @@ | ||
export interface InfiniteQueryResult<T> { | ||
totalPages: number; | ||
totalElements: number; | ||
size: number; | ||
content: T; | ||
number: number; | ||
sort: { | ||
empty: boolean; | ||
sorted: boolean; | ||
unsorted: boolean; | ||
}; | ||
numberOfElements: number; | ||
pageable: { | ||
offset: number; | ||
sort: { | ||
empty: boolean; | ||
sorted: boolean; | ||
unsorted: boolean; | ||
}; | ||
pageSize: number; | ||
paged: boolean; | ||
pageNumber: number; | ||
unpaged: boolean; | ||
}; | ||
first: boolean; | ||
last: boolean; | ||
empty: boolean; | ||
} | ||
|
||
export interface ApiResponseType<T> { | ||
message: string; | ||
data: T; | ||
} |
Oops, something went wrong.