generated from 202306-NEA-DZ-FEW/capstone-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(single item page): add single item page
feat #4
- Loading branch information
1 parent
293299d
commit 567b5ea
Showing
1 changed file
with
66 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import { | ||
getDocData, | ||
getItemByCategory, | ||
} from "@/lib/firebase/firestoreFunctions"; | ||
|
||
import ItemCard from "@/components/itemcard/ItemCard"; | ||
import SingleItemCard from "@/components/singleitemcard/SingleItemCard"; | ||
|
||
function ItemPage({ item, otherItems }) { | ||
// otherItems = [otherItems[0], otherItems[1], otherItems[0], otherItems[1]]; | ||
const { | ||
title, | ||
description, | ||
updatedAt, | ||
categories, | ||
imagesList, | ||
location, | ||
userData, | ||
userId, | ||
} = item; | ||
return ( | ||
<> | ||
<SingleItemCard | ||
images={imagesList} | ||
title={title} | ||
description={description} | ||
location={location} | ||
name={userData.name} | ||
phone={userData.phone} | ||
email={userData.email} | ||
/> | ||
<div className='mt-12 border-t border-slate-300'> | ||
<h2 className='text-4xl font-semi my-4'>Related items</h2> | ||
<div className='flex flex-wrap gap-5 justify-start '> | ||
{otherItems.map((element) => ( | ||
<ItemCard item={element} key={element.id} /> | ||
))} | ||
</div> | ||
</div> | ||
</> | ||
); | ||
} | ||
|
||
export async function getStaticProps({ params }) { | ||
let item = await getDocData("items", params.id); | ||
item = JSON.parse(JSON.stringify(item)); | ||
|
||
let otherItems = await getItemByCategory(item.categories); | ||
otherItems = JSON.parse(JSON.stringify(otherItems)); | ||
|
||
return { | ||
props: { | ||
item, | ||
otherItems, | ||
}, | ||
|
||
revalidate: 10, | ||
}; | ||
} | ||
|
||
export async function getStaticPaths() { | ||
const paths = [{ params: { id: "51ODFz5Jd1DAQlM2CpMH" } }]; | ||
return { paths, fallback: "blocking" }; | ||
} | ||
|
||
export default ItemPage; |