diff --git a/app/properties/page.jsx b/app/properties/page.jsx index a95d086..da4447b 100644 --- a/app/properties/page.jsx +++ b/app/properties/page.jsx @@ -1,7 +1,11 @@ -import properties from '@/properties.json'; import PropertyCard from '@/components/PropertyCard'; +import Property from '@/models/Property'; +import connectDB from '@/config/database'; + +const PropertiesPage = async () => { + await connectDB(); + const properties = await Property.find({}); -const PropertiesPage = () => { return (
diff --git a/components/HomeProperties.jsx b/components/HomeProperties.jsx index d2bea43..51859a6 100644 --- a/components/HomeProperties.jsx +++ b/components/HomeProperties.jsx @@ -1,11 +1,16 @@ -import properties from '@/properties.json'; import Link from 'next/link'; import PropertyCard from './PropertyCard'; +import connectDB from '@/config/database'; +import Property from '@/models/Property'; -const HomeProperties = () => { - const recentProperties = properties - .sort(() => Math.random() - Math.random()) - .slice(0, 3); +const HomeProperties = async () => { + await connectDB(); + + // Get the 3 latest properties + const recentProperties = await Property.find({}) + .sort({ createdAt: -1 }) + .limit(3) + .lean(); return ( <> @@ -25,6 +30,7 @@ const HomeProperties = () => {
+