
Job listings with filtering built with Next
Design comparison
Solution retrospective
I am most proud of the filtering functions I wrote for this project, as this is an essential functionality that I assume will be needed often working on real websites.
What challenges did you encounter, and how did you overcome them?When I was scaling the company logos down for mobile screens, I ran into the issue that the images seemed to longer be left-aligned, i.e. they seemed to have some margin or padding on the left that I couldn't figure out how to get rid of. I learned that this happened because scaling always happens from the center, so the image will shift visually. I learned to prevent this by applying the CSS transform-origin property (in my case, transform-origin: left
).
I also, for some reason, wasn't able to color in the free spaces of the mobile background svg. To solve this, I eventually resorted to adding a <rect>
element to the svg to overlay it and thus fill in the previously white spaces.
There is one thing I wasn't able to figure out: on mobile screens, when adding filters, they get squished once they wrap onto a new line. I worked around this by giving them a min-height, but I feel that there has to be a better solution. I don't understand why this behavior happens, the container can grow in height to accommodate for new lines as I didn't limit its height anywhere. So if anyone has an explanation for this, I'm all ears!
Community feedback
- P@markuslewinPosted about 1 month ago
How would the browser know you want the filters to be 40px, though? 🤔
When the filters are on one line, the Clear button is the tallest child of the
.skills
container. The default behavior of flex is to stretch the flex items to fill the container. In this case, it stretches the filters until they're the same height as the button. When the filters wrap, the filters container is larger than the Clear button, and so the items no longer need to stretch to fill the.skills
container. (Now the Clear button is stretched instead, to fill the space created by the filters).I think
min-height
sounds like a good solution! You could also use padding to set an "implicit" minimum height, like you did for the Clear button.1@Jenny-EikensPosted about 1 month ago@markuslewin Right, that makes perfect sense! Thanks :)
0P@markuslewinPosted about 1 month ago@Jenny-Eikens Also!
filteredJobs
doesn't have to be state here, since its value can always be calculated fromlistings
andfilters
. That way, you avoid having to synchronizing states in auseEffect
:const JobList = ({ listings }: JobListProps) => { const [filters, setFilters] = useState<string[]>([]); // No effect let filteredJobs; if (filters.length === 0) { filteredJobs = listings; } else { const matchingJobs = listings.filter((job) => { const jobTags = [job.role, job.level, ...job.languages, ...job.tools]; return filters.every((filter) => jobTags.includes(filter)); }); filteredJobs = matchingJobs; } return <></>; };
Great job on this challenge!
Marked as helpful0@Jenny-EikensPosted about 1 month ago@markuslewin Oh, right! I totally missed that. I didn't consider that the filters state variable changing would cause a re-render anyway. It's definitely more efficient this way. Thanks again!
1
Please log in to post a comment
Log in with GitHubJoin 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