From 859a16ef31993f043cfa89a07907c85a385c8d8a Mon Sep 17 00:00:00 2001 From: Mikyo King Date: Thu, 14 Mar 2024 13:42:19 -0600 Subject: [PATCH] fix(projects): the home page should direct you to the projects page if there are multiple projects with data --- app/src/pages/home/homeLoader.ts | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/app/src/pages/home/homeLoader.ts b/app/src/pages/home/homeLoader.ts index 2434b69e20..06c2303cc9 100644 --- a/app/src/pages/home/homeLoader.ts +++ b/app/src/pages/home/homeLoader.ts @@ -34,11 +34,23 @@ export async function homeLoader(_args: LoaderFunctionArgs) { if (data?.functionality.modelInferences) { return redirect("/model"); } else if (data?.projects.edges?.length) { + // Detect if there is only a single project with data. If that's the case, redirect to that project + let numProjectsWithData = 0, + projectIdWithData = null; for (const { project } of data.projects.edges) { if (project.endTime != null) { - return redirect(`/projects/${project.id}`); + numProjectsWithData++; + projectIdWithData = project.id; } } + if (numProjectsWithData > 1) { + // There are multiple projects with data, redirect to projects + return redirect("/projects"); + } else if (numProjectsWithData === 1 && projectIdWithData != null) { + // There is only one project with data, redirect to that project + return redirect(`/projects/${projectIdWithData}`); + } + // Fallback to the default project const projectId = data?.projects.edges[0].project.id; return redirect(`/projects/${projectId}`); } else {