Skip to content
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

completed working on the functionality for the sorting button found in the filter results component #110

Merged
merged 4 commits into from
Nov 9, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import { teamMembers } from "./data/teamData";
import WyChooseUs from "./components/whyChooseUs/WhyChooseUs";
import CompanyShowcaseComponent from "./components/companyShowcaseComponent/CompanyShowcaseComponent";
import { showCaseData } from "./data/showCaseData";
import FilterResults from "./components/FilterResults/FilterResults";
import {filterData} from "./data/filterData"
import "./App.css";
import JobsShowcase from "./components/JobsShowcase/JobsShowcase";
import { showcaseData } from "./data";
Expand Down Expand Up @@ -95,6 +97,7 @@ function App() {
const { t } = useTranslation();
return (
<div>
<FilterResults filterData={filterData}/>
<RoadMaps />
<Hero />
<JobsFinder />
Expand Down
5 changes: 4 additions & 1 deletion src/components/FilterResults/FilterButton.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { Fragment } from "react";
import { Menu, Transition } from "@headlessui/react";

function FilterButton() {
function FilterButton({handleChange}) {

return (
<Menu
as="div"
Expand Down Expand Up @@ -34,6 +35,7 @@ function FilterButton() {
<div
data-testid="language-button-option"
aria-hidden="true"
onClick={(e)=>handleChange('newest',e)}
className={`${
active
? "bg-white text-secondary rounded"
Expand All @@ -49,6 +51,7 @@ function FilterButton() {
<div
data-testid="language-button-option"
aria-hidden="true"
onClick={(e)=>handleChange('oldest',e)}
className={`${
active
? "bg-white text-secondary rounded"
Expand Down
24 changes: 22 additions & 2 deletions src/components/FilterResults/FilterResults.jsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,29 @@
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { faBookmark } from "@fortawesome/free-regular-svg-icons";
import { useState } from 'react';
import FilterButton from "./FilterButton";

function FilterResults({ filterData }) {
const jobCard = filterData.map((job) => {
const [data, setData] = useState(filterData)
const newArray=filterData.map((key)=>(
{ ...key, date: new Date(key.postingDate)}
))

// console.log(newArray)

const handleChange = (props)=>{
// console.log(props)
if (props==='newest'){
const sortingDataByNewest = newArray.sort((a, b) => b.date - a.date)
// console.log('newest data', sortingDataByNewest)
setData(sortingDataByNewest)
} else{
const sortingDataByOldest = newArray.sort((a, b) => a.date - b.date)
// console.log('oldest data', sortingDataByOldest)
setData(sortingDataByOldest)
}}

const jobCard = data.map((job) => {
return (
<div
key={job.id}
Expand Down Expand Up @@ -52,7 +72,7 @@ function FilterResults({ filterData }) {
</span>
Results
</h2>
<FilterButton />
<FilterButton handleChange={handleChange}/>
</div>
{jobCard}
</div>
Expand Down