|
| 1 | +import { FC } from 'react' |
| 2 | +import { useTranslation } from 'react-i18next' |
| 3 | +import { Link as RouterLink } from 'react-router-dom' |
| 4 | +import Card from '@mui/material/Card' |
| 5 | +import CardHeader from '@mui/material/CardHeader' |
| 6 | +import CardContent from '@mui/material/CardContent' |
| 7 | +import Link from '@mui/material/Link' |
| 8 | +import { Layer, useGetRuntimeRoflApps } from '../../../oasis-nexus/api' |
| 9 | +import { SearchScope } from '../../../types/searchScope' |
| 10 | +import { NUMBER_OF_ITEMS_ON_DASHBOARD as limit } from '../../config' |
| 11 | +import { COLORS } from '../../../styles/theme/colors' |
| 12 | +import { AppErrors } from '../../../types/errors' |
| 13 | +import { RouteUtils } from '../../utils/route-utils' |
| 14 | +import { RoflAppsList } from '../../components/Rofl/RoflAppsList' |
| 15 | + |
| 16 | +export const LatestRoflApps: FC<{ scope: SearchScope }> = ({ scope }) => { |
| 17 | + const { t } = useTranslation() |
| 18 | + const { network, layer } = scope |
| 19 | + if (layer !== Layer.sapphire) { |
| 20 | + throw AppErrors.UnsupportedLayer |
| 21 | + } |
| 22 | + const roflAppsQuery = useGetRuntimeRoflApps(network, layer, { limit }) |
| 23 | + const { isLoading, data } = roflAppsQuery |
| 24 | + const roflApps = data?.data.rofl_apps |
| 25 | + |
| 26 | + if (!roflApps?.length) { |
| 27 | + return null |
| 28 | + } |
| 29 | + |
| 30 | + return ( |
| 31 | + <Card> |
| 32 | + <CardHeader |
| 33 | + disableTypography |
| 34 | + component="h3" |
| 35 | + title={t('rofl.listTitle')} |
| 36 | + action={ |
| 37 | + <Link |
| 38 | + component={RouterLink} |
| 39 | + to={RouteUtils.getRoflAppsRoute(scope.network)} |
| 40 | + sx={{ color: COLORS.brandDark }} |
| 41 | + > |
| 42 | + {t('common.viewAll')} |
| 43 | + </Link> |
| 44 | + } |
| 45 | + /> |
| 46 | + <CardContent> |
| 47 | + <RoflAppsList apps={roflApps} isLoading={isLoading} limit={limit} pagination={false} /> |
| 48 | + </CardContent> |
| 49 | + </Card> |
| 50 | + ) |
| 51 | +} |
0 commit comments