Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found

Submitted

Static jobs listings with filter using React Js

@Iykekelvins

Desktop design screenshot for the Job listings with filtering coding challenge

This is a solution for...

  • HTML
  • CSS
  • JS
3intermediate
View challenge

Design comparison


SolutionDesign

Solution retrospective


Feedback required

Community feedback

@hjludwig

Posted

Hi Kelvin. Thanks for having a look at my solution.

Yours looks good, but (as Chamunorwa said) the filter function doesn't quite work as expected. It should only display jobs that match all the filters whereas yours displays all jobs that match the only last selected filter term.

const filterCategory = (category) => {
    const newCategory = data.filter(
      (item) =>
        item.role === category ||
        item.level === category ||
        item.languages.includes(category) ||
        item.tools.includes(category)
    );

    if (categories.includes(category)) {
      return null;
    } else {
      const newItem = { id: new Date().getTime().toString(), title: category };
      setCategories([...categories, newItem]);
    }
    setJobs(newCategory);
  };

I discovered I could use the .every() method to make sure the filter function only returned those jobs that matched all the filter terms:

const filterJobs = terms => {
        if (terms.length === 0) {
            return;
        }

        const filteredJobs = data.filter(job => {
            const tags = [...job.languages, ...job.tools, job.role, job.level];
            return terms.every(term => tags.includes(term));
        });
        setJobs(filteredJobs);
    };

I believe you should also call the filterCategory function when a filter term is removed.

One other little detail: You forgot to add the little border on the left of the featured jobs.

All the best.

Marked as helpful

0
T
Chamu 13,110

@ChamuMutezva

Posted

Greetings Kelvin Here are a few things that i managed to pick

  • The site is responsive , well done
  • The filter is not working as expected - it is only filtering the last selected choice without considering other previous selected choices.
  • headings are not in order. The first level heading should be an h1 then followed by an h2. Skipping headings is not recommended.

Happy coding

Marked as helpful

0

@Iykekelvins

Posted

@ChamuMutezva Hi, good morning. Thank you so much for giving your feedback. Is there a chance you could please assist me on what I should do? This would be much appreciated.

0
T
Chamu 13,110

@ChamuMutezva

Posted

@Iykekelvins , Hi. The logic of the filter function is as follows:

  • you will need an array that holds your filter categories, which is supposed to be empty on loading.
  • When pressing a button eg css , some checks has to take place before the selected category is added to the array. Does the array contain the selected category already? If the answer is yes, then do nothing since the array is already in order, if no is the answer then add it to the filter array.
  • Next is to use this array to filter for cards (that contains all the categories in the filter array). Display these cards only.

I am still trying to find my way with react, i will see if i can be able to temper with your code to implement the above.

0

Please log in to post a comment

Log in with GitHub
Discord logo

Join our Discord community

Join thousands of Frontend Mentor community members taking the challenges, sharing resources, helping each other, and chatting about all things front-end!

Join our Discord