-
- 7
-
-
+ className="text-accent mr-1 font-semibold"
+ />
Results
{
+ // 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);
-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]);
+
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 (
-
+
Filter
-
{/* SALARY */}
@@ -145,6 +173,7 @@ const Filter = () => {
fillRule="nonzero"
/>
+ {/* */}
@@ -313,7 +343,6 @@ const Filter = () => {
-
);
};
diff --git a/src/data/filterData.js b/src/data/filterData.js
index 1e25a5d..651a2ca 100644
--- a/src/data/filterData.js
+++ b/src/data/filterData.js
@@ -3,77 +3,78 @@ export const filterData = [
src: "/assets/filterResults/Murex.png",
position: "DevOps Engineer",
jobModel: "Remote",
- salary: "$5000-$1000",
+ minSalary: "1000",
+ maxSalary: "5000",
employer: "Murex",
jobType: "Full Time",
payFreq: "Monthly",
postingDate: "07/12/2022",
+ location: "Iraq",
id: "1",
},
{
src: "/assets/filterResults/Murex.png",
position: "DevOps Engineer",
jobModel: "Remote",
- salary: "$4000-$6000",
+ minSalary: "4000",
+ maxSalary: "6000",
employer: "Murex",
jobType: "Internship",
payFreq: "Monthly",
postingDate: "06/26/2022",
+ location: "Lebanon",
id: "2",
},
{
src: "/assets/filterResults/EAB.png",
position: "Associate Data Scientist",
jobModel: "Remote",
- salary: "$2500-$4500",
+ minSalary: "2500",
+ maxSalary: "4500",
employer: "EAB",
jobType: "Part Time",
payFreq: "Monthly",
postingDate: "06/19/2022",
+ location: "Iraq",
id: "3",
},
{
src: "/assets/filterResults/EAB.png",
position: "Data Analyst",
jobModel: "Remote",
- salary: "$6500-$8000",
+ minSalary: "6500",
+ maxSalary: "8000",
employer: "EAB",
jobType: "Full Time",
payFreq: "Monthly",
postingDate: "06/19/2022",
+ location: "Syria",
id: "4",
},
{
src: "/assets/filterResults/EAB.png",
position: "Network Engineer",
jobModel: "Remote",
- salary: "$5000-$8000",
+ minSalary: "5000",
+ maxSalary: "8000",
employer: "EAB",
jobType: "Full Time",
payFreq: "Monthly",
postingDate: "06/19/2022",
+ location: "Yemen",
id: "5",
},
- {
- src: "/assets/filterResults/EAB.png",
- position: "Junior Netwoek Engineer",
- jobModel: "Remote",
- salary: "$-$",
- employer: "EAB",
- jobType: "Full Time",
- payFreq: "Monthly",
- postingDate: "06/05/2021",
- id: "6",
- },
{
src: "/assets/filterResults/EAB.png",
position: "Creative Project Manager",
jobModel: "Remote",
- salary: "$5000-$6000",
+ minSalary: "5000",
+ maxSalary: "6000",
employer: "EAB",
jobType: "Full Time",
payFreq: "Monthly",
postingDate: "01/01/2022",
- id: "7",
+ location: "Lebanon",
+ id: "6",
},
];