Skip to content

Fix #4478 : Added lazy loading to the All Challenges page #4484

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

Open
wants to merge 15 commits into
base: master
Choose a base branch
from

Conversation

PrasadCodesML
Copy link
Contributor

@PrasadCodesML PrasadCodesML commented Mar 17, 2025

This PR fixes the all challenges page by loading content using lazy loading method as mentioned in the issue #4478

Untitled.video.-.Made.with.Clipchamp.2.mp4

Changes After Adding Lazy Loading are as follows

1. frontend/src/views/web/challenge-list.html

  1. getAllResults(parameters, challengeList, noneFlag, paginationType)
  • Core function that makes API requests to fetch challenge data
  • Handles pagination, data processing, and populating challenge lists
  • Manages loading states and error handling
  1. initializeChallenges()
  • Initializes all three challenge types (current, upcoming, past)
  • Sets up sequential loading for better performance
  • Called immediately when the controller is initialized
  1. initScrollListener()
  • Implements infinite scrolling functionality
  • Detects when user approaches the bottom of the page
  • Loads more challenges based on which section is currently visible
  1. checkVisibility()
  • Monitors which challenge sections are currently visible in the viewport
  • Initializes data loading for sections as they come into view
  • Improves performance by only loading data when needed

Scroll Event Listener for Lazy Loading

  • Added an infinite scrolling mechanism to load more challenges dynamically.

2. frontend/src/js/controllers/challengeListCtrl.js

New imageLoaded Method Added

  • Added a function to handle lazy loading when images load completely.

Lazy Loading Optimization

  • Instead of loading all images at once, only images visible in the viewport are loaded dynamically.

Pagination Logic Modified

  • Updated the logic to track when more items need to be loaded and load them when scrolling.
  • Integrated with the loadMore() function.

3. frontend\tests\controllers-test\challengeListCtrl.test.js

Updated the tests folder for proper build changed

  1. utilities.sendRequest
  2. Changed utilities.sendRequest mock logic
  3. Improved getAllResults recursion test
  4. Ensured utilities.getData() and utilities.storeData() are properly mocked

The above code is doing visbility based loading that is why there are some factor to consider initially all the ongoing, upcoming and past challenges div's are visible on the screen which will make a api call and fetch the challenge data but since initially all the 3 are visible it will load the fastest to fetch api first, even though i have included a function to loadSequentially() but the api calling speed of past and upcoming functions are fast as compared to the ongoing function so sometimes it might happen some of the past challenges are being loaded.
However, this can be fixed by increasing the visibility time in checkVisibility() but if there are no ongoing challenges it will take more time to load the upcoming and past challenges.

One of the solution to this problem can be introducing 3 tabs on the All challenges page to top right by clicking on that particular time(ongoing, upcoming or past) we can load challenges accordingly.

Let me know if any changes are need, or if you prefer to solve the problem in a different way...

@chiruu12
Copy link

@PrasadCodesML hey! I was working on the issue please make sure you communicate with others too next time.

Copy link
Member

@RishabhJain2018 RishabhJain2018 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @PrasadCodesML , Thanks for the PR. Can you please remove the formatting changes to the lines that are not required?

$timeout(vm.checkVisibility, 500);
});
}
})();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a new line here.

Copy link
Contributor Author

@PrasadCodesML PrasadCodesML Mar 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes i will modify those changes

@@ -1,13 +1,27 @@
<section class="ev-sm-container ev-view challenge-container">
<!-- ongoing challenges -->
<div class="challenge-page-title" id = "ongoing-challenges"><strong class="text-med-black fs-18">Ongoing Challenges</strong></div>
<div class="challenge-page-title" id="ongoing-challenges">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What are we changing here?

<div ng-if="challengeList.noneCurrentChallenge">None</div>
<div class="row">
<div class="col s12 m3" ng-repeat="challenge in challengeList.currentList"><a class="ev-card-hover" ui-sref="web.challenge-main.challenge-page({challengeId:challenge.id})">
<div class="col s12 m3" ng-repeat="challenge in challengeList.currentList">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What are we changing here?

});
});
});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a new line here.

@RishabhJain2018
Copy link
Member

Hey @PrasadCodesML , Can you please fix the travis build?

@PrasadCodesML
Copy link
Contributor Author

Hey @PrasadCodesML , Can you please fix the travis build?

Yes working on it.

Copy link

codecov bot commented Mar 23, 2025

Codecov Report

Attention: Patch coverage is 46.91358% with 86 lines in your changes missing coverage. Please review.

Project coverage is 67.98%. Comparing base (96968d6) to head (5a2c973).
Report is 1132 commits behind head on master.

Files with missing lines Patch % Lines
frontend/src/js/controllers/challengeListCtrl.js 46.91% 86 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4484      +/-   ##
==========================================
- Coverage   72.93%   67.98%   -4.95%     
==========================================
  Files          83       20      -63     
  Lines        5368     3692    -1676     
==========================================
- Hits         3915     2510    -1405     
+ Misses       1453     1182     -271     
Files with missing lines Coverage Δ
frontend/src/js/controllers/challengeListCtrl.js 51.63% <46.91%> (-43.06%) ⬇️

... and 64 files with indirect coverage changes

Files with missing lines Coverage Δ
frontend/src/js/controllers/challengeListCtrl.js 51.63% <46.91%> (-43.06%) ⬇️

... and 64 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c194f5e...5a2c973. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@PrasadCodesML
Copy link
Contributor Author

Hey @PrasadCodesML , Can you please fix the travis build?

Hey, @RishabhJain2018 the Travis build is fixed

Copy link
Member

@gautamjajoo gautamjajoo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A couple of questions:

  1. Why are we using pagination?
  2. There are some changes like adding the loader, modifying css, etc. Why are those needed?
  3. Can we use any library to implement lazy-loading?
  4. Can you populate the database with a couple of more challenges, and then show the network tab from the Google Developer console? I am not sure if the challenges are loaded according to the viewport.

@PrasadCodesML
Copy link
Contributor Author

A couple of questions:

  1. Why are we using pagination?
  2. There are some changes like adding the loader, modifying css, etc. Why are those needed?
  3. Can we use any library to implement lazy-loading?
  4. Can you populate the database with a couple of more challenges, and then show the network tab from the Google Developer console? I am not sure if the challenges are loaded according to the viewport.

Why are we using pagination?
Pagination is essential here because it reduces initial payload size and breaks content into manageable chunks

Why are loaders and CSS modifications needed?
These UX elements are crucial because without loaders, users have no indication if data is loading or if something failed, layout shifts during loading create a jarring experience

Can we use lazy-loading libraries?
It tried using angular's built in lazy loading library but there were too many complex dependency issues because of older version of Angular, The current scroll-based implementation, while not ideal, is more compatible with the existing architecture.

Can you populate the database with a couple of more challenges, and then show the network tab from the Google Developer console? I am not sure if the challenges are loaded according to the viewport.
Yes, i will work on this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants