Skip to content
This repository was archived by the owner on Jun 25, 2025. It is now read-only.

Commit 7ce2fae

Browse files
committed
Return related materials ordered by query instead of covers
In the current version we retrieve object ids from search result, pass these to the cover service in the same order and merge material data intro the provided results. However practice has shown that the cover service does not necessarily preserve the order of the requested ids in the response. This leads to a situation where the related materials will not have the same order as in the linked search result. To preserve the order of the materials from the search result we merge cover data into the materials instead and filter away any materials without a cover.
1 parent e0dc8bf commit 7ce2fae

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

src/apps/related-materials/related-materials.entry.jsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,16 +50,17 @@ async function getRelatedMaterials({
5050
// Remove covers which do not have the requested cover size.
5151
const covers = coverData.filter(cover => cover.imageUrls[coverSize]?.url);
5252

53-
function mergeCoverAndMaterials(cover) {
54-
function locateCoverMaterial(material) {
53+
function mergeMaterialsAndCovers(material) {
54+
function locateMaterialCover(cover) {
5555
return material.pid[0] === cover.id;
5656
}
57-
const material = materials.find(locateCoverMaterial);
57+
const cover = covers.find(locateMaterialCover);
5858
return { ...Material.format(material), cover };
5959
}
6060

61-
const coveredMaterials = covers.map(mergeCoverAndMaterials);
62-
return coveredMaterials;
61+
const coveredMaterials = materials.map(mergeMaterialsAndCovers);
62+
// Remove materials without covers.
63+
return coveredMaterials.filter(material => material.cover);
6364
}
6465

6566
/**

0 commit comments

Comments
 (0)