Skip to content

Commit

Permalink
fix: handle loading states for project details for a single project
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasheartman committed Oct 21, 2024
1 parent 9fecc02 commit 3bc9c9a
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 18 deletions.
24 changes: 19 additions & 5 deletions frontend/src/component/personalDashboard/MyProjects.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,10 @@ const ProjectListItem: FC<{
);
};

type MyProjectsState = 'no projects' | 'projects' | 'projects with error';
type MyProjectsState =
| 'no projects'
| 'projects'
| 'projects with error or loading';

export const MyProjects = forwardRef<
HTMLDivElement,
Expand All @@ -149,7 +152,7 @@ export const MyProjects = forwardRef<
const state: MyProjectsState = projects.length
? personalDashboardProjectDetails
? 'projects'
: 'projects with error'
: 'projects with error or loading'
: 'no projects';

const activeProjectStage =
Expand Down Expand Up @@ -190,7 +193,7 @@ export const MyProjects = forwardRef<
),
};

case 'projects with error':
case 'projects with error or loading':
return {
list: (
<StyledList>
Expand All @@ -206,8 +209,19 @@ export const MyProjects = forwardRef<
))}
</StyledList>
),
box1: <DataError project={activeProject} />,
box2: <ContactAdmins admins={admins} />,
box1: (
<div data-loading>
<DataError
data-loading
project={activeProject}
/>
</div>
),
box2: (
<div data-loading>
<ContactAdmins admins={admins} />
</div>
),
};

case 'projects': {
Expand Down
11 changes: 3 additions & 8 deletions frontend/src/component/personalDashboard/PersonalDashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -130,15 +130,10 @@ export const PersonalDashboard = () => {
splash?.personalDashboardKeyConcepts ? 'closed' : 'open',
);

const { personalDashboardProjectDetails, error: detailsError } =
const { personalDashboardProjectDetails, loading: detailsLoading } =
usePersonalDashboardProjectDetails(activeProject);

const activeProjectStage =
personalDashboardProjectDetails?.onboardingStatus.status ?? 'loading';

const projectStageRef = useLoading(
!detailsError && activeProjectStage === 'loading',
);
const loadingProjectDetailsRef = useLoading(detailsLoading);

return (
<MainContent>
Expand Down Expand Up @@ -192,7 +187,7 @@ export const PersonalDashboard = () => {
<MyProjects
owners={personalDashboard?.projectOwners ?? []}
admins={personalDashboard?.admins ?? []}
ref={projectStageRef}
ref={loadingProjectDetailsRef}
projects={projects}
activeProject={activeProject || ''}
setActiveProject={setActiveProject}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@ import { ActionBox } from './ActionBox';

export const DataError: FC<{ project: string }> = ({ project }) => {
return (
<ActionBox
data-loading
title={`Couldn't fetch data for project "${project}".`}
>
<ActionBox title={`Couldn't fetch data for project "${project}".`}>
<p>
The API request to get data for this project returned with an
error.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export const RoleAndOwnerInfo = ({ roles, owners }: Props) => {
const firstRoles = roles.slice(0, 3);
const extraRoles = roles.slice(3);
return (
<Wrapper>
<Wrapper data-loading>
<InfoSection>
{roles.length > 0 ? (
<>
Expand Down

0 comments on commit 3bc9c9a

Please sign in to comment.