Skip to content

Commit

Permalink
Merge pull request #105 from reload/related-materials-hide-if-empty
Browse files Browse the repository at this point in the history
Do not render component if there are no related materials to show
  • Loading branch information
kasperg authored Jul 12, 2020
2 parents fc51d19 + 3f9c9a5 commit dd009f8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
4 changes: 3 additions & 1 deletion src/apps/related-materials/related-materials.entry.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,11 @@ function useGetRelatedMaterials({
const finishedMaterials =
related?.filter(material => material.data)?.length || 0;
const tries = relatedMaterials.tries + 1;
// If we have no materials to show then finish using the empty state.
const endStatus = finishedMaterials > 0 ? "finished" : "empty";
const status =
finishedMaterials >= amount || tries >= maxTries
? "finished"
? endStatus
: "processing";
setRelatedMaterials({
status,
Expand Down
9 changes: 6 additions & 3 deletions src/apps/related-materials/related-materials.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,13 @@ function RelatedMaterials({
searchText,
titleText
}) {
if (status === "failed") {
// We fail discretly since there is no use in showing links or anything since the fail
// would mean a lack of works/materials.
if (status === "failed" || status === "empty") {
// Return discretly.
// When a failure occurs there is no use in showing links or anything since
// the fail would mean a lack of works/materials.
// An actual unhandled failure would still result in our error boundary.
// At the moment we also do not render anything if there are no materials
// to show.
return null;
}
return (
Expand Down

0 comments on commit dd009f8

Please sign in to comment.