feat: Initialize project
This commit is contained in:
1 parent
eccc32337f
commit
3c1050898e
65 files changed
+5661
-596
No files matched your search
@@ -0,0 +1,32 @@
|
||||
'use client';
|
||||
|
||||
import { useInfiniteQuery } from '@tanstack/react-query';
|
||||
import { useSearchParams } from 'next/navigation';
|
||||
|
||||
import API from './api';
|
||||
|
||||
const useTop = () => {
|
||||
const page = useSearchParams().get('page');
|
||||
|
||||
return useInfiniteQuery({
|
||||
queryKey: ['top'],
|
||||
queryFn: ({ pageParam: page }) => API.top({ page }),
|
||||
suspense: true,
|
||||
getNextPageParam({ page, total_pages }) {
|
||||
if (page === total_pages) return undefined;
|
||||
|
||||
if (typeof window !== 'undefined') {
|
||||
const url = new URL(location.href);
|
||||
|
||||
url.searchParams.set('page', page.toString());
|
||||
|
||||
window.history.pushState(null, '', url.href);
|
||||
}
|
||||
|
||||
return `${page + 1}`;
|
||||
},
|
||||
defaultPageParam: page || '1'
|
||||
});
|
||||
};
|
||||
|
||||
export default useTop;
|
||||
Reference in new issue
Block a user