4466ba436b
## Description This PR ensures that the default prettier config is used for examples and templates. This config is compatible with `prettier@3` as well (upgrading prettier is bigger change that can be a future PR). ## Changes - Updated `.prettierrc.json` in root with `"trailingComma": "es5"` (will be needed upgrading to prettier@3) - Added `examples/.prettierrc.json` with default config (this will change every example) - Added `packages/create-next-app/templates/.prettierrc.json` with default config (this will change every template) ## Related - Fixes #54402 - Closes #54409
72 lines
2.1 KiB
TypeScript
72 lines
2.1 KiB
TypeScript
import Link from "next/link";
|
|
import dbConnect from "../lib/dbConnect";
|
|
import Pet, { Pets } from "../models/Pet";
|
|
import { GetServerSideProps } from "next";
|
|
|
|
type Props = {
|
|
pets: Pets[];
|
|
};
|
|
|
|
const Index = ({ pets }: Props) => {
|
|
return (
|
|
<>
|
|
{pets.map((pet) => (
|
|
<div key={pet._id}>
|
|
<div className="card">
|
|
<img src={pet.image_url} />
|
|
<h5 className="pet-name">{pet.name}</h5>
|
|
<div className="main-content">
|
|
<p className="pet-name">{pet.name}</p>
|
|
<p className="owner">Owner: {pet.owner_name}</p>
|
|
|
|
{/* Extra Pet Info: Likes and Dislikes */}
|
|
<div className="likes info">
|
|
<p className="label">Likes</p>
|
|
<ul>
|
|
{pet.likes.map((data, index) => (
|
|
<li key={index}>{data} </li>
|
|
))}
|
|
</ul>
|
|
</div>
|
|
<div className="dislikes info">
|
|
<p className="label">Dislikes</p>
|
|
<ul>
|
|
{pet.dislikes.map((data, index) => (
|
|
<li key={index}>{data} </li>
|
|
))}
|
|
</ul>
|
|
</div>
|
|
|
|
<div className="btn-container">
|
|
<Link href={{ pathname: "/[id]/edit", query: { id: pet._id } }}>
|
|
<button className="btn edit">Edit</button>
|
|
</Link>
|
|
<Link href={{ pathname: "/[id]", query: { id: pet._id } }}>
|
|
<button className="btn view">View</button>
|
|
</Link>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
))}
|
|
</>
|
|
);
|
|
};
|
|
|
|
/* Retrieves pet(s) data from mongodb database */
|
|
export const getServerSideProps: GetServerSideProps<Props> = async () => {
|
|
await dbConnect();
|
|
|
|
/* find all the data in our database */
|
|
const result = await Pet.find({});
|
|
|
|
/* Ensures all objectIds and nested objectIds are serialized as JSON data */
|
|
const pets = result.map((doc) => {
|
|
const pet = JSON.parse(JSON.stringify(doc));
|
|
return pet;
|
|
});
|
|
|
|
return { props: { pets: pets } };
|
|
};
|
|
|
|
export default Index;
|