zubhub
zubhub copied to clipboard
Improve more projects section
Summary
'More Projects' section used to show the projects of the same user instead of showing similar projects from any user. With this PR, this section sends a request to the backend with the current project's id and retrieves 3 recommended projects depending on the project's categories.
Closes #1013
The changes in backend is adapted from @anthonycruzmacedo 's code in #458
Changes
Frontend
- api function is created to send a request to
projects/${id}/recommend/
- error cases handled in projectActions.js with
getMoreProjects
function -
projectDetails.jsx
usesgetMoreProjects
to render the recommended projects
Backend
-
'<uuid:pk>/recommend/'
url is used to recommend projects -
ProjectRecommendAPIView
class returns 3 recommended projects -
recommend_projects
function handles the logic to determine the 3 projects by checking the projects with the same category/categories, and show the most liked projects if there's none.
Screenshots
Before
- shows the same user
- shows empty section when projects not found
After
- shows other projects with the same categories from any user
- shows most liked projects when no other project with the same category is found
Update
With the updated function, the projects are filtered based on their title, tags and categories. When doing title check, the project title is converted into an array of strings and each word is mapped. If any of the words are found in other titles, the project is appended. I will refer to these projects with 'similar title' in this PR.
First loop is done with the similar titled projects, looking for:
- Similar title, 1 matching category and 1 matching tag
- (if above filter's results are empty:) Similar title, 1 matching category or tag
- (if above filter's results are empty:) Similar title
Second loop looks for projects with:
- 1 matching category and 1 matching tag,
- (if above filter's results are empty:) 1 matching category or 1 matching tag
Third loop looks for the most liked projects
the code looks good. Still need to manually test the PR
pre-commit checks failed ❌❌❌ make sure you have pre-commit set up locally (see the README.md for instructions). If you have set up pre-commit locally, you may need to undo this commit and run "pre-commit" locally to see what the errors are.
All pre-commit checks passed ✅✅✅