Filter - pmvdbijl7/matching-app GitHub Wiki
Filter profiles
When a user has logged or signed in to Matchflix, the user will see all the other profiles that he can match with. We found it necessary to keep the user's choices organized. A great way to do this, is to build a filter in the app. The filter that we build is based on gender preferences.
How did we implement this?
We added a dropdown list with the relevant filter topics in the page where all user profiles are shown. The next step was to collect the right value that is selected in the dropdown list. That value is sended with POST
. The next step was to show only the that given value of users in the database. And render the page with only the chosen value. All this is shown in the code below.
const FilterGet = (req, res) => {
const filterGender = req.body.gender;
const authUser = req.user._id;
const filterParam = {
$and: [{ gender: filterGender }],
};
const useFilter = User.find(filterParam);
useFilter.exec((err, docs) => {
if (!err) {
res.render('pages/home', {
title: 'Home',
users: docs,
authUser: authUser,
headerLeft: { path: '/', text: 'Refresh' },
headerRight: { path: '/matches', text: 'Matches' },
});
} else {
console.log('Error in retrieving profile data: ' + err);
}
});
};
User experience
This is what the user sees on the homepage, all profiles that are registered on Matchflix.
The user can filter these profiles by gender. So that the user can eliminate profiles that the user isn't interested in.
If the user wants to see the list with all the profiles again, the refresh button on the top left corner can be activated. The filter will be removed with this action.