diff --git a/src/apps/favorites-list/FavoritesList.tsx b/src/apps/favorites-list/FavoritesList.tsx index 17f04c2064..6bf7195e32 100644 --- a/src/apps/favorites-list/FavoritesList.tsx +++ b/src/apps/favorites-list/FavoritesList.tsx @@ -6,6 +6,7 @@ import { useText } from "../../core/utils/text"; import { Pid } from "../../core/utils/types/ids"; import CardListItemAdapter from "../../components/card-item-list/card-list-item/card-list-item-adapter"; import MaterialListItem from "../../components/card-item-list/MaterialListItem"; +import CardListItemSkeleton from "../../components/card-item-list/card-list-item/card-list-item-skeleton"; export interface FavoritesListProps { pageSize: number; @@ -13,7 +14,7 @@ export interface FavoritesListProps { const FavoritesList: React.FC = ({ pageSize }) => { const t = useText(); - const { data } = useGetList("default"); + const { data, isLoading } = useGetList("default"); const [displayedMaterials, setDisplayedMaterials] = useState([]); const [materials, setMaterials] = useState([]); const { itemsShown, PagerComponent, page } = usePager({ @@ -41,40 +42,68 @@ const FavoritesList: React.FC = ({ pageSize }) => { } }, [collections, data]); + const skeletonList = ( + <> +
+
 
+
+
    + {/* + We'll show 5 skeleton cards which should cover most screens. + */} + {[...Array(5)].map(() => ( +
  • + +
  • + ))} +
+ + ); + + const materialsCount = materials.length > 0 && ( +

+ {t("favoritesListMaterialsText", { + placeholders: { "@count": materials.length } + })} +

+ ); + + const renderContent = () => + displayedMaterials.length > 0 ? ( +
    + {displayedMaterials.map((pid, i) => { + const isFirstNewItem = i === page * pageSize; + return ( + + + + ); + })} +
+ ) : ( + + ); + return (

{t("favoritesListHeaderText")}

- {materials.length > 0 && ( -

- {t("favoritesListMaterialsText", { - placeholders: { "@count": materials.length } - })} -

- )} - {displayedMaterials.length > 0 && ( -
    - {displayedMaterials.map((pid, i) => { - const isFirstNewItem = i === page * pageSize; - return ( - - - - ); - })} -
- )} - {displayedMaterials.length === 0 && ( - + {isLoading ? ( + skeletonList + ) : ( + <> + {materialsCount} + {renderContent()} + + )} -
); }; diff --git a/src/components/card-item-list/card-list-item/card-list-item-adapter.tsx b/src/components/card-item-list/card-list-item/card-list-item-adapter.tsx index d87614b41c..106dfc046d 100644 --- a/src/components/card-item-list/card-list-item/card-list-item-adapter.tsx +++ b/src/components/card-item-list/card-list-item/card-list-item-adapter.tsx @@ -3,15 +3,19 @@ import { useGetSmallWorkQuery } from "../../../core/dbc-gateway/generated/graphq import { Work } from "../../../core/utils/types/entities"; import CardListItem from "./card-list-item"; import { Pid } from "../../../core/utils/types/ids"; +import CardListItemSkeleton from "./card-list-item-skeleton"; export interface CardListItemAdapterProps { pid: Pid; } const CardListItemAdapter: FC = ({ pid }) => { - const { data } = useGetSmallWorkQuery({ + const { data, isLoading } = useGetSmallWorkQuery({ id: pid }); + + if (isLoading) return ; + return (
{data && data.work && (