From 87107ff7836b711c2058679b772088fea7cadb71 Mon Sep 17 00:00:00 2001 From: Jacob Pihl Date: Thu, 9 Nov 2023 15:55:56 +0100 Subject: [PATCH] Show skeleton loader when fetching materials To make it visible to the user that we are fetching materials, we are showing a skeleton loader on the materials we are waiting to finish fetching --- .../materials/utils/material-fetch-hoc.tsx | 9 +++++++-- .../reservation-material/reservation-material.tsx | 15 ++++++++++++++- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/apps/loan-list/materials/utils/material-fetch-hoc.tsx b/src/apps/loan-list/materials/utils/material-fetch-hoc.tsx index a2cc270c69..94cc51119e 100644 --- a/src/apps/loan-list/materials/utils/material-fetch-hoc.tsx +++ b/src/apps/loan-list/materials/utils/material-fetch-hoc.tsx @@ -17,7 +17,8 @@ type InputProps = { const fetchMaterial =

( - Component: ComponentType

+ Component: ComponentType

, + FallbackComponent?: ComponentType ): FC

=> ({ identifier, faust, ...props }: InputProps) => { // If this is a digital book, another HOC fetches the data and this @@ -48,7 +49,11 @@ const fetchMaterial = } }, [isSuccessManifestation, data]); - if (!material) return null; + // in cases where the material is not found we return null, else we would load forever + if (data && data.manifestation === null) return null; + + // if the fallback component is provided we can show it while the data is loading + if (!material) return FallbackComponent ? : null; return ( = ({ ); }; -export default fetchDigitalMaterial(fetchMaterial(ReservationMaterial)); +const ReservationMaterialSkeleton: FC = () => { + return ( +

  • +
    + +
    +
  • + ); +}; + +export default fetchDigitalMaterial( + fetchMaterial(ReservationMaterial, ReservationMaterialSkeleton) +);