Work on brewery page, refactors

Refactor query types to explicitly use z.infer
This commit is contained in:
Aaron William Po
2023-03-31 21:13:35 -04:00
parent d8a8dad37f
commit b69dbc95b4
33 changed files with 308 additions and 243 deletions

View File

@@ -5,13 +5,14 @@ import React from 'react';
import Layout from '@/components/ui/Layout';
import withPageAuthRequired from '@/getServerSideProps/withPageAuthRequired';
import getBeerPostById from '@/services/BeerPost/getBeerPostById';
import { BeerPostQueryResult } from '@/services/BeerPost/schema/BeerPostQueryResult';
import beerPostQueryResult from '@/services/BeerPost/schema/BeerPostQueryResult';
import EditBeerPostForm from '@/components/EditBeerPostForm';
import FormPageLayout from '@/components/ui/forms/FormPageLayout';
import { BiBeer } from 'react-icons/bi';
import { z } from 'zod';
interface EditPageProps {
beerPost: BeerPostQueryResult;
beerPost: z.infer<typeof beerPostQueryResult>;
}
const EditPage: NextPage<EditPageProps> = ({ beerPost }) => {

View File

@@ -11,19 +11,20 @@ import getAllBeerComments from '@/services/BeerComment/getAllBeerComments';
import getBeerPostById from '@/services/BeerPost/getBeerPostById';
import getBeerRecommendations from '@/services/BeerPost/getBeerRecommendations';
import { BeerCommentQueryResultArrayT } from '@/services/BeerComment/schema/BeerCommentQueryResult';
import { BeerPostQueryResult } from '@/services/BeerPost/schema/BeerPostQueryResult';
import beerPostQueryResult from '@/services/BeerPost/schema/BeerPostQueryResult';
import { BeerPost } from '@prisma/client';
import getBeerPostLikeCount from '@/services/BeerPostLike/getBeerPostLikeCount';
import getBeerCommentCount from '@/services/BeerComment/getBeerCommentCount';
import { z } from 'zod';
import BeerCommentQueryResult from '@/services/BeerComment/schema/BeerCommentQueryResult';
interface BeerPageProps {
beerPost: BeerPostQueryResult;
beerPost: z.infer<typeof beerPostQueryResult>;
beerRecommendations: (BeerPost & {
brewery: { id: string; name: string };
beerImages: { id: string; alt: string; url: string }[];
})[];
beerComments: BeerCommentQueryResultArrayT;
beerComments: z.infer<typeof BeerCommentQueryResult>[];
commentsPageCount: number;
likeCount: number;
}

View File

@@ -8,9 +8,10 @@ import BreweryPostQueryResult from '@/services/BreweryPost/types/BreweryPostQuer
import { BeerType } from '@prisma/client';
import { NextPage } from 'next';
import { BiBeer } from 'react-icons/bi';
import { z } from 'zod';
interface CreateBeerPageProps {
breweries: BreweryPostQueryResult[];
breweries: z.infer<typeof BreweryPostQueryResult>[];
types: BeerType[];
}

View File

@@ -6,11 +6,12 @@ import DBClient from '@/prisma/DBClient';
import Layout from '@/components/ui/Layout';
import BeerIndexPaginationBar from '@/components/BeerIndex/BeerIndexPaginationBar';
import BeerCard from '@/components/BeerIndex/BeerCard';
import { BeerPostQueryResult } from '@/services/BeerPost/schema/BeerPostQueryResult';
import beerPostQueryResult from '@/services/BeerPost/schema/BeerPostQueryResult';
import Head from 'next/head';
import { z } from 'zod';
interface BeerPageProps {
initialBeerPosts: BeerPostQueryResult[];
initialBeerPosts: z.infer<typeof beerPostQueryResult>[];
pageCount: number;
}

View File

@@ -14,8 +14,8 @@ const DEBOUNCE_DELAY = 300;
const SearchPage: NextPage = () => {
const router = useRouter();
const querySearch = router.query.search as string | undefined;
const [searchValue, setSearchValue] = useState(querySearch || '');
const querySearch = (router.query.search as string) || '';
const [searchValue, setSearchValue] = useState(querySearch);
const { searchResults, isLoading, searchError } = useBeerPostSearch(searchValue);
const debounceSearch = debounce((value: string) => {
@@ -36,7 +36,7 @@ const SearchPage: NextPage = () => {
if (!querySearch || searchValue) {
return;
}
setSearchValue(searchValue);
setSearchValue(querySearch);
}, DEBOUNCE_DELAY)();
}, [querySearch, searchValue]);