Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Favorite Page skeleton view [DDFLSBP-484] #1077

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 58 additions & 29 deletions src/apps/favorites-list/FavoritesList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@ 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;
}

const FavoritesList: React.FC<FavoritesListProps> = ({ pageSize }) => {
const t = useText();
const { data } = useGetList("default");
const { data, isLoading } = useGetList("default");
const [displayedMaterials, setDisplayedMaterials] = useState<Pid[]>([]);
const [materials, setMaterials] = useState<Pid[]>([]);
const { itemsShown, PagerComponent, page } = usePager({
Expand Down Expand Up @@ -41,40 +42,68 @@ const FavoritesList: React.FC<FavoritesListProps> = ({ pageSize }) => {
}
}, [collections, data]);

const skeletonList = (
<>
<div className="ssc">
<div className="ssc-line w-10 my-32">&nbsp;</div>
</div>
<ul className="card-list-page__list my-32">
{/*
We'll show 5 skeleton cards which should cover most screens.
*/}
{[...Array(5)].map(() => (
<li>
<CardListItemSkeleton />
</li>
))}
</ul>
</>
);

const materialsCount = materials.length > 0 && (
<p className="text-small-caption my-32">
{t("favoritesListMaterialsText", {
placeholders: { "@count": materials.length }
})}
</p>
);

const renderContent = () =>
displayedMaterials.length > 0 ? (
<ul className="card-list-page__list my-32">
{displayedMaterials.map((pid, i) => {
const isFirstNewItem = i === page * pageSize;
return (
<MaterialListItem
key={pid}
ref={isFirstNewItem ? lastItemRef : null}
>
<CardListItemAdapter pid={pid} />
</MaterialListItem>
);
})}
</ul>
) : (
<EmptyList
classNames="mt-24"
emptyListText={t("favoritesListEmptyText")}
/>
);

return (
<div className="card-list-page">
<h1 className="text-header-h2 mb-16 search-result-title">
{t("favoritesListHeaderText")}
</h1>
{materials.length > 0 && (
<p className="text-small-caption my-32">
{t("favoritesListMaterialsText", {
placeholders: { "@count": materials.length }
})}
</p>
)}
{displayedMaterials.length > 0 && (
<ul className="card-list-page__list my-32">
{displayedMaterials.map((pid, i) => {
const isFirstNewItem = i === page * pageSize;
return (
<MaterialListItem
key={pid}
ref={isFirstNewItem ? lastItemRef : null}
>
<CardListItemAdapter key={pid} pid={pid} />
</MaterialListItem>
);
})}
</ul>
)}
{displayedMaterials.length === 0 && (
<EmptyList
classNames="mt-24"
emptyListText={t("favoritesListEmptyText")}
/>
{isLoading ? (
skeletonList
) : (
<>
{materialsCount}
{renderContent()}
<PagerComponent />
</>
)}
<PagerComponent />
</div>
);
};
Expand Down
3 changes: 3 additions & 0 deletions src/apps/favorites-list/favorites-list.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ describe("Favorites list", () => {
});

it("Favorites list basics", () => {
// Wait for element not in skeleton screen to prevent testing prematurely.
cy.get(".cover").should("be.visible");

// 2.a. Header "Favorites"
cy.get(".card-list-page").find("h1").should("have.text", "Favorites");
// Number of materials on list
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<CardListItemAdapterProps> = ({ pid }) => {
const { data } = useGetSmallWorkQuery({
const { data, isLoading } = useGetSmallWorkQuery({
id: pid
});

if (isLoading) return <CardListItemSkeleton />;

return (
<div>
{data && data.work && (
Expand Down
Loading