done
This commit is contained in:
parent
d54bcdb9c5
commit
8b49882f18
|
@ -113,13 +113,40 @@ export const updatePropertyById = async (req, res) => {
|
|||
// };
|
||||
|
||||
|
||||
// controllers/propertyController.js
|
||||
// export const getProperties = async (req, res) => {
|
||||
// try {
|
||||
// const { page = 1, limit = 10 } = req.query;
|
||||
// const skip = (page - 1) * limit;
|
||||
// const totalProperties = await PropertyModal.countDocuments();
|
||||
// const properties = await PropertyModal.find()
|
||||
// .sort({ createdAt: -1 })
|
||||
// .skip(skip)
|
||||
// .limit(parseInt(limit));
|
||||
|
||||
// res.status(200).json({
|
||||
// success: true,
|
||||
// data: properties,
|
||||
// totalPages: Math.ceil(totalProperties / limit),
|
||||
// currentPage: parseInt(page), // Include the currentPage in the response
|
||||
// });
|
||||
// } catch (err) {
|
||||
// res.status(500).json({ success: false, message: 'Server error' });
|
||||
// }
|
||||
// };
|
||||
|
||||
|
||||
export const getProperties = async (req, res) => {
|
||||
try {
|
||||
const { page = 1, limit = 10 } = req.query;
|
||||
const { page = 1, limit = 10, keyword = "" } = req.query;
|
||||
const skip = (page - 1) * limit;
|
||||
const totalProperties = await PropertyModal.countDocuments();
|
||||
const properties = await PropertyModal.find()
|
||||
|
||||
// Use a filter to match the keyword if provided
|
||||
const keywordFilter = keyword
|
||||
? { address: { $regex: keyword, $options: "i" } }
|
||||
: {};
|
||||
|
||||
const totalProperties = await PropertyModal.countDocuments(keywordFilter);
|
||||
const properties = await PropertyModal.find(keywordFilter)
|
||||
.sort({ createdAt: -1 })
|
||||
.skip(skip)
|
||||
.limit(parseInt(limit));
|
||||
|
@ -128,7 +155,7 @@ export const getProperties = async (req, res) => {
|
|||
success: true,
|
||||
data: properties,
|
||||
totalPages: Math.ceil(totalProperties / limit),
|
||||
currentPage: parseInt(page), // Include the currentPage in the response
|
||||
currentPage: parseInt(page),
|
||||
});
|
||||
} catch (err) {
|
||||
res.status(500).json({ success: false, message: 'Server error' });
|
||||
|
@ -137,3 +164,4 @@ export const getProperties = async (req, res) => {
|
|||
|
||||
|
||||
|
||||
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -45,7 +45,7 @@
|
|||
|
||||
|
||||
|
||||
<script type="module" crossorigin src="/assets/index-DJmr6ji6.js"></script>
|
||||
<script type="module" crossorigin src="/assets/index-BsVOnNCb.js"></script>
|
||||
<link rel="stylesheet" crossorigin href="/assets/index-DepkKhoc.css">
|
||||
</head>
|
||||
|
||||
|
|
|
@ -11,7 +11,6 @@ const EditProperty = () => {
|
|||
|
||||
const [formData, setFormData] = useState({
|
||||
propertyType: "",
|
||||
title: "",
|
||||
yearBuild: "",
|
||||
totalSqft: "",
|
||||
});
|
||||
|
@ -24,7 +23,6 @@ const EditProperty = () => {
|
|||
if (selectedProperty) {
|
||||
setFormData({
|
||||
propertyType: selectedProperty.propertyType,
|
||||
title: selectedProperty.title,
|
||||
yearBuild: selectedProperty.yearBuild,
|
||||
totalSqft: selectedProperty.totalSqft,
|
||||
});
|
||||
|
@ -62,23 +60,6 @@ const EditProperty = () => {
|
|||
</select>
|
||||
</div>
|
||||
|
||||
<div className="col-12">
|
||||
<div className="form-floating mb-3">
|
||||
<input
|
||||
type="text"
|
||||
className="form-control"
|
||||
name="title"
|
||||
value={formData.title}
|
||||
onChange={handleChange}
|
||||
placeholder="Property title"
|
||||
required
|
||||
/>
|
||||
<label htmlFor="title" className="form-label">
|
||||
Property Title
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="col-12">
|
||||
<div className="form-floating mb-3">
|
||||
<input
|
||||
|
|
|
@ -20,9 +20,15 @@ const SearchProperties = () => {
|
|||
const limit = 10; // Number of results per page
|
||||
|
||||
// Dispatch getProperties to load properties on page change
|
||||
// useEffect(() => {
|
||||
// dispatch(getProperties({ page, limit }));
|
||||
// }, [dispatch, page]);
|
||||
|
||||
// Dispatch getProperties to load properties on page or keyword change
|
||||
useEffect(() => {
|
||||
dispatch(getProperties({ page, limit }));
|
||||
}, [dispatch, page]);
|
||||
dispatch(getProperties({ page, limit, keyword }));
|
||||
}, [dispatch, page, keyword]);
|
||||
|
||||
|
||||
// Filter properties based on the keyword entered
|
||||
useEffect(() => {
|
||||
|
@ -45,10 +51,16 @@ const SearchProperties = () => {
|
|||
e.preventDefault();
|
||||
};
|
||||
|
||||
// const handlePageChange = (newPage) => {
|
||||
// setPage(newPage); // Update the current page when user clicks pagination
|
||||
// };
|
||||
|
||||
const handlePageChange = (newPage) => {
|
||||
setPage(newPage); // Update the current page when user clicks pagination
|
||||
setPage(newPage);
|
||||
dispatch(getProperties({ page: newPage, limit, keyword })); // Pass the keyword when changing page
|
||||
};
|
||||
|
||||
|
||||
return (
|
||||
<>
|
||||
<Navbar />
|
||||
|
@ -109,7 +121,6 @@ const SearchProperties = () => {
|
|||
filteredProperties.map((property) => (
|
||||
<tr key={property.id}>
|
||||
<td>
|
||||
|
||||
{property.images && property.images[0] ? (
|
||||
<img
|
||||
src={property.images[0].file || profilepic}
|
||||
|
@ -123,11 +134,6 @@ const SearchProperties = () => {
|
|||
style={{ width: "100px", height: "auto" }}
|
||||
/>
|
||||
)}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</td>
|
||||
<td>
|
||||
<div className="widget-26-job-title">
|
||||
|
|
|
@ -69,6 +69,14 @@ export const updateProperty = createAsyncThunk(
|
|||
// return response.data;
|
||||
// });
|
||||
|
||||
// export const getProperties = createAsyncThunk(
|
||||
// 'properties/getProperties',
|
||||
// async ({ page, limit, keyword = "" }) => {
|
||||
// const response = await axios.get(`${import.meta.env.VITE_REACT_APP_SECRET}/properties?page=${page}&limit=${limit}&keyword=${keyword}`);
|
||||
// return response.data;
|
||||
// }
|
||||
// );
|
||||
|
||||
export const getProperties = createAsyncThunk(
|
||||
'properties/getProperties',
|
||||
async ({ page, limit, keyword = "" }) => {
|
||||
|
@ -77,6 +85,7 @@ export const getProperties = createAsyncThunk(
|
|||
}
|
||||
);
|
||||
|
||||
|
||||
const propertySlice = createSlice({
|
||||
name: "property",
|
||||
initialState: {
|
||||
|
|
Loading…
Reference in New Issue