From dfe4532390d50e192cb271c7052e13f798f21272 Mon Sep 17 00:00:00 2001 From: Robert Kaussow Date: Mon, 18 Nov 2024 23:50:51 +0100 Subject: [PATCH] fix layout --- web/src/compositions/useRepos.ts | 30 +++++++++++++++++++++++++----- web/src/store/repos.ts | 9 +++++++++ web/src/views/Repos.vue | 13 ++++++++++--- 3 files changed, 44 insertions(+), 8 deletions(-) diff --git a/web/src/compositions/useRepos.ts b/web/src/compositions/useRepos.ts index ac754727a8..002e9ccb3e 100644 --- a/web/src/compositions/useRepos.ts +++ b/web/src/compositions/useRepos.ts @@ -15,12 +15,32 @@ export default function useRepos() { } function sortReposByLastActivity(repos: Repo[]): Repo[] { - return repos.sort((a, b) => { - const aLastActivity = a.last_pipeline_item?.created || 0; - const bLastActivity = b.last_pipeline_item?.created || 0; - - return bLastActivity - aLastActivity; + console.log( + 'Pre-sort repos:', + repos.map((r) => ({ + name: r.name, + last_pipeline_item: r.last_pipeline_item?.created, + })), + ); + + const reposWithPipelines = repos.filter((r) => r.last_pipeline_item?.created); + const reposWithoutPipelines = repos.filter((r) => !r.last_pipeline_item?.created); + + const sortedWithPipelines = reposWithPipelines.sort((a, b) => { + return (b.last_pipeline_item?.created || 0) - (a.last_pipeline_item?.created || 0); }); + + const sorted = [...sortedWithPipelines, ...reposWithoutPipelines]; + + console.log( + 'Post-sort repos:', + sorted.map((r) => ({ + name: r.name, + last_pipeline_item: r.last_pipeline_item?.created, + })), + ); + + return sorted; } function updateLastAccess(repoId: number) { diff --git a/web/src/store/repos.ts b/web/src/store/repos.ts index f14d9a5b85..f181909a5d 100644 --- a/web/src/store/repos.ts +++ b/web/src/store/repos.ts @@ -16,6 +16,14 @@ export const useRepoStore = defineStore('repos', () => { .map(([, repo]) => repo), ); + const sortedByActivity = computed(() => { + return Object.values(ownedRepos.value).sort((a, b) => { + const aLastActivity = a.last_pipeline_item?.created || 0; + const bLastActivity = b.last_pipeline_item?.created || 0; + return bLastActivity - aLastActivity; + }); + }); + function getRepo(repoId: Ref) { return computed(() => repos.get(repoId.value)); } @@ -45,6 +53,7 @@ export const useRepoStore = defineStore('repos', () => { return { repos, ownedRepos, + sortedByActivity, ownedRepoIds, getRepo, setRepo, diff --git a/web/src/views/Repos.vue b/web/src/views/Repos.vue index 92820b536b..652d79c3ec 100644 --- a/web/src/views/Repos.vue +++ b/web/src/views/Repos.vue @@ -8,7 +8,7 @@