Skip to content

Commit

Permalink
Load more for This Week and Last Week section fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
doiayokanmi committed Jul 8, 2023
1 parent a43d2d5 commit 855d0a4
Showing 1 changed file with 34 additions and 11 deletions.
45 changes: 34 additions & 11 deletions src/components/RecentRepoListWrap.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,31 @@
// ...
import { useLocation, useSearchParams } from "react-router-dom";
import locationsHash from "../lib/locationsHash";
import ListRepositories from "./ListRepositories";
import { useEffect, useState } from "react";
import { useRepositoriesList } from "../hooks/useRepositoriesList";

export enum RepoOrderByEnum {
popular = "stars",
recent = "created_at",
upvoted = "votesCount",
discussed = "issues",
myVotes = "myVotes"
}

const parseLimitValue = (limit: string | null): number => {
if (!limit) {
return 25;
}
const value = parseInt(limit);

if (isNaN(value) || value <= 0) {
return 15;
}
if (value > 25) {
return 50;
}
return value;
};

const RecentRepoListWrap = (): JSX.Element => {
const [searchParams, setSearchParams] = useSearchParams();
Expand All @@ -19,27 +46,23 @@ const RecentRepoListWrap = (): JSX.Element => {

if (!isLoading) {
const thisWeekData = data.filter((repo) => repo.created_at && new Date(repo.created_at) > lastSunday);

Check failure on line 48 in src/components/RecentRepoListWrap.tsx

View workflow job for this annotation

GitHub Actions / Code standards

Unexpected parentheses around single function argument

thisWeekData.sort((a, b) => (new Date(a.created_at!) > new Date(b.created_at!) ? 1 : -1));

Check failure on line 49 in src/components/RecentRepoListWrap.tsx

View workflow job for this annotation

GitHub Actions / Code standards

Expected blank line before this statement
thisWeekData.sort((a, b) => (a.votesCount! > b.votesCount! ? -1 : 1));
setThisWeek(thisWeekData.slice(0, 101)); // Fix: Limit the number of repositories displayed to 101
setThisWeek(thisWeekData);

const lastWeekData = data.filter(
(repo) =>

Check failure on line 54 in src/components/RecentRepoListWrap.tsx

View workflow job for this annotation

GitHub Actions / Code standards

Unexpected parentheses around single function argument
repo.created_at &&
new Date(repo.created_at) < lastSunday &&
new Date(repo.created_at) > new Date(lastSunday.getTime() - 7 * 24 * 60 * 60 * 1000)

Check failure on line 57 in src/components/RecentRepoListWrap.tsx

View workflow job for this annotation

GitHub Actions / Code standards

Missing trailing comma
);

lastWeekData.sort((a, b) => (new Date(a.created_at!) > new Date(b.created_at!) ? 1 : -1));

Check failure on line 59 in src/components/RecentRepoListWrap.tsx

View workflow job for this annotation

GitHub Actions / Code standards

Expected blank line before this statement
lastWeekData.sort((a, b) => (a.votesCount! > b.votesCount! ? -1 : 1));
setLastWeek(lastWeekData.slice(0, 101)); // Fix: Limit the number of repositories displayed to 101
setLastWeek(lastWeekData);

const olderData = data.filter(
(repo) =>
repo.created_at && new Date(repo.created_at) < new Date(lastSunday.getTime() - 7 * 24 * 60 * 60 * 1000)
(repo) => repo.created_at && new Date(repo.created_at) < new Date(lastSunday.getTime() - 7 * 24 * 60 * 60 * 1000)

Check failure on line 64 in src/components/RecentRepoListWrap.tsx

View workflow job for this annotation

GitHub Actions / Code standards

Unexpected parentheses around single function argument

Check failure on line 64 in src/components/RecentRepoListWrap.tsx

View workflow job for this annotation

GitHub Actions / Code standards

Missing trailing comma
);

olderData.sort((a, b) => (new Date(a.created_at!) > new Date(b.created_at!) ? 1 : -1));

Check failure on line 66 in src/components/RecentRepoListWrap.tsx

View workflow job for this annotation

GitHub Actions / Code standards

Expected blank line before this statement
olderData.sort((a, b) => (a.votesCount! > b.votesCount! ? -1 : 1));
setOlder(olderData);
Expand All @@ -59,7 +82,7 @@ const RecentRepoListWrap = (): JSX.Element => {
activeLink={activeLink}
fetchedData={thisWeek}
handleLoadingMore={handleLoadingMore}
limit={101} // Fix: Set the limit to 101 to hide the "Load More" button
limit={limit}
title="This Week"
/>
)}
Expand All @@ -69,7 +92,7 @@ const RecentRepoListWrap = (): JSX.Element => {
activeLink={activeLink}
fetchedData={lastWeek}
handleLoadingMore={handleLoadingMore}
limit={101} // Fix: Set the limit to 101 to hide the "Load More" button
limit={limit}
title="Last Week"
/>
)}
Expand All @@ -79,7 +102,7 @@ const RecentRepoListWrap = (): JSX.Element => {
activeLink={activeLink}
fetchedData={older}
handleLoadingMore={handleLoadingMore}
limit={limit} // Fix: Set the limit to the actual limit value
limit={limit}
title="Older"
/>
)}
Expand Down

0 comments on commit 855d0a4

Please sign in to comment.