mirror of
https://github.com/aaronpo97/the-biergarten-app.git
synced 2026-02-16 10:42:08 +00:00
Add date established to brewery page
This commit is contained in:
@@ -46,7 +46,7 @@ const BeerCard: FC<{ post: z.infer<typeof beerPostQueryResult> }> = ({ post }) =
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex justify-between">
|
||||
liked by {likeCount} users
|
||||
<span>liked by {likeCount} users</span>
|
||||
{user && <BeerPostLikeButton beerPostId={post.id} mutateCount={mutate} />}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -2,7 +2,7 @@ import UserContext from '@/contexts/userContext';
|
||||
import useGetBreweryPostLikeCount from '@/hooks/useGetBreweryPostLikeCount';
|
||||
import BreweryPostQueryResult from '@/services/BreweryPost/types/BreweryPostQueryResult';
|
||||
import { FC, useContext } from 'react';
|
||||
import { Link } from 'react-daisyui';
|
||||
import Link from 'next/link';
|
||||
import { z } from 'zod';
|
||||
import Image from 'next/image';
|
||||
import BreweryPostLikeButton from './BreweryPostLikeButton';
|
||||
@@ -24,19 +24,28 @@ const BreweryCard: FC<{ brewery: z.infer<typeof BreweryPostQueryResult> }> = ({
|
||||
/>
|
||||
)}
|
||||
</figure>
|
||||
<div className="card-body space-y-3">
|
||||
<div className="card-body">
|
||||
<div>
|
||||
<h2 className="text-3xl font-bold">
|
||||
<Link href={`/breweries/${brewery.id}`}>{brewery.name}</Link>
|
||||
<h2 className="mb-2 text-2xl font-bold lg:text-3xl">
|
||||
<Link href={`/breweries/${brewery.id}`} className="link-hover link">
|
||||
{brewery.name}
|
||||
</Link>
|
||||
</h2>
|
||||
<h3 className="text-xl font-semibold">{brewery.location}</h3>
|
||||
<h3 className="text-xl font-normal lg:text-2xl">
|
||||
located in {brewery.location}
|
||||
</h3>
|
||||
<h4 className="text-lg lg:text-xl">
|
||||
est. {brewery.dateEstablished.getFullYear()}
|
||||
</h4>
|
||||
</div>
|
||||
liked by {likeCount} users
|
||||
<div className="flex justify-between">
|
||||
<span>liked by {likeCount} users</span>
|
||||
{user && (
|
||||
<BreweryPostLikeButton breweryPostId={brewery.id} mutateCount={mutate} />
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
@@ -34,14 +34,17 @@ const BeerPage: NextPage = () => {
|
||||
return (
|
||||
<>
|
||||
<Head>
|
||||
<title>Beer</title>
|
||||
<meta name="description" content="Beer posts" />
|
||||
<title>Beers | The Biergarten App</title>
|
||||
<meta
|
||||
name="description"
|
||||
content="Find beers made by breweries near you and around the world."
|
||||
/>
|
||||
</Head>
|
||||
<div className="flex items-center justify-center bg-base-100" ref={pageRef}>
|
||||
<div className="my-10 flex w-10/12 flex-col space-y-4 lg:w-8/12 2xl:w-7/12">
|
||||
<header className="my-10 flex justify-between lg:flex-row">
|
||||
<div>
|
||||
<h1 className="text-4xl font-bold lg:text-6xl">The Biergarten Index</h1>
|
||||
<h1 className="text-4xl font-bold lg:text-6xl">The Biergarten App</h1>
|
||||
<h2 className="text-2xl font-bold lg:text-4xl">Beers</h2>
|
||||
</div>
|
||||
{!!user && (
|
||||
|
||||
@@ -5,6 +5,7 @@ import UserContext from '@/contexts/userContext';
|
||||
import useBreweryPosts from '@/hooks/useBreweryPosts';
|
||||
import BreweryPostQueryResult from '@/services/BreweryPost/types/BreweryPostQueryResult';
|
||||
import { NextPage } from 'next';
|
||||
import Head from 'next/head';
|
||||
import { useContext, MutableRefObject, useRef } from 'react';
|
||||
import { Link } from 'react-daisyui';
|
||||
import { FaPlus, FaArrowUp } from 'react-icons/fa';
|
||||
@@ -34,11 +35,19 @@ const BreweryPage: NextPage<BreweryPageProps> = () => {
|
||||
|
||||
const pageRef: MutableRefObject<HTMLDivElement | null> = useRef(null);
|
||||
return (
|
||||
<>
|
||||
<Head>
|
||||
<title>Breweries</title>
|
||||
<meta
|
||||
name="description"
|
||||
content="Find breweries near you and around the world."
|
||||
/>
|
||||
</Head>
|
||||
<div className="flex items-center justify-center bg-base-100" ref={pageRef}>
|
||||
<div className="my-10 flex w-10/12 flex-col space-y-4 lg:w-8/12 2xl:w-7/12">
|
||||
<header className="my-10 flex justify-between lg:flex-row">
|
||||
<div>
|
||||
<h1 className="text-4xl font-bold lg:text-6xl">The Biergarten Index</h1>
|
||||
<h1 className="text-4xl font-bold lg:text-6xl">The Biergarten App</h1>
|
||||
<h2 className="text-2xl font-bold lg:text-4xl">Breweries</h2>
|
||||
</div>
|
||||
{!!user && (
|
||||
@@ -109,6 +118,7 @@ const BreweryPage: NextPage<BreweryPageProps> = () => {
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
2
src/prisma/migrations/20230423235322_/migration.sql
Normal file
2
src/prisma/migrations/20230423235322_/migration.sql
Normal file
@@ -0,0 +1,2 @@
|
||||
-- AlterTable
|
||||
ALTER TABLE "BreweryPost" ADD COLUMN "dateEstablished" TIMESTAMPTZ(3) NOT NULL DEFAULT CURRENT_TIMESTAMP;
|
||||
@@ -105,7 +105,8 @@ model BreweryPost {
|
||||
postedById String
|
||||
breweryComments BreweryComment[]
|
||||
breweryImages BreweryImage[]
|
||||
BreweryPostLike BreweryPostLike[]
|
||||
breweryPostLike BreweryPostLike[]
|
||||
dateEstablished DateTime @default(now()) @db.Timestamptz(3)
|
||||
}
|
||||
|
||||
model BreweryComment {
|
||||
|
||||
@@ -24,6 +24,8 @@ const createNewBreweryPosts = async ({
|
||||
const description = faker.lorem.lines(5);
|
||||
const user = users[Math.floor(Math.random() * users.length)];
|
||||
const createdAt = faker.date.past(1);
|
||||
const dateEstablished = faker.date.past(40);
|
||||
|
||||
breweryPromises.push(
|
||||
prisma.breweryPost.create({
|
||||
data: {
|
||||
@@ -32,6 +34,7 @@ const createNewBreweryPosts = async ({
|
||||
description,
|
||||
postedBy: { connect: { id: user.id } },
|
||||
createdAt,
|
||||
dateEstablished,
|
||||
},
|
||||
}),
|
||||
);
|
||||
|
||||
@@ -23,6 +23,7 @@ const getAllBeerPosts = async (pageNum: number, pageSize: number) => {
|
||||
},
|
||||
take: pageSize,
|
||||
skip,
|
||||
orderBy: { createdAt: 'desc' },
|
||||
},
|
||||
);
|
||||
|
||||
|
||||
@@ -18,7 +18,10 @@ const getAllBreweryPosts = async (pageNum?: number, pageSize?: number) => {
|
||||
name: true,
|
||||
postedBy: { select: { username: true, id: true } },
|
||||
breweryImages: { select: { path: true, caption: true, id: true, alt: true } },
|
||||
createdAt: true,
|
||||
dateEstablished: true,
|
||||
},
|
||||
orderBy: { createdAt: 'desc' },
|
||||
});
|
||||
|
||||
return breweryPosts;
|
||||
|
||||
@@ -13,6 +13,8 @@ const getBreweryPostById = async (id: string) => {
|
||||
name: true,
|
||||
breweryImages: { select: { path: true, caption: true, id: true, alt: true } },
|
||||
postedBy: { select: { username: true, id: true } },
|
||||
createdAt: true,
|
||||
dateEstablished: true,
|
||||
},
|
||||
where: { id },
|
||||
});
|
||||
|
||||
@@ -8,6 +8,8 @@ const BreweryPostQueryResult = z.object({
|
||||
breweryImages: z.array(
|
||||
z.object({ path: z.string(), caption: z.string(), id: z.string(), alt: z.string() }),
|
||||
),
|
||||
createdAt: z.coerce.date(),
|
||||
dateEstablished: z.coerce.date(),
|
||||
});
|
||||
|
||||
export default BreweryPostQueryResult;
|
||||
|
||||
Reference in New Issue
Block a user