diff --git a/app/properties/saved/page.jsx b/app/properties/saved/page.jsx new file mode 100644 index 0000000..db76bc8 --- /dev/null +++ b/app/properties/saved/page.jsx @@ -0,0 +1,35 @@ +import PropertyCard from '@/components/PropertyCard'; +import connectDB from '@/config/database'; +import User from '@/models/User'; +import { getSessionUser } from '@/utils/getSessionUser'; + +const SavedPropertiesPage = async () => { + await connectDB(); + + const sessionUser = await getSessionUser(); + + const { userId } = sessionUser; + + // NOTE: here we can make one database query by using Model.populate + const { bookmarks } = await User.findById(userId) + .populate('bookmarks') + .lean(); + + return ( +
+
+

Saved Properties

+ {bookmarks.length === 0 ? ( +

No saved properties

+ ) : ( +
+ {bookmarks.map((property) => ( + + ))} +
+ )} +
+
+ ); +}; +export default SavedPropertiesPage; diff --git a/components/Navbar.jsx b/components/Navbar.jsx index 5c65df3..6835dfc 100644 --- a/components/Navbar.jsx +++ b/components/Navbar.jsx @@ -202,7 +202,7 @@ const Navbar = () => { Your Profile