Skip to content

Pagination for home page and category page #158

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 2 commits into
base: main
Choose a base branch
from

Conversation

wishrohitv
Copy link
Contributor

Fixes #

Proposed Changes

Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This draft PR implements pagination for both the home and category pages. Key changes include:

  • Addition of a new API endpoint (returnHomeFeedData) and a refactored database query function (getHomeFeedData) to support paginated post retrieval.
  • Updates to the front-end code (HTML template and JavaScript) for rendering post cards with pagination.
  • Removal of redundant database connection code from the index and category routes and registration of new blueprints.

Reviewed Changes

Copilot reviewed 9 out of 13 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
utils/getHomeFeedData.py Introduces a new function to fetch home feed data with pagination parameters.
static/tailwindUI/pureHtmlMacro/postCardMacro.html Adds an HTML template for post cards used in the home feed.
static/tailwindUI/js/homeFeed.js Updates JS logic to fetch and render paginated posts and handle spinner states.
routes/returnPostAnalyticsData.py Changes the error response to use make_response for consistency.
routes/returnHomeFeedData.py Creates a new endpoint to serve home feed data based on query parameters.
routes/index.py Refactors the home route to remove inline database access and instead defers to external data fetching via blueprints.
routes/category.py Removes the inline DB query in favor of an alternative approach for handling category posts.
modules.py Imports the new getHomeFeedData function.
app.py Registers the new blueprint for the home feed data endpoint.
Files not reviewed (4)
  • templates/tailwindUI/category.html.jinja: Language not supported
  • templates/tailwindUI/components/sortMenu.html.jinja: Language not supported
  • templates/tailwindUI/index.html.jinja: Language not supported
  • templates/tailwindUI/user.html.jinja: Language not supported
Comments suppressed due to low confidence (1)

routes/category.py:109

  • The fetching of post data has been removed from this route without a clear replacement, leaving the template without the expected 'posts' data. Confirm if this change is intentional.
return render_template(..., category=translations["categories"][category.lower()], ...)


// Id
let homeSpinner = document.getElementById("homeSpinner")
let loadMoreSpinner = document.getElementById("lodeMoreSpinner")
Copy link
Preview

Copilot AI Apr 26, 2025

Choose a reason for hiding this comment

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

The element ID 'lodeMoreSpinner' appears to be a typo. Verify if the intended ID is 'loadMoreSpinner'.

Suggested change
let loadMoreSpinner = document.getElementById("lodeMoreSpinner")
let loadMoreSpinner = document.getElementById("loadMoreSpinner")

Copilot uses AI. Check for mistakes.

Comment on lines +67 to +68

if (connection.ok) {
Copy link
Preview

Copilot AI Apr 26, 2025

Choose a reason for hiding this comment

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

The variable 'posts' is assigned without declaration, which could lead to unintended global scope. Consider declaring it with 'let' or 'const'.

Suggested change
if (connection.ok) {
let posts; // Declare posts locally

Copilot uses AI. Check for mistakes.

Comment on lines 26 to 27
print(category, by, sort, limit, offset, "rohit")

Copy link
Preview

Copilot AI Apr 26, 2025

Choose a reason for hiding this comment

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

Unexpected debug print statement ('rohit') found in production code. It should be removed before deployment.

Suggested change
print(category, by, sort, limit, offset, "rohit")

Copilot uses AI. Check for mistakes.

@DogukanUrker
Copy link
Owner

Good job. I love that. we can merge it after fixes. Please check copilot report.

@wishrohitv
Copy link
Contributor Author

Thanks!, I've fixed those typos and bugs

@wishrohitv wishrohitv marked this pull request as ready for review April 26, 2025 17:07
@DogukanUrker DogukanUrker requested a review from Copilot April 26, 2025 19:29
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR implements pagination for the home page and category page and refactors the API endpoints to retrieve paginated post data. Key changes include a new utility function for fetching paginated home feed data, updates to the home feed and category routes to remove direct database calls, and integration of front-end logic with a new HTML macro and JavaScript to render posts.

Reviewed Changes

Copilot reviewed 9 out of 13 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
utils/getHomeFeedData.py New utility function to fetch and return paginated home feed data from the database.
static/tailwindUI/pureHtmlMacro/postCardMacro.html Added HTML macro for rendering individual post cards.
static/tailwindUI/js/homeFeed.js Added JavaScript logic to load, render, and paginate home feed data using the new API.
routes/returnPostAnalyticsData.py Updated the analytics endpoint response with make_response.
routes/returnHomeFeedData.py Introduced a new API endpoint to serve paginated home feed data.
routes/index.py Refactored the home page route to use pagination parameters and remove direct DB calls.
routes/category.py Updated category route to integrate pagination and remove direct DB calls.
modules.py Imported the new getHomeFeedData utility.
app.py Registered the new home feed data blueprint.
Files not reviewed (4)
  • templates/tailwindUI/category.html.jinja: Language not supported
  • templates/tailwindUI/components/sortMenu.html.jinja: Language not supported
  • templates/tailwindUI/index.html.jinja: Language not supported
  • templates/tailwindUI/user.html.jinja: Language not supported

category = request.args.get("category", type=str, default="all")
by = request.args.get("by", type=str, default="hot")
sort = request.args.get("sort", type=str, default="desc")
limit = request.args.get("limit", type=int, default="4")
Copy link
Preview

Copilot AI Apr 26, 2025

Choose a reason for hiding this comment

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

The default value for 'limit' is set as a string instead of an integer; change it to default=4 to ensure correct type conversion.

Suggested change
limit = request.args.get("limit", type=int, default="4")
limit = request.args.get("limit", type=int, default=4)

Copilot uses AI. Check for mistakes.

const tempContainer = document.createElement('div');
tempContainer.innerHTML = postCardHtml;

// Register macro in dome
Copy link
Preview

Copilot AI Apr 26, 2025

Choose a reason for hiding this comment

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

Typo in comment: 'dome' should be corrected to 'DOM'.

Suggested change
// Register macro in dome
// Register macro in DOM

Copilot uses AI. Check for mistakes.

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

Successfully merging this pull request may close these issues.

2 participants