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 {