Skip to content

Commit ba5d9d0

Browse files
authored
feat: sort followers on the basis of date
1 parent 2233319 commit ba5d9d0

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

scripts/src/fetchFollowers.js

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,11 @@ const getLatestFollowers = async () => {
2323

2424
try {
2525
while (hasMore) {
26-
const { data } =
27-
await octokit.rest.users.listFollowersForAuthenticatedUser({
28-
username: username,
29-
per_page: perPage,
30-
page: page,
31-
});
26+
const { data } = await octokit.rest.users.listFollowersForAuthenticatedUser({
27+
username: username,
28+
per_page: perPage,
29+
page: page,
30+
});
3231

3332
followers = followers.concat(data);
3433

@@ -42,18 +41,18 @@ const getLatestFollowers = async () => {
4241
const formattedFollowers = followers.map((follower) => ({
4342
profileUrl: follower.html_url,
4443
picUrl: follower.avatar_url,
44+
followedAt: follower.created_at, // Fetch the follow date
4545
}));
4646

4747
formattedFollowers.sort((a, b) => {
48-
return a.profileUrl.localeCompare(b.profileUrl);
48+
return new Date(b.followedAt) - new Date(a.followedAt); // Sort by follow date
4949
});
5050

5151
return formattedFollowers;
5252
} catch (error) {
5353
console.error("Error fetching followers:", error.message);
5454
}
5555
};
56-
5756
export async function handleFetchFollowers() {
5857
const followers = await getLatestFollowers();
5958
const followersLength = followers.length;

0 commit comments

Comments
 (0)