Files
Luke SandbergandGitHub eaad5b4c14 Enable prettier for turbopack (#78559)
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.
2025-04-29 11:38:46 -07:00

76 lines
2.0 KiB
JavaScript

import { useState } from 'react'
import { useRouter } from 'next/router'
import Link from 'next/link'
import dbConnect from '../../lib/dbConnect'
import Pet from '../../models/Pet'
/* Allows you to view pet card info and delete pet card*/
const PetPage = ({ pet }) => {
const router = useRouter()
const [message, setMessage] = useState('')
const handleDelete = async () => {
const petID = router.query.id
try {
await fetch(`/api/pets/${petID}`, {
method: 'Delete',
})
router.push('/')
} catch (error) {
setMessage('Failed to delete the pet.')
}
}
return (
<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>
<button className="btn delete" onClick={handleDelete}>
Delete
</button>
</div>
</div>
</div>
{message && <p>{message}</p>}
</div>
)
}
export async function getServerSideProps({ params }) {
await dbConnect()
const pet = await Pet.findById(params.id).lean()
pet._id = pet._id.toString()
return { props: { pet } }
}
export default PetPage