From 4d1a2e8a8896c588e5bfe0ade9e5871246df16e0 Mon Sep 17 00:00:00 2001 From: Mikkel Jakobsen Date: Thu, 11 Apr 2024 13:49:41 +0200 Subject: [PATCH] Choosing bestRepresentation pid as cover pid It is an experiment to see if we can get more covers shown. --- src/apps/material/material.tsx | 4 ++-- .../card-item-list/card-list-item/card-list-item.tsx | 4 ++-- src/components/material/MaterialHeader.tsx | 5 +++-- src/components/simple-material/SimpleMaterial.tsx | 11 ++++------- src/core/utils/helpers/general.ts | 6 +++--- 5 files changed, 14 insertions(+), 16 deletions(-) diff --git a/src/apps/material/material.tsx b/src/apps/material/material.tsx index 68abb8ebaa..88ab94e004 100644 --- a/src/apps/material/material.tsx +++ b/src/apps/material/material.tsx @@ -22,7 +22,6 @@ import { isParallelReservation } from "./helper"; import { Manifestation, Work } from "../../core/utils/types/entities"; -import { getManifestationPid } from "../../core/utils/helpers/general"; import { PeriodicalEdition } from "../../components/material/periodical/helper"; import InfomediaModal from "../../components/material/infomedia/InfomediaModal"; import { useStatistics } from "../../core/statistics/useStatistics"; @@ -38,6 +37,7 @@ import { isAnonymous, isBlocked } from "../../core/utils/helpers/user"; import ReservationFindOnShelfModals from "./ReservationFindOnShelfModals"; import { usePatronData } from "../../core/utils/helpers/usePatronData"; import { useGetWork } from "../../core/utils/useGetWork"; +import { getWorkPid } from "../../core/utils/helpers/general"; export interface MaterialProps { wid: WorkId; @@ -137,7 +137,7 @@ const Material: React.FC = ({ wid }) => { } } = data as { work: Work }; - const pid = getManifestationPid(manifestations); + const pid = getWorkPid(work); const detailsListData = getDetailsListData({ manifestation: selectedManifestations[0], work, diff --git a/src/components/card-item-list/card-list-item/card-list-item.tsx b/src/components/card-item-list/card-list-item/card-list-item.tsx index 23cd355996..9e1e194449 100644 --- a/src/components/card-item-list/card-list-item/card-list-item.tsx +++ b/src/components/card-item-list/card-list-item/card-list-item.tsx @@ -13,7 +13,7 @@ import Link from "../../atoms/links/Link"; import { creatorsToString, flattenCreators, - getManifestationPid, + getWorkPid, getReleaseYearSearchResult, materialIsFiction } from "../../../core/utils/helpers/general"; @@ -73,7 +73,7 @@ const CardListItem: React.FC = ({ const dispatch = useDispatch(); const queryClient = useQueryClient(); const author = creatorsToString(flattenCreators(creators), t); - const manifestationPid = getManifestationPid(manifestations); + const manifestationPid = getWorkPid(item); const firstItemInSeries = getNumberedSeries(series).shift(); const materialFullUrl = constructMaterialUrl( materialUrl, diff --git a/src/components/material/MaterialHeader.tsx b/src/components/material/MaterialHeader.tsx index 45d5044fb4..8eb6742352 100644 --- a/src/components/material/MaterialHeader.tsx +++ b/src/components/material/MaterialHeader.tsx @@ -9,7 +9,7 @@ import { creatorsToString, flattenCreators, getMaterialTypes, - getManifestationPid + getWorkPid } from "../../core/utils/helpers/general"; import { useText } from "../../core/utils/text"; import { WorkId } from "../../core/utils/types/ids"; @@ -51,6 +51,7 @@ const MaterialHeader: React.FC = ({ mainLanguages, workId: wid }, + work, selectedManifestations, setSelectedManifestations, selectedPeriodical, @@ -84,7 +85,7 @@ const MaterialHeader: React.FC = ({ .map((language) => language.display) .join(", "); const title = containsDanish ? fullTitle : `${fullTitle} (${allLanguages})`; - const pid = getManifestationPid(manifestations); + const pid = getWorkPid(work); const { track } = useStatistics(); // This is used to track whether the user is changing between material types or just clicking the same button over const manifestationMaterialTypes = getMaterialTypes(selectedManifestations); diff --git a/src/components/simple-material/SimpleMaterial.tsx b/src/components/simple-material/SimpleMaterial.tsx index 8d94a32547..ca4b32aa6c 100644 --- a/src/components/simple-material/SimpleMaterial.tsx +++ b/src/components/simple-material/SimpleMaterial.tsx @@ -7,10 +7,7 @@ import ButtonFavourite, { } from "../button-favourite/button-favourite"; import { Cover } from "../cover/cover"; import { Work } from "../../core/utils/types/entities"; -import { - getContributors, - getManifestationPid -} from "../../core/utils/helpers/general"; +import { getContributors, getWorkPid } from "../../core/utils/helpers/general"; import { TypedDispatch } from "../../core/store"; import { guardedRequest } from "../../core/guardedRequests.slice"; import { constructMaterialUrl } from "../../core/utils/helpers/url"; @@ -29,9 +26,9 @@ const SimpleMaterial: FC = ({ work: { titles: { full: fullTitle }, creators, - workId, - manifestations: { all: manifestations } + workId }, + work, app }) => { const u = useUrls(); @@ -49,7 +46,7 @@ const SimpleMaterial: FC = ({ } // For retrieving cover - const manifestationPid = getManifestationPid(manifestations); + const manifestationPid = getWorkPid(work); const addToListRequest = (id: ButtonFavouriteId) => { dispatch( diff --git a/src/core/utils/helpers/general.ts b/src/core/utils/helpers/general.ts index f56135d25b..b6b085d171 100644 --- a/src/core/utils/helpers/general.ts +++ b/src/core/utils/helpers/general.ts @@ -96,9 +96,9 @@ export const getFirstPublishedYear = (manifestations: Manifestation[]) => { ); }; -export const getManifestationPid = (manifestations: Manifestation[]) => { - const ordered = orderManifestationsByYear(manifestations); - return ordered[0].pid; +// This function is used to find the most representative pid of a work. +export const getWorkPid = (work: Work) => { + return work.manifestations.bestRepresentation.pid || null; }; export const getCoverTint = (index: number) => {