forked from DangleDangle/dangledangle-client
-
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.
Merge pull request #78 from YAPP-Github/feat/YW2-153
[Feat] 홈 캘린더 api
- Loading branch information
Showing
19 changed files
with
220 additions
and
129 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 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 { NUM_OF_MAX_ITERATION_MONTHS } from '@/constants/volunteerEvent'; | ||
import { getStartOfMonth, getEndOfMonth } from '@/utils/timeConvert'; | ||
import { UseInfiniteQueryOptions } from '@tanstack/react-query'; | ||
import moment, { Moment } from 'moment'; | ||
import { GetResponse } from '.'; | ||
|
||
export type UseVolunteerEventListPageParam = { | ||
to: Moment; | ||
from: Moment; | ||
}; | ||
|
||
export const monthlyInfiniteOption: UseInfiniteQueryOptions<GetResponse> = { | ||
getPreviousPageParam: ( | ||
lastPage | ||
): UseVolunteerEventListPageParam | undefined => { | ||
const prevDate = moment(lastPage.from).subtract(1, 'month'); | ||
|
||
// NUM_OF_MAX_ITERATION_MONTHS개월 이전 데이터는 받아오지 않는다. | ||
const minDate = getStartOfMonth(new Date()).subtract( | ||
NUM_OF_MAX_ITERATION_MONTHS, | ||
'months' | ||
); | ||
if (prevDate.isSameOrBefore(minDate)) { | ||
return undefined; | ||
} | ||
|
||
return { | ||
from: getStartOfMonth(prevDate), | ||
to: getEndOfMonth(prevDate) | ||
}; | ||
}, | ||
getNextPageParam: (lastPage): UseVolunteerEventListPageParam | undefined => { | ||
const nextDate = moment(lastPage.from).add(1, 'month'); | ||
|
||
// NUM_OF_MAX_ITERATION_MONTHS개월 이후 데이터는 받아오지 않는다. | ||
const maxDate = getStartOfMonth(new Date()).add( | ||
NUM_OF_MAX_ITERATION_MONTHS, | ||
'months' | ||
); | ||
|
||
if (nextDate.isSameOrAfter(maxDate)) { | ||
return undefined; | ||
} | ||
|
||
return { | ||
from: getStartOfMonth(nextDate), | ||
to: getEndOfMonth(nextDate) | ||
}; | ||
} | ||
}; |
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,45 @@ | ||
import { | ||
UseInfiniteQueryOptions, | ||
useInfiniteQuery | ||
} from '@tanstack/react-query'; | ||
import { Moment } from 'moment'; | ||
import moment from 'moment'; | ||
import { | ||
formatDatetimeForServer, | ||
getEndOfMonth, | ||
getStartOfMonth, | ||
minutes | ||
} from '@/utils/timeConvert'; | ||
import { NUM_OF_MAX_ITERATION_MONTHS } from '@/constants/volunteerEvent'; | ||
import { GetResponse, HomeEventFilter, shelterGet, queryKey } from '.'; | ||
|
||
export default function useShelterHomeEventList( | ||
filter: HomeEventFilter, | ||
from: Moment, | ||
to: Moment, | ||
options?: UseInfiniteQueryOptions<GetResponse> | ||
) { | ||
const filterForKey = { | ||
...filter | ||
}; | ||
delete filterForKey.latitude; | ||
delete filterForKey.longitude; | ||
return useInfiniteQuery<GetResponse>( | ||
queryKey.list(filterForKey), | ||
({ | ||
pageParam = { | ||
from, | ||
to | ||
} | ||
}) => | ||
shelterGet( | ||
filter, | ||
formatDatetimeForServer(pageParam.from, 'DATE'), | ||
formatDatetimeForServer(pageParam.to, 'DATE') | ||
), | ||
{ | ||
cacheTime: minutes(10), | ||
...options | ||
} | ||
); | ||
} |
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
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
Oops, something went wrong.