Skip to content

Commit

Permalink
Bug: MyPoint useinfiniteQuery
Browse files Browse the repository at this point in the history
  • Loading branch information
yejinleee committed Jul 9, 2022
1 parent 162586e commit 7a8d1b1
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 30 deletions.
3 changes: 2 additions & 1 deletion src/screens/RegisterCategory.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,10 @@ const RegisterCategory = ({navigation, route}: Props) => {
// };

const renderedCategories = () => {
return categoryList.map((item) => {
return categoryList.map((item, idx) => {
return (
<CategoryItem
key={idx}
onPress={() => {
if (selectedCategories.includes(item.id)) {
setSelectedCategories((current) =>
Expand Down
76 changes: 47 additions & 29 deletions src/screens/my/MyPoint.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {calHeight, calWidth} from '../../assets/CalculateLength';
import {customAxios} from '../../api/customAxios';
import {useInfiniteQuery} from 'react-query';
import {queryKey} from '../../api/queryKey';
import { resolvePath } from 'react-native-reanimated/lib/types/lib/reanimated2/animation/styleAnimation';

type Props = NativeStackScreenProps<MyStackParamList, 'MyPoint'>;
export type PointsListContent = {
Expand Down Expand Up @@ -69,43 +70,58 @@ export const MyPoint = ({navigation, route}: Props) => {
// ```
//마이페이지 - 나의 포인트 내역 조회
const getPointsList = async () => {
const {data} = await customAxios().get('/api/v1/points/list/me', {
const response = await customAxios().get('/api/v1/points/list/me', {
params: {
pageNumber: 1,
pageNumber: 0,
},
});
// console.log('받아아', response.data.result.point.content.length); //왜 20개씩 옵니까 ?
// console.log('여여ㅕㅇ',response);//response.data.result 하면 스웨커대로
// console.log(data.result.point);x
// console.log('d', data.result.point.content[0].date);
return {
result: data.result.point.content,
isLast: data.result.point.last, //그페이지가 끝인건지 아닌지TF
// nextPage: pageParam + 1,
pageNumber: data.result.point.pageable.pageNumber,
totalPoints: data.result.totalPoints,
};
// return {
// result: data.result.point.content,
// isLast: data.result.point.last, //그페이지가 끝인건지 아닌지TF
// // nextPage: pageParam + 1,
// pageNumber: data.result.point.pageable.pageNumber,
// totalPoints: data.result.totalPoints,
// };
// console.log(response.data);
//{"code": 1000, "isSuccess": true, "message": ["요청에 성공하였습 니다."], "result": {"point": {"content": [Array], "empty": false, "first": true, "last": false, "number": 0, "numberOfElements": 20, "pageable": [Object], "size": 20, "sort": [Object]}, "totalPoints": 750}}
return response;
};
// const DataPointsList = useQuery<PointsListType>(queryKey.POINTSLIST, getPointsList);
// DataPointsList.content (//point없애줘..) 로 접근
// DataPointsList.totalPoints로 접근

//inf시도
const res = useInfiniteQuery<PointsListType>(queryKey.POINTSLIST, getPointsList, {
//첫번째인자 - 호출된 가장 마지막에 있는 페이지 데이터
//두번째인자 - 호출된 모든 페이지 데이터
//(벨로그) 현재 받아온데이터 , 현재 쌓여있는 전체 데이터. 페이지정보 받아올수있다면 사용하면될것
// lastPage(첫인자)엔 저 위에 getPointsList에서 리턴한 {result:~, isLAst ~~}
getNextPageParam: (lastPage, _allPages) => {
if (!lastPage.isLast) return lastPage.pageNumber + 1; //다음 페이지를 호출할 때 사용 될 pageParam
// if (!lastPage.isLast) return _allPages.length + 1; // ? _ ?
return undefined;
const {isLoading, data, hasNextPage, fetchNextPage} = useInfiniteQuery(
queryKey.POINTSLIST,
getPointsList,
{
//첫번째인자 - 호출된 가장 마지막에 있는 페이지 데이터
//두번째인자 - 호출된 모든 페이지 데이터
//(벨로그) 현재 받아온데이터 , 현재 쌓여있는 전체 데이터. 페이지정보 받아올수있다면 사용하면될것
// lastPage(첫인자)엔 저 위에 getPointsList에서 리턴한 {result:~, isLAst ~~}
//getNextPageParam= retrives # of next page
getNextPageParam: (lastPage, _allPages) => {
// console.log('요건몰까',lastPage.data.result.point.last); //스웨거대로임
if (!lastPage.data.result.point.last) return lastPage.data.result.point.pageable.pageNumber + 1; //다음 페이지를 호출할 때 사용 될 pageParam
// if (!lastPage.isLast) return _allPages.length + 1; // ? _ ?
return undefined;
},
},
});
);
// console.log('dd',data?.pages[0].data.result.point.content[0]); //더미데이터같은형식
console.log('총포인트', data?.pages[0].data.result.totalPoints);
const loadMore = () => {
if (hasNextPage) {
fetchNextPage();
}
};
//
console.log('rrr', res.data.pages);
// console.log('rrr', res.data?.pages);
// [{"isLast": false, "pageNumber": 0, "result": [[Object], [Object], [Object], [Object], [Object], [Object], [Object], [Object], [Object], [Object], [Object], [Object], [Object], [Object], [Object], [Object], [Object], [Object], [Object], [Object]], "totalPoints": 750}]
const goBack = () => {
navigation.goBack();
};
// 호출시
// {res.data.pages[0].result[0].date}
return (
<>
<SafeAreaView style={{flex: 0, backgroundColor: '#FFFFFF'}} />
Expand All @@ -116,7 +132,7 @@ export const MyPoint = ({navigation, route}: Props) => {
<View>
<Text style={[DesignSystem.body2Lt, {color: '#616161'}]}>내 포인트</Text>
<Text style={[DesignSystem.h1SB, {color: '#111111'}]}>
{res.data.pages[0].totalPoints.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',')}P
{data?.pages[0].data.result.totalPoints.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',')}P
{/* {DataPointsList.totalPoints.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',')}P */}
</Text>
</View>
Expand All @@ -135,10 +151,12 @@ export const MyPoint = ({navigation, route}: Props) => {
<Text style={[DesignSystem.subtitle2, {marginTop: 16, color: '#111111'}]}>포인트 내역</Text>
<FlatList
style={{marginTop: 18}}
showsVerticalScrollIndicator={false}
showsVerticalScrollIndicator={true}
scrollEventThrottle={10}
data={dummyMission}
// data={DataPointsList.content}
// data={dummyMission}
data={data?.pages[0].data.result.point.content}
onEndReached={loadMore}
onEndReachedThreshold={0.8}
renderItem={({item}) => (
<>
<MyPointList
Expand Down

0 comments on commit 7a8d1b1

Please sign in to comment.