mirror of
https://github.com/hanzoai/next.js.git
synced 2026-10-30 14:46:38 +00:00
Enable prettier for turbopack While the majority of the javascript in turbopack is for tests, this code is generally hand authored so prettier will help us. There are also core parts of turbopack implemented in JavaScript/TypeScript so a formatter will help. This was done by simply fixing prettier ignore and chasing lint errors. There were a few fun issues * We had a test file called `won't-run-tla.js` and this triggered a bug in our eslint precommit hook. The simplest thing was to simply drop the `'` character so that is what i did. I spent a small amount of time trying to narrow this down't in the `lint-staged` dependency but failed, so i think the problem is probably in `eslint`, but it isn't really clear. * We had another test exercising `import.meta` but in a file called `.cjs`, which prettier rejects due its default `babel` parser. So i excluded this from prettier.
66 lines
1.8 KiB
JavaScript
66 lines
1.8 KiB
JavaScript
import Link from 'next/link'
|
|
import dbConnect from '../lib/dbConnect'
|
|
import Pet from '../models/Pet'
|
|
|
|
const Index = ({ pets }) => (
|
|
<>
|
|
{/* Create a card for each pet */}
|
|
{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="/[id]/edit" as={`/${pet._id}/edit`}>
|
|
<button className="btn edit">Edit</button>
|
|
</Link>
|
|
<Link href="/[id]" as={`/${pet._id}`}>
|
|
<button className="btn view">View</button>
|
|
</Link>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
))}
|
|
</>
|
|
)
|
|
|
|
/* Retrieves pet(s) data from mongodb database */
|
|
export async function getServerSideProps() {
|
|
await dbConnect()
|
|
|
|
/* find all the data in our database */
|
|
const result = await Pet.find({})
|
|
const pets = result.map((doc) => {
|
|
const pet = doc.toObject()
|
|
pet._id = pet._id.toString()
|
|
return pet
|
|
})
|
|
|
|
return { props: { pets: pets } }
|
|
}
|
|
|
|
export default Index
|