Skip to content

Commit

Permalink
Merge pull request #2304 from webb-tools/linh/overview-service-table
Browse files Browse the repository at this point in the history
feat(tangle-dapp): Integrate backend on Active Service table on Overview page
  • Loading branch information
drewstone authored May 9, 2024
2 parents 394f07b + 5e24e75 commit c60ff46
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 60 deletions.
14 changes: 6 additions & 8 deletions apps/tangle-dapp/app/services/ActiveServicesTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,28 @@ import { Typography } from '@webb-tools/webb-ui-components';
import { FC } from 'react';

import { ContainerSkeleton, ServiceTable, TableStatus } from '../../components';
import { useActiveServices } from '../../data/serviceOverview';
import useServiceOverview from '../../data/serviceOverview/useServiceOverview';

const pageSize = 10;

const ActiveServicesTable: FC = () => {
const { data: activeServicesData, isLoading: activeServicesDataLoading } =
useActiveServices();
const { services, isLoading } = useServiceOverview();

return (
<div className="space-y-5">
<Typography variant="h4" fw="bold">
Active Services
</Typography>
{activeServicesData && activeServicesData.length === 0 ? (
{services && services.length === 0 ? (
<TableStatus
title="No Past Services Found"
title="No Active Services Found"
description="No ongoing MPC services at the moment. Active services will be listed here."
icon="⏳"
/>
) : activeServicesDataLoading || !activeServicesData ? (
) : isLoading || !services ? (
<ContainerSkeleton />
) : (
// TODO: Handle lazy load when integrating with backend
<ServiceTable data={activeServicesData} pageSize={pageSize} />
<ServiceTable data={services} pageSize={pageSize} />
)}
</div>
);
Expand Down
11 changes: 11 additions & 0 deletions apps/tangle-dapp/app/services/layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { ReactNode } from 'react';

import ServiceOverviewContext from '../../context/ServiceOverviewContext';

export default function ServiceDetailsLayout({
children,
}: {
children: ReactNode;
}) {
return <ServiceOverviewContext>{children}</ServiceOverviewContext>;
}
49 changes: 49 additions & 0 deletions apps/tangle-dapp/context/ServiceOverviewContext.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
'use client';

import { Option } from '@polkadot/types';
import { TanglePrimitivesJobsJobInfo } from '@polkadot/types/lookup';
import { createContext, FC, PropsWithChildren, useCallback } from 'react';
import { map } from 'rxjs/operators';

import usePolkadotApiRx from '../hooks/usePolkadotApiRx';
import { Service } from '../types';
import { extractServiceDetails } from '../utils/polkadot/services';

export const ServiceOverviewContext = createContext<{
services: Service[];
isLoading: boolean;
}>({
services: [],
isLoading: true,
});

const ServiceOverviewProvider: FC<PropsWithChildren> = ({ children }) => {
const { data: services, isLoading } = usePolkadotApiRx(
useCallback((api) => {
return api.query.jobs.submittedJobs.entries().pipe(
map((jobsData) =>
jobsData
.map(([key, job]) => {
const id = key.args[1].toString();
const service = extractServiceDetails(
id,
job as Option<TanglePrimitivesJobsJobInfo>
);
return service;
})
.filter((service): service is Service => service !== null)
)
);
}, [])
);

return (
<ServiceOverviewContext.Provider
value={{ services: services ?? [], isLoading }}
>
{children}
</ServiceOverviewContext.Provider>
);
};

export default ServiceOverviewProvider;
2 changes: 1 addition & 1 deletion apps/tangle-dapp/data/serviceOverview/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export { default as useActiveServices } from './useActiveServices';
export { default as useServiceOverview } from './useServiceOverview';
51 changes: 0 additions & 51 deletions apps/tangle-dapp/data/serviceOverview/useActiveServices.ts

This file was deleted.

9 changes: 9 additions & 0 deletions apps/tangle-dapp/data/serviceOverview/useServiceOverview.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
'use client';

import { useContext } from 'react';

import { ServiceOverviewContext } from '../../context/ServiceOverviewContext';

export default function useServiceOverview() {
return useContext(ServiceOverviewContext);
}

0 comments on commit c60ff46

Please sign in to comment.