generated from mbti-nf-team/nextjs-starter
-
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 #202 from mbti-nf-team/feat/google-node-api
- Loading branch information
Showing
18 changed files
with
192 additions
and
107 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
File renamed without changes.
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
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 |
---|---|---|
@@ -1,13 +1,40 @@ | ||
import { useQuery } from '@tanstack/react-query'; | ||
import { checkEmpty } from '@nf-team/core'; | ||
import { useInfiniteQuery } from '@tanstack/react-query'; | ||
|
||
import { fetchGoogleSearch } from '@/lib/apis/search'; | ||
import { TextSearchPlace } from '@/lib/types/google.maps'; | ||
import { filteredPlaces } from '@/utils'; | ||
|
||
import useIntersectionObserver from '../useIntersectionObserver'; | ||
|
||
function useGetGoogleSearch({ keyword }: { keyword: string; }) { | ||
const query = useQuery([keyword], () => fetchGoogleSearch({ keyword }), { | ||
const query = useInfiniteQuery<TextSearchPlace>(['googleSearch', keyword], ({ pageParam }) => fetchGoogleSearch({ keyword, nextCursor: pageParam }), { | ||
enabled: !!keyword, | ||
getNextPageParam: ({ next_page_token }) => next_page_token, | ||
select: (response) => ({ | ||
...response, | ||
pages: checkEmpty(response?.pages).map((places) => ({ | ||
...places, | ||
results: filteredPlaces(checkEmpty(places?.results)), | ||
})), | ||
}), | ||
}); | ||
|
||
const { hasNextPage, fetchNextPage } = query; | ||
|
||
const refState = useIntersectionObserver<HTMLDivElement>({ | ||
isRoot: true, | ||
fetchNextPage, | ||
hasNextPage, | ||
intersectionOptions: { | ||
rootMargin: '80px', | ||
}, | ||
}); | ||
|
||
return query; | ||
return { | ||
query, | ||
refState, | ||
}; | ||
} | ||
|
||
export default useGetGoogleSearch; |
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.
62b2571
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
offbeat – ./
offbeat-nf-team.vercel.app
offbeat-git-main-nf-team.vercel.app
unnamed-k-place-frontend.vercel.app
offbeat.place
www.offbeat.place