Add "Sort by activity" toggle to repo list

This commit is contained in:
Rūdolfs Ošiņš
2026-04-29 12:12:03 +02:00
parent 4dce10bc66
commit 4ddca81f16
2 changed files with 52 additions and 2 deletions
+16
View File
@@ -37,3 +37,19 @@ export async function fetchRepoInfos(
}),
}));
}
export async function sortRepoInfosByActivity(
repos: RepoInfo[],
): Promise<RepoInfo[]> {
const withActivity = await Promise.all(
repos.map(async r => ({ info: r, activity: await r.activity })),
);
return withActivity
.sort((a, b) => {
if (a.activity.length === 0 && b.activity.length === 0) return 0;
if (a.activity.length === 0) return 1;
if (b.activity.length === 0) return -1;
return b.activity[0].time - a.activity[0].time;
})
.map(x => x.info);
}