Renacer Social, the app

LawListPage.tsx 1.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import {
  2. IonContent,
  3. IonHeader,
  4. IonLoading,
  5. IonPage,
  6. IonTitle,
  7. IonToast,
  8. IonToolbar,
  9. } from "@ionic/react";
  10. import { alertCircleOutline } from "ionicons/icons";
  11. import useSWR from "swr";
  12. import TopicList from "../components/TopicList";
  13. import { fetcher } from "../lib/api";
  14. import { Topic } from "../types";
  15. const LawListPage: React.FC = () => {
  16. const { data, error } = useSWR<Topic[]>(
  17. "/api/getTopicList?type=laws",
  18. fetcher
  19. );
  20. const isLoading = !data && !error;
  21. return (
  22. <IonPage>
  23. <IonHeader>
  24. <IonToolbar>
  25. <IonTitle>Leyes</IonTitle>
  26. </IonToolbar>
  27. </IonHeader>
  28. <IonContent fullscreen>
  29. <IonHeader collapse="condense">
  30. <IonToolbar>
  31. <IonTitle size="large">Leyes</IonTitle>
  32. </IonToolbar>
  33. </IonHeader>
  34. {data && <TopicList loading={isLoading} topics={data as Topic[]} />}
  35. <IonToast
  36. icon={alertCircleOutline}
  37. color="danger"
  38. isOpen={error !== undefined}
  39. message="Failed to load items."
  40. duration={1500}
  41. />
  42. </IonContent>
  43. </IonPage>
  44. );
  45. };
  46. export default LawListPage;