-
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.
Refactor Home component to use Prisma model and add type annotations
- Loading branch information
1 parent
3761010
commit 91894fa
Showing
1 changed file
with
28 additions
and
25 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 |
---|---|---|
@@ -1,44 +1,47 @@ | ||
|
||
import { TbCoinRupee } from 'react-icons/tb'; | ||
import Container from './components/Container'; | ||
import EmptyState from './components/EmptyState'; | ||
import getListings, { IListingsParams } from './actions/getListings'; | ||
import ListingCard from './components/listings/ListingCard'; | ||
import getCurrentUser from './actions/getCurrentUser'; | ||
|
||
interface HomeProps { | ||
searchParams: IListingsParams | ||
// types.ts | ||
|
||
export interface SafeListing { | ||
id: string; | ||
title: string; | ||
description: string; | ||
price: number; | ||
locationValue: string; | ||
// Add all other fields that 'listing' might contain | ||
createdAt: string; // Make sure to convert dates to string as you're doing in getListings | ||
} | ||
|
||
interface HomeProps { | ||
searchParams: IListingsParams; | ||
} | ||
|
||
const Home = async ({searchParams}: HomeProps)=> { | ||
const listings = await getListings(searchParams) ; | ||
const Home = async ({ searchParams }: HomeProps) => { | ||
const listings = await getListings(searchParams); | ||
const currentUser = await getCurrentUser(); | ||
|
||
|
||
if(listings.length === 0) { | ||
return ( | ||
<EmptyState showReset={true} /> | ||
) | ||
if (listings.length === 0) { | ||
return <EmptyState showReset={true} />; | ||
} | ||
|
||
|
||
|
||
return ( | ||
|
||
<Container> | ||
<div className="pt-24 grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 lg:grid-cols-4 xl:grid-cols-5 2xl:grid-cols-6 gap-8"> | ||
{listings.map((listing) => ( | ||
<ListingCard | ||
key={listing.id} | ||
data={listing} | ||
currentUser={currentUser} | ||
/> | ||
))} | ||
</div> | ||
{listings.map((listing: Listing) => ( | ||
<ListingCard | ||
key={listing.id} | ||
data={listing} | ||
currentUser={currentUser} | ||
/> | ||
))} | ||
</div> | ||
</Container> | ||
|
||
) | ||
} | ||
); | ||
}; | ||
|
||
export default Home; | ||
export default Home; |