mirror of
https://seed.radicle.dev/rad:z4V1sjrXqjvFdnCUbxPFqd5p4DtH5.git
synced 2026-11-21 22:30:41 +08:00
Add "Sort by activity" toggle to repo list
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user