-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Jobs page filtering functionality #123
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,17 @@ | ||
import { useState } from "react"; | ||
import { useEffect, useState } from "react"; | ||
|
||
const Filter = ({ setData, filterData }) => { | ||
// obtaining min and max values for salary range from filterData.js to be set as initial states // | ||
const minSalaryArray = filterData.map((item) => item.minSalary); | ||
const minSalaryValue = Math.min(...minSalaryArray); | ||
|
||
const maximumSalaryArray = filterData.map((item) => item.maxSalary); | ||
const maxSalaryValue = Math.max(...maximumSalaryArray); | ||
Comment on lines
+5
to
+9
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I love how you took advantage of the built-in Math function of min and max!!🔥 |
||
|
||
const Filter = () => { | ||
const [filter, setFilter] = useState({ | ||
salary: { | ||
min: "", | ||
max: "", | ||
min: `${minSalaryValue}`, | ||
max: `${maxSalaryValue}`, | ||
}, | ||
|
||
location: "", | ||
|
@@ -32,14 +39,36 @@ const Filter = () => { | |
}, | ||
}); | ||
} | ||
console.log(filter); | ||
}; | ||
|
||
useEffect(() => { | ||
setData( | ||
filterData.filter((item) => { | ||
if ( | ||
item.minSalary >= filter.salary.min && | ||
item.minSalary <= filter.salary.max | ||
) { | ||
return item; | ||
} | ||
return null; | ||
}) | ||
); | ||
}, [filter.salary]); | ||
Comment on lines
+44
to
+56
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Awesome work on achieving the filtering!! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you @AllanSaleh for your continuous support and guidance! I really appreciate your efforts and dedication! Have a lovely day 🙏 |
||
|
||
const locationHandler = (e) => { | ||
setFilter({ | ||
...filter, | ||
location: e.target.value, | ||
}); | ||
|
||
setData( | ||
filterData.filter((item) => { | ||
if (item.location === e.target.value) { | ||
return item; | ||
} | ||
return null; | ||
}) | ||
); | ||
}; | ||
|
||
const employmentTypeHandler = (e) => { | ||
|
@@ -86,10 +115,9 @@ const Filter = () => { | |
|
||
return ( | ||
<div className="flex "> | ||
<div className=" w-screen bg-gray-100 h-screen p-5 flex flex-col items-center"> | ||
<div className="bg-gray-200 h-screen p-5 flex flex-col items-center"> | ||
<h2 className="text-secondary font-bold text-3xl">Filter</h2> | ||
|
||
<hr className="w-full" /> | ||
{/* SALARY */} | ||
<div className="salary pl-3"> | ||
<div className="flex space-between pt-3 pb-3 text-center"> | ||
|
@@ -145,6 +173,7 @@ const Filter = () => { | |
fillRule="nonzero" | ||
/> | ||
</svg> | ||
{/* <form onSubmit={handleChangeLocation}> */} | ||
<select | ||
className="border border-gray-300 rounded-md text-gray-600 h-10 pl-5 pr-10 bg-white hover:border-gray-400 focus:outline-none appearance-none w-56 " | ||
value={filter.location} | ||
|
@@ -158,6 +187,7 @@ const Filter = () => { | |
<option>Lebanon</option> | ||
<option>Kuwait</option> | ||
</select> | ||
{/* </form> */} | ||
</div> | ||
</div> | ||
</div> | ||
|
@@ -313,7 +343,6 @@ const Filter = () => { | |
</div> | ||
</div> | ||
</div> | ||
<div className="w-full" /> | ||
</div> | ||
); | ||
}; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Kudos to you!!
The component looks nicer now!!