Skip to content

Commit

Permalink
Add project amount call
Browse files Browse the repository at this point in the history
  • Loading branch information
kplatis committed Apr 10, 2024
1 parent 8fc2626 commit d1da067
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions src/components/VirtualLab/VirtualLabSidebar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { useAtomValue } from 'jotai';
import { LoadingOutlined } from '@ant-design/icons';

import VirtualLabsSelect from './VirtualLabsSelect';
import { virtualLabDetailAtomFamily } from '@/state/virtual-lab/lab';
import { virtualLabDetailAtomFamily, virtualLabProjectsAtomFamily } from '@/state/virtual-lab/lab';
import VerticalLinks, { LinkItem } from '@/components/VerticalLinks';

type Props = {
Expand All @@ -17,7 +17,12 @@ type Props = {
export default function VirtualLabSidebar({ virtualLabId }: Props) {
const currentPage = usePathname().split('/').pop();
const virtualLab = useAtomValue(loadable(virtualLabDetailAtomFamily(virtualLabId)));
const projects = useAtomValue(loadable(virtualLabProjectsAtomFamily(virtualLabId)));

/**
* Renders the title of the virtual lab based on the request status
* @returns
*/
const renderVirtualLabTitle = () => {
if (virtualLab.state === 'loading') {
return <Spin indicator={<LoadingOutlined />} />;
Expand All @@ -30,14 +35,28 @@ export default function VirtualLabSidebar({ virtualLabId }: Props) {
return null;
};

/**
* Renders the amount of projects in the virtual lab based on the request status
* @returns
*/
const renderProjectsAmount = () => {
if (projects.state === 'loading') {
return <Spin indicator={<LoadingOutlined />} />;
}
if (projects.state === 'hasData') {
return projects.data.results.length;
}
return null;
};

const linkItems: LinkItem[] = [
{ key: 'lab', content: 'The Virtual Lab', href: 'lab' },
{
key: 'projects',
content: (
<div className="flex justify-between">
<span>Projects</span>
<span className="font-normal text-primary-3">9</span>
<span className="font-normal text-primary-3">{renderProjectsAmount()}</span>
</div>
),
href: 'projects',
Expand Down

0 comments on commit d1da067

Please sign in to comment.