Skip to content

Commit

Permalink
Merge pull request #102 from reload/related-materials-preserve-materi…
Browse files Browse the repository at this point in the history
…al-order

Return related materials ordered by query instead of covers
  • Loading branch information
kasperg authored Jul 9, 2020
2 parents a216256 + 7ce2fae commit 9f4f94b
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/apps/related-materials/related-materials.entry.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,17 @@ async function getRelatedMaterials({
// Remove covers which do not have the requested cover size.
const covers = coverData.filter(cover => cover.imageUrls[coverSize]?.url);

function mergeCoverAndMaterials(cover) {
function locateCoverMaterial(material) {
function mergeMaterialsAndCovers(material) {
function locateMaterialCover(cover) {
return material.pid[0] === cover.id;
}
const material = materials.find(locateCoverMaterial);
const cover = covers.find(locateMaterialCover);
return { ...Material.format(material), cover };
}

const coveredMaterials = covers.map(mergeCoverAndMaterials);
return coveredMaterials;
const coveredMaterials = materials.map(mergeMaterialsAndCovers);
// Remove materials without covers.
return coveredMaterials.filter(material => material.cover);
}

/**
Expand Down

0 comments on commit 9f4f94b

Please sign in to comment.