mirror of
https://github.com/aaronpo97/the-biergarten-app.git
synced 2026-02-16 10:42:08 +00:00
Refactor beer by id page
Extracted services to separate files.
This commit is contained in:
@@ -1,10 +1,9 @@
|
|||||||
import sendCreateBeerCommentRequest from '@/requests/sendCreateBeerCommentRequest';
|
import sendCreateBeerCommentRequest from '@/requests/sendCreateBeerCommentRequest';
|
||||||
import { BeerCommentQueryResultArrayT } from '@/services/BeerComment/schema/BeerCommentQueryResult';
|
|
||||||
import BeerCommentValidationSchema from '@/services/BeerComment/schema/CreateBeerCommentValidationSchema';
|
import BeerCommentValidationSchema from '@/services/BeerComment/schema/CreateBeerCommentValidationSchema';
|
||||||
import { BeerPostQueryResult } from '@/services/BeerPost/schema/BeerPostQueryResult';
|
import { BeerPostQueryResult } from '@/services/BeerPost/schema/BeerPostQueryResult';
|
||||||
import { zodResolver } from '@hookform/resolvers/zod';
|
import { zodResolver } from '@hookform/resolvers/zod';
|
||||||
import { useRouter } from 'next/router';
|
import { useRouter } from 'next/router';
|
||||||
import { Dispatch, SetStateAction, FunctionComponent, useState, useEffect } from 'react';
|
import { FunctionComponent, useState, useEffect } from 'react';
|
||||||
import { Rating } from 'react-daisyui';
|
import { Rating } from 'react-daisyui';
|
||||||
import { useForm, SubmitHandler } from 'react-hook-form';
|
import { useForm, SubmitHandler } from 'react-hook-form';
|
||||||
import { z } from 'zod';
|
import { z } from 'zod';
|
||||||
@@ -18,7 +17,6 @@ import FormTextArea from '../ui/forms/FormTextArea';
|
|||||||
|
|
||||||
interface BeerCommentFormProps {
|
interface BeerCommentFormProps {
|
||||||
beerPost: BeerPostQueryResult;
|
beerPost: BeerPostQueryResult;
|
||||||
setComments: Dispatch<SetStateAction<BeerCommentQueryResultArrayT>>;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const BeerCommentForm: FunctionComponent<BeerCommentFormProps> = ({ beerPost }) => {
|
const BeerCommentForm: FunctionComponent<BeerCommentFormProps> = ({ beerPost }) => {
|
||||||
|
|||||||
@@ -9,14 +9,13 @@ import CommentCard from './CommentCard';
|
|||||||
|
|
||||||
interface BeerPostCommentsSectionProps {
|
interface BeerPostCommentsSectionProps {
|
||||||
beerPost: BeerPostQueryResult;
|
beerPost: BeerPostQueryResult;
|
||||||
setComments: React.Dispatch<React.SetStateAction<BeerCommentQueryResultArrayT>>;
|
|
||||||
comments: BeerCommentQueryResultArrayT;
|
comments: BeerCommentQueryResultArrayT;
|
||||||
commentsPageCount: number;
|
commentsPageCount: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
const BeerPostCommentsSection: FC<BeerPostCommentsSectionProps> = ({
|
const BeerPostCommentsSection: FC<BeerPostCommentsSectionProps> = ({
|
||||||
beerPost,
|
beerPost,
|
||||||
setComments,
|
|
||||||
comments,
|
comments,
|
||||||
commentsPageCount,
|
commentsPageCount,
|
||||||
}) => {
|
}) => {
|
||||||
@@ -30,7 +29,7 @@ const BeerPostCommentsSection: FC<BeerPostCommentsSectionProps> = ({
|
|||||||
<div className="card h-96 bg-base-300">
|
<div className="card h-96 bg-base-300">
|
||||||
<div className="card-body h-full">
|
<div className="card-body h-full">
|
||||||
{user ? (
|
{user ? (
|
||||||
<BeerCommentForm beerPost={beerPost} setComments={setComments} />
|
<BeerCommentForm beerPost={beerPost} />
|
||||||
) : (
|
) : (
|
||||||
<div className="flex h-full flex-col items-center justify-center">
|
<div className="flex h-full flex-col items-center justify-center">
|
||||||
<span className="text-lg font-bold">Log in to leave a comment.</span>
|
<span className="text-lg font-bold">Log in to leave a comment.</span>
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ const Navbar = () => {
|
|||||||
return (
|
return (
|
||||||
<nav className="navbar bg-primary text-primary-content">
|
<nav className="navbar bg-primary text-primary-content">
|
||||||
<div className="flex-1">
|
<div className="flex-1">
|
||||||
<Link className="btn btn-ghost text-3xl normal-case" href="/">
|
<Link className="btn-ghost btn text-3xl normal-case" href="/">
|
||||||
<span className="cursor-pointer text-xl font-bold">The Biergarten App</span>
|
<span className="cursor-pointer text-xl font-bold">The Biergarten App</span>
|
||||||
</Link>
|
</Link>
|
||||||
</div>
|
</div>
|
||||||
@@ -68,8 +68,8 @@ const Navbar = () => {
|
|||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
<div className="flex-none lg:hidden">
|
<div className="flex-none lg:hidden">
|
||||||
<div className="dropdown dropdown-end">
|
<div className="dropdown-end dropdown">
|
||||||
<label tabIndex={0} className="btn btn-ghost btn-circle">
|
<label tabIndex={0} className="btn-ghost btn-circle btn">
|
||||||
<span className="w-10 rounded-full">
|
<span className="w-10 rounded-full">
|
||||||
<svg
|
<svg
|
||||||
xmlns="http://www.w3.org/2000/svg"
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
|
|||||||
11
services/BeerComment/getBeerCommentCount.ts
Normal file
11
services/BeerComment/getBeerCommentCount.ts
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
import DBClient from '@/prisma/DBClient';
|
||||||
|
|
||||||
|
const getBeerCommentCount = async (beerPostId: string) => {
|
||||||
|
const count = await DBClient.instance.beerComment.count({
|
||||||
|
where: { beerPostId },
|
||||||
|
});
|
||||||
|
|
||||||
|
return count;
|
||||||
|
};
|
||||||
|
|
||||||
|
export default getBeerCommentCount;
|
||||||
11
services/BeerPostLike/getBeerPostLikeCount.ts
Normal file
11
services/BeerPostLike/getBeerPostLikeCount.ts
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
import DBClient from '@/prisma/DBClient';
|
||||||
|
|
||||||
|
const getBeerPostLikeCount = async (beerPostId: string) => {
|
||||||
|
const count = await DBClient.instance.beerPostLike.count({
|
||||||
|
where: { beerPostId },
|
||||||
|
});
|
||||||
|
|
||||||
|
return count;
|
||||||
|
};
|
||||||
|
|
||||||
|
export default getBeerPostLikeCount;
|
||||||
Reference in New Issue
Block a user