Proyectos de Subversion LeadersLinked - SPA

Rev

Rev 3659 | Autoría | Comparar con el anterior | Ultima modificación | Ver Log |

import React from 'react';
import { useParams } from 'react-router-dom';
import { Link } from 'react-router-dom';

import { useAlert, useApi } from '@shared/hooks';
import { getTopic } from '@microlearning/services';

import { Grid, PageHeader, Spinner } from '@shared/components';
import { CapsuleCard } from '@microlearning/components';

export function TopicPage() {
  const { uuid } = useParams();

  const { showError } = useAlert();

  const { data: topic, loading } = useApi(getTopic, {
    autoFetch: true,
    autoFetchArgs: [uuid],
    onError: (error) => {
      showError(error.message);
    }
  });

  if (loading || !topic) return <Spinner />;

  return (
    <>
      <PageHeader title={`${topic?.name} - Cápsulas`} goBack />
      <Grid
        items={topic.capsules}
        emptyMessage='No hay cápsulas para mostrar'
        renderItem={(capsule) => (
          <Link to={`/microlearning/capsules/${capsule.uuid}`}>
            <CapsuleCard capsule={capsule} />
          </Link>
        )}
        keyExtractor={(capsule) => capsule.uuid}
      />
    </>
  );
}