Properties Page

Creating Properties Page Components

Preparations

Add properties.json file in your project root directory:

properties.json
properties.json
// properties.json
[
  {
    "_id": "1",
    "owner": "1",
    "name": "Boston Commons Retreat",
    "type": "Apartment",
    "description": "This is a beautiful apartment located near the commons. It is a 2 bedroom apartment with a full kitchen and bathroom. It is available for weekly or monthly rentals.",
    "location": {
      "street": "120 Tremont Street",
      "city": "Boston",
      "state": "MA",
      "zipcode": "02108"
    },
    "beds": 2,
    "baths": 1,
    "square_feet": 1500,
    "amenities": [
      "Wifi",
      "Full kitchen",
      "Washer & Dryer",
      "Free Parking",
      "Hot Tub",
      "24/7 Security",
      "Wheelchair Accessible",
      "Elevator Access",
      "Dishwasher",
      "Gym/Fitness Center",
      "Air Conditioning",
      "Balcony/Patio",
      "Smart TV",
      "Coffee Maker"
    ],
    "rates": {
      "weekly": 1100,
      "monthly": 4200
    },
    "seller_info": {
      "name": "John Doe",
      "email": "[email protected]",
      "phone": "617-555-5555"
    },
    "images": ["a1.jpg", "a2.jpg", "a3.jpg"],
    "is_featured": false,
    "createdAt": "2024-01-01T00:00:00.000Z",
    "updatedAt": "2024-01-01T00:00:00.000Z"
  },
  {
    "_id": "2",
    "owner": "1",
    "name": "Cozy Downtown Loft",
    "type": "Apartment",
    "description": "A cozy downtown loft with great city views.",
    "location": {
      "street": "45 Main Street",
      "city": "New York",
      "state": "NY",
      "zipcode": "10001"
    },
    "beds": 1,
    "baths": 1,
    "square_feet": 1800,
    "amenities": [
      "Wifi",
      "Full kitchen",
      "Washer & Dryer",
      "Free Parking",
      "Hot Tub",
      "24/7 Security",
      "Wheelchair Accessible",
      "Elevator Access",
      "Dishwasher",
      "High-Speed Internet",
      "Air Conditioning",
      "Smart TV",
      "Outdoor Grill/BBQ"
    ],
    "rates": {
      "weekly": 1000,
      "monthly": 4000
    },
    "seller_info": {
      "name": "Jane Smith",
      "email": "[email protected]",
      "phone": "212-555-5555"
    },
    "images": ["b1.jpg", "b2.jpg", "b3.jpg"],
    "is_featured": false,
    "createdAt": "2024-01-02T00:00:00.000Z",
    "updatedAt": "2024-01-02T00:00:00.000Z"
  },
  {
    "_id": "3",
    "owner": "2",
    "name": "Luxury Condo with a View",
    "type": "Condo",
    "description": "Experience luxury in this stunning condo with breathtaking views.",
    "location": {
      "street": "500 Lux Lane",
      "city": "Los Angeles",
      "state": "CA",
      "zipcode": "90001"
    },
    "beds": 3,
    "baths": 2,
    "square_feet": 2200,
    "amenities": [
      "Wifi",
      "Full kitchen",
      "Washer & Dryer",
      "Free Parking",
      "Hot Tub",
      "24/7 Security",
      "Wheelchair Accessible",
      "Elevator Access",
      "Dishwasher",
      "Swimming Pool",
      "Gym/Fitness Center",
      "Air Conditioning",
      "Smart TV",
      "Coffee Maker"
    ],
    "rates": {
      "nightly": 200,
      "weekly": 750,
      "monthly": 3300
    },
    "seller_info": {
      "name": "David Johnson",
      "email": "[email protected]",
      "phone": "213-555-5555"
    },
    "images": ["c1.jpg", "c2.jpg", "c3.jpg"],
    "is_featured": false,
    "createdAt": "2024-01-03T00:00:00.000Z",
    "updatedAt": "2024-01-03T00:00:00.000Z"
  },
  {
    "_id": "4",
    "owner": "2",
    "name": "Charming Cottage Getaway",
    "type": "Cottage Or Cabin",
    "description": "Escape to this charming cottage for a peaceful retreat.",
    "location": {
      "street": "123 Countryside Lane",
      "city": "Austin",
      "state": "TX",
      "zipcode": "78701"
    },
    "beds": 1,
    "baths": 1,
    "square_feet": 900,
    "amenities": [
      "Fireplace",
      "Outdoor Grill/BBQ",
      "Balcony/Patio",
      "Coffee Maker"
    ],
    "rates": {
      "weekly": 2000
    },
    "seller_info": {
      "name": "Emily Davis",
      "email": "[email protected]",
      "phone": "512-555-5555"
    },
    "images": ["d1.jpg", "d2.jpg", "d3.jpg"],
    "is_featured": false,
    "createdAt": "2024-01-04T00:00:00.000Z",
    "updatedAt": "2024-01-04T00:00:00.000Z"
  },
  {
    "_id": "5",
    "owner": "3",
    "name": "Modern Downtown Studio",
    "type": "Studio",
    "description": "Stay in style in this modern downtown studio apartment.",
    "location": {
      "street": "75 Urban Avenue",
      "city": "Chicago",
      "state": "IL",
      "zipcode": "60601"
    },
    "beds": 1,
    "baths": 1,
    "square_feet": 900,
    "amenities": [
      "High-Speed Internet",
      "Smart TV",
      "Air Conditioning",
      "Gym/Fitness Center",
      "Outdoor Grill/BBQ"
    ],
    "rates": {
      "weekly": 1100,
      "monthly": 4200
    },
    "seller_info": {
      "name": "Michael Brown",
      "email": "[email protected]",
      "phone": "312-555-5555"
    },
    "images": ["e1.jpg", "e2.jpg", "e3.jpg"],
    "is_featured": true,
    "createdAt": "2024-01-05T00:00:00.000Z",
    "updatedAt": "2024-01-05T00:00:00.000Z"
  },
  {
    "_id": "6",
    "owner": "3",
    "name": "Seaside Retreat",
    "type": "House",
    "description": "Escape to this seaside house for a relaxing getaway.",
    "location": {
      "street": "456 Oceanfront Drive",
      "city": "Miami",
      "state": "FL",
      "zipcode": "33101"
    },
    "beds": 4,
    "baths": 3,
    "square_feet": 2800,
    "amenities": [
      "Beach Access",
      "Swimming Pool",
      "Balcony/Patio",
      "Smart TV",
      "Outdoor Grill/BBQ"
    ],
    "rates": {
      "nightly": 500,
      "weekly": 2500
    },
    "seller_info": {
      "name": "Sarah Wilson",
      "email": "[email protected]",
      "phone": "305-555-5555"
    },
    "images": ["f1.jpg", "f2.jpg", "f3.jpg"],
    "is_featured": true,
    "createdAt": "2024-01-06T00:00:00.000Z",
    "updatedAt": "2024-01-06T00:00:00.000Z"
  },
  {
    "_id": "7",
    "owner": "4",
    "name": "Rustic Cabin in the Woods",
    "type": "Cottage Or Cabin",
    "description": "Experience nature in this cozy rustic cabin.",
    "location": {
      "street": "789 Forest Lane",
      "city": "Denver",
      "state": "CO",
      "zipcode": "80201"
    },
    "beds": 2,
    "baths": 1,
    "square_feet": 1100,
    "amenities": [
      "Fireplace",
      "Outdoor Grill/BBQ",
      "Hiking Trails Access",
      "Pet-Friendly"
    ],
    "rates": {
      "nightly": 475,
      "weekly": 2000
    },
    "seller_info": {
      "name": "Robert Anderson",
      "email": "[email protected]",
      "phone": "303-555-5555"
    },
    "images": ["g1.jpg", "g2.jpg", "g3.jpg"],
    "is_featured": false,
    "createdAt": "2024-01-07T00:00:00.000Z",
    "updatedAt": "2024-01-07T00:00:00.000Z"
  },
  {
    "_id": "8",
    "owner": "5",
    "name": "Ski-In/Ski-Out Chalet",
    "type": "Chalet",
    "description": "Hit the slopes from this cozy ski-in/ski-out chalet.",
    "location": {
      "street": "321 Mountain Road",
      "city": "Aspen",
      "state": "CO",
      "zipcode": "81611"
    },
    "beds": 3,
    "baths": 2,
    "square_feet": 1800,
    "amenities": [
      "Ski Equipment Storage",
      "Fireplace",
      "Balcony/Patio",
      "Smart TV"
    ],
    "rates": {
      "nightly": 300,
      "weekly": 1100
    },
    "seller_info": {
      "name": "Jennifer Martin",
      "email": "[email protected]",
      "phone": "970-555-5555"
    },
    "images": ["h1.jpg", "h2.jpg", "h3.jpg"],
    "is_featured": false,
    "createdAt": "2024-01-08T00:00:00.000Z",
    "updatedAt": "2024-01-08T00:00:00.000Z"
  },
  {
    "_id": "9",
    "owner": "6",
    "name": "Mountain View Retreat",
    "type": "House",
    "description": "Enjoy stunning mountain views from this spacious retreat.",
    "location": {
      "street": "600 Summit Drive",
      "city": "Boulder",
      "state": "CO",
      "zipcode": "80301"
    },
    "beds": 4,
    "baths": 3,
    "square_feet": 2400,
    "amenities": [
      "Mountain View",
      "Hiking Trails Access",
      "Air Conditioning",
      "Smart TV",
      "Outdoor Grill/BBQ"
    ],
    "rates": {
      "weekly": 1000,
      "monthly": 3800
    },
    "seller_info": {
      "name": "Lisa Taylor",
      "email": "[email protected]",
      "phone": "303-555-5555"
    },
    "images": ["i1.jpg", "i2.jpg", "i3.jpg"],
    "is_featured": false,
    "createdAt": "2024-01-09T00:00:00.000Z",
    "updatedAt": "2024-01-09T00:00:00.000Z"
  },
  {
    "_id": "10",
    "owner": "7",
    "name": "Historic Downtown Loft",
    "type": "Apartment",
    "description": "Step back in time with a stay in this historic downtown loft.",
    "location": {
      "street": "123 History Lane",
      "city": "Philadelphia",
      "state": "PA",
      "zipcode": "19101"
    },
    "beds": 2,
    "baths": 1,
    "square_feet": 1200,
    "amenities": [
      "High-Speed Internet",
      "Air Conditioning",
      "Smart TV",
      "Coffee Maker"
    ],
    "rates": {
      "weekly": 550,
      "monthly": 2100
    },
    "seller_info": {
      "name": "Matthew Harris",
      "email": "[email protected]",
      "phone": "215-555-5555"
    },
    "images": ["j1.jpg", "j2.jpg", "j3.jpg"],
    "is_featured": false,
    "createdAt": "2024-01-10T00:00:00.000Z",
    "updatedAt": "2024-01-10T00:00:00.000Z"
  }
]

Create properties images folder in public folder as follows: public>images>properties and then add all images in images>properties folder

5MB
archive
Open

1. Set Up the Properties Page

a. Update the Properties Page File

  • In your Next.js project, update a Page.jsx file for the properties page. For example:

  • This file will serve as the main page where all property listings are displayed.

b. Import the JSON Data

  • Place your properties.json file in an accessible location (e.g., in the project root or in a /data folder).

  • In your page.jsx file, import the JSON data:


find <!— All Listings --> comment section and just copy first three lines of code and past them to page,jsx

properties.html

2. Build the Page Structure

a. Create a Container for Listings

  • Start by creating a section element that holds your property listings. You can copy the outer container markup from your theme file:

b. Implement Conditional Rendering for Empty Data

  • Before rendering the listings, check if the properties array is empty and display a message if so:


3. Render the Property Listings

a. Loop Through the Properties Data

  • Use JavaScript’s .map() to iterate through the properties array and render each listing as a card:

  • Insert this code inside the grid container from the previous step.


4. Create the Property Card Component

a. Create a New Component File

  • In the components/ folder, create a new file named PropertyCard.jsx:

b. Build the Component Structure

  • Copy the relevant HTML markup for a property listing from your theme’s properties.html (the markup between the listing divs) into PropertyCard.jsx.

  • Modify the static content to dynamically display property data using the property prop.

  • Example:

  • Note: Adjust the paths and markup as needed to match your actual JSON structure and theme design.


5. Integrate the Property Card Component

a. Import the PropertyCard Component

  • In your app/properties/page.jsx file, import the component at the top:

b. Use the Component in the Map Function

  • Replace the placeholder div in your .map() loop with the <PropertyCard /> component, passing the property data as props:


6. Leverage Next.js Rendering Strategies

a. Server Rendering for Static Data

  • Since the properties data is coming from a static JSON file, you can leverage Next.js’s server components or static generation to render this page.

  • In Next.js 13+ with the app directory, pages are server components by default, which means the data is fetched at build time or request time and the page is rendered on the server.

b. Future Enhancements

  • Once you integrate an API or database, you can modify the data fetching strategy (e.g., using getStaticProps or fetch inside server components) without affecting your component structure.


7. Test and Refine

a. Run the Development Server

  • Start your Next.js server:

  • Navigate to http://localhost:3000/properties and verify that:

    • The container displays a heading and the grid.

    • If there are no properties, the “No properties found” message appears.

    • Each property from your JSON data is rendered as a PropertyCard with dynamic content.

b. Adjust Styling and Layout

  • Refine the Tailwind CSS classes and layout to match your desired design.

  • Verify responsiveness on different screen sizes.


Recap

  • Properties Page Setup: Create a dedicated page that imports data from a JSON file and conditionally renders a grid of property listings.

  • Dynamic Rendering: Use .map() to iterate over the properties and render each one with a reusable PropertyCard component.

  • Component Reusability: Build a PropertyCard component that dynamically displays property details, leveraging the structure provided in your theme files.

  • Next.js Rendering: Leverage Next.js server components (default in the app folder) for efficient, server-side rendering of static data, with room for future API integration.

Last updated