Skip to content

Commit

Permalink
Choosing bestRepresentation pid as cover pid
Browse files Browse the repository at this point in the history
It is an experiment to see if we can get more covers shown.
  • Loading branch information
spaceo committed Apr 11, 2024
1 parent 45b0ad9 commit 4d1a2e8
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 16 deletions.
4 changes: 2 additions & 2 deletions src/apps/material/material.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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;
Expand Down Expand Up @@ -137,7 +137,7 @@ const Material: React.FC<MaterialProps> = ({ wid }) => {
}
} = data as { work: Work };

const pid = getManifestationPid(manifestations);
const pid = getWorkPid(work);
const detailsListData = getDetailsListData({
manifestation: selectedManifestations[0],
work,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import Link from "../../atoms/links/Link";
import {
creatorsToString,
flattenCreators,
getManifestationPid,
getWorkPid,
getReleaseYearSearchResult,
materialIsFiction
} from "../../../core/utils/helpers/general";
Expand Down Expand Up @@ -73,7 +73,7 @@ const CardListItem: React.FC<CardListItemProps> = ({
const dispatch = useDispatch<TypedDispatch>();
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,
Expand Down
5 changes: 3 additions & 2 deletions src/components/material/MaterialHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -51,6 +51,7 @@ const MaterialHeader: React.FC<MaterialHeaderProps> = ({
mainLanguages,
workId: wid
},
work,
selectedManifestations,
setSelectedManifestations,
selectedPeriodical,
Expand Down Expand Up @@ -84,7 +85,7 @@ const MaterialHeader: React.FC<MaterialHeaderProps> = ({
.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);
Expand Down
11 changes: 4 additions & 7 deletions src/components/simple-material/SimpleMaterial.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -29,9 +26,9 @@ const SimpleMaterial: FC<SimpleMaterialProps> = ({
work: {
titles: { full: fullTitle },
creators,
workId,
manifestations: { all: manifestations }
workId
},
work,
app
}) => {
const u = useUrls();
Expand All @@ -49,7 +46,7 @@ const SimpleMaterial: FC<SimpleMaterialProps> = ({
}

// For retrieving cover
const manifestationPid = getManifestationPid(manifestations);
const manifestationPid = getWorkPid(work);

const addToListRequest = (id: ButtonFavouriteId) => {
dispatch(
Expand Down
6 changes: 3 additions & 3 deletions src/core/utils/helpers/general.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down

0 comments on commit 4d1a2e8

Please sign in to comment.