diff --git a/app/properties/page.jsx b/app/properties/page.jsx index 661b697..f2246aa 100644 --- a/app/properties/page.jsx +++ b/app/properties/page.jsx @@ -1,4 +1,5 @@ import PropertyCard from '@/components/PropertyCard'; +import PropertySearchForm from '@/components/PropertySearchForm'; import Property from '@/models/Property'; import connectDB from '@/config/database'; @@ -7,19 +8,27 @@ const PropertiesPage = async () => { const properties = await Property.find({}).lean(); return ( - - - {properties.length === 0 ? ( - No properties found - ) : ( - - {properties.map((property, index) => ( - - ))} - - )} - - + <> + + + + + + + + Browse Properties + {properties.length === 0 ? ( + No properties found + ) : ( + + {properties.map((property, index) => ( + + ))} + + )} + + + > ); }; diff --git a/app/properties/search-results/page.jsx b/app/properties/search-results/page.jsx new file mode 100644 index 0000000..0011678 --- /dev/null +++ b/app/properties/search-results/page.jsx @@ -0,0 +1,67 @@ +import Link from 'next/link'; +import { FaArrowAltCircleLeft } from 'react-icons/fa'; +import PropertyCard from '@/components/PropertyCard'; +import PropertySearchForm from '@/components/PropertySearchForm'; +import connectDB from '@/config/database'; +import Property from '@/models/Property'; +import { convertToSerializeableObject } from '@/utils/convertToObject'; + +const SearchResultsPage = async ({ + searchParams: { location, propertyType }, +}) => { + await connectDB(); + + const locationPattern = new RegExp(location, 'i'); + + // Match location pattern against database fields + let query = { + $or: [ + { name: locationPattern }, + { description: locationPattern }, + { 'location.street': locationPattern }, + { 'location.city': locationPattern }, + { 'location.state': locationPattern }, + { 'location.zipcode': locationPattern }, + ], + }; + + // Only check for property if its not 'All' + if (propertyType && propertyType !== 'All') { + const typePattern = new RegExp(propertyType, 'i'); + query.type = typePattern; + } + + const propertiesQueryResults = await Property.find(query).lean(); + const properties = convertToSerializeableObject(propertiesQueryResults); + + return ( + <> + + + + + + + + + Back To Properties + + Search Results + {properties.length === 0 ? ( + No search results found + ) : ( + + {properties.map((property) => ( + + ))} + + )} + + + > + ); +}; +export default SearchResultsPage;
No properties found
No search results found