Refactor: force style consistency for pagination queries

All pagination queries now use an underscore for page_num, and page_size
This commit is contained in:
Aaron William Po
2023-05-02 23:45:32 -04:00
parent c5b546dcf6
commit b7b239a4a1
7 changed files with 33 additions and 33 deletions

View File

@@ -1,6 +1,6 @@
{ {
"arrowParens": "always", "arrowParens": "always",
"bracketSpacing": false, "bracketSpacing": true,
"jsxSingleQuote": false, "jsxSingleQuote": false,
"printWidth": 90, "printWidth": 90,
"proseWrap": "always", "proseWrap": "always",

View File

@@ -1,4 +1,4 @@
import {FC} from 'react'; import { FC } from 'react';
import Spinner from '../ui/Spinner'; import Spinner from '../ui/Spinner';
import CommentLoadingCardBody from '../BeerBreweryComments/CommentLoadingCardBody'; import CommentLoadingCardBody from '../BeerBreweryComments/CommentLoadingCardBody';
@@ -6,10 +6,10 @@ interface LoadingComponentProps {
length: number; length: number;
} }
const LoadingComponent: FC<LoadingComponentProps> = ({length}) => { const LoadingComponent: FC<LoadingComponentProps> = ({ length }) => {
return ( return (
<> <>
{Array.from({length}).map((_, i) => ( {Array.from({ length }).map((_, i) => (
<CommentLoadingCardBody key={i} /> <CommentLoadingCardBody key={i} />
))} ))}
<div className="p-1"> <div className="p-1">

View File

@@ -1,7 +1,7 @@
import {FC, MutableRefObject} from 'react'; import { FC, MutableRefObject } from 'react';
import {FaArrowUp} from 'react-icons/fa'; import { FaArrowUp } from 'react-icons/fa';
import {useInView} from 'react-intersection-observer'; import { useInView } from 'react-intersection-observer';
import useBeerPostComments from '@/hooks/data-fetching/beer-comments/useBeerPostComments'; import useBeerPostComments from '@/hooks/data-fetching/beer-comments/useBeerPostComments';
@@ -41,7 +41,7 @@ const CommentsComponent: FC<CommentsComponentProps> = ({
size, size,
mutate, mutate,
}) => { }) => {
const {ref: penultimateCommentRef} = useInView({ const { ref: penultimateCommentRef } = useInView({
/** /**
* When the second last comment comes into view, call setSize from useBeerPostComments * When the second last comment comes into view, call setSize from useBeerPostComments
* to load more comments. * to load more comments.

View File

@@ -38,7 +38,7 @@ const useBeerPosts = ({ pageSize }: { pageSize: number }) => {
}; };
const { data, error, isLoading, setSize, size } = useSWRInfinite( const { data, error, isLoading, setSize, size } = useSWRInfinite(
(index) => `/api/beers?pageNum=${index + 1}&pageSize=${pageSize}`, (index) => `/api/beers?page_num=${index + 1}&page_size=${pageSize}`,
fetcher, fetcher,
); );

View File

@@ -38,7 +38,7 @@ const useBreweryPosts = ({ pageSize }: { pageSize: number }) => {
}; };
const { data, error, isLoading, setSize, size } = useSWRInfinite( const { data, error, isLoading, setSize, size } = useSWRInfinite(
(index) => `/api/breweries?pageNum=${index + 1}&pageSize=${pageSize}`, (index) => `/api/breweries?page_num=${index + 1}&page_size=${pageSize}`,
fetcher, fetcher,
); );

View File

@@ -9,8 +9,8 @@ import { z } from 'zod';
interface GetBeerPostsRequest extends NextApiRequest { interface GetBeerPostsRequest extends NextApiRequest {
query: { query: {
pageNum: string; page_num: string;
pageSize: string; page_size: string;
}; };
} }
@@ -18,8 +18,8 @@ const getBeerPosts = async (
req: GetBeerPostsRequest, req: GetBeerPostsRequest,
res: NextApiResponse<z.infer<typeof APIResponseValidationSchema>>, res: NextApiResponse<z.infer<typeof APIResponseValidationSchema>>,
) => { ) => {
const pageNum = parseInt(req.query.pageNum, 10); const pageNum = parseInt(req.query.page_num, 10);
const pageSize = parseInt(req.query.pageSize, 10); const pageSize = parseInt(req.query.page_size, 10);
const beerPosts = await getAllBeerPosts(pageNum, pageSize); const beerPosts = await getAllBeerPosts(pageNum, pageSize);
const beerPostCount = await DBClient.instance.beerPost.count(); const beerPostCount = await DBClient.instance.beerPost.count();
@@ -42,8 +42,8 @@ const router = createRouter<
router.get( router.get(
validateRequest({ validateRequest({
querySchema: z.object({ querySchema: z.object({
pageNum: z.string().regex(/^\d+$/), page_num: z.string().regex(/^\d+$/),
pageSize: z.string().regex(/^\d+$/), page_size: z.string().regex(/^\d+$/),
}), }),
}), }),
getBeerPosts, getBeerPosts,

View File

@@ -9,8 +9,8 @@ import { z } from 'zod';
interface GetBreweryPostsRequest extends NextApiRequest { interface GetBreweryPostsRequest extends NextApiRequest {
query: { query: {
pageNum: string; page_num: string;
pageSize: string; page_size: string;
}; };
} }
@@ -18,8 +18,8 @@ const getBreweryPosts = async (
req: GetBreweryPostsRequest, req: GetBreweryPostsRequest,
res: NextApiResponse<z.infer<typeof APIResponseValidationSchema>>, res: NextApiResponse<z.infer<typeof APIResponseValidationSchema>>,
) => { ) => {
const pageNum = parseInt(req.query.pageNum, 10); const pageNum = parseInt(req.query.page_num, 10);
const pageSize = parseInt(req.query.pageSize, 10); const pageSize = parseInt(req.query.page_size, 10);
const breweryPosts = await getAllBreweryPosts(pageNum, pageSize); const breweryPosts = await getAllBreweryPosts(pageNum, pageSize);
const breweryPostCount = await DBClient.instance.breweryPost.count(); const breweryPostCount = await DBClient.instance.breweryPost.count();
@@ -42,8 +42,8 @@ const router = createRouter<
router.get( router.get(
validateRequest({ validateRequest({
querySchema: z.object({ querySchema: z.object({
pageNum: z.string().regex(/^\d+$/), page_num: z.string().regex(/^\d+$/),
pageSize: z.string().regex(/^\d+$/), page_size: z.string().regex(/^\d+$/),
}), }),
}), }),
getBreweryPosts, getBreweryPosts,