Skip to content

Commit

Permalink
Reintroduce MaterialAvailabilityText for online manifestations
Browse files Browse the repository at this point in the history
This was partially removed by misunderstanding in [DDFBRA-49](https://reload.atlassian.net/browse/DDFBRA-49).

It has now been reintroduced along with an update to `MaterialAvailabilityTextOnline`, ensuring it checks for all e-materials (Publizon).

Here is the commit where it was removed:
[b28c225](b28c225)
  • Loading branch information
kasperbirch1 committed Dec 17, 2024
1 parent 0baed0c commit 089e11f
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { useText } from "../../../../core/utils/text";
import MaterialAvailabilityTextParagraph from "../generic/MaterialAvailabilityTextParagraph";
import { ManifestationMaterialType } from "../../../../core/utils/types/material-type";
import { AvailabilityTextMap, getAvailabilityText } from "./helper";
import { playerTypes, readerTypes } from "../../../reader-player/helper";

interface MaterialAvailabilityTextOnlineProps {
isbns: string[];
Expand Down Expand Up @@ -43,16 +44,26 @@ const MaterialAvailabilityTextOnline: React.FC<
} = libraryProfileData;

const availabilityTextMap: AvailabilityTextMap = {
[ManifestationMaterialType.ebook]: {
text: "onlineLimitMonthEbookInfoText",
count: totalEbookLoans,
limit: maxConcurrentEbookLoansPerBorrower
},
[ManifestationMaterialType.audioBook]: {
text: "onlineLimitMonthAudiobookInfoText",
count: totalAudioLoans,
limit: maxConcurrentAudioLoansPerBorrower
},
...Object.fromEntries(
readerTypes.map((type) => [
type,
{
text: "onlineLimitMonthEbookInfoText",
count: totalEbookLoans,
limit: maxConcurrentEbookLoansPerBorrower
}
])
),
...Object.fromEntries(
playerTypes.map((type) => [
type,
{
text: "onlineLimitMonthAudiobookInfoText",
count: totalAudioLoans,
limit: maxConcurrentAudioLoansPerBorrower
}
])
),
materialIsIncluded: {
text: "materialIsIncludedText"
}
Expand Down
7 changes: 3 additions & 4 deletions src/components/material/MaterialHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,10 @@ const MaterialHeader: React.FC<MaterialHeaderProps> = ({
);
// We need availability in order to show availability text under action buttons
const { isAvailable } = useAvailabilityData({
// "accessTypes" will always be physical here - shouldShowMaterialAvailabilityText() helper
// rules out all online materials.
accessTypes: [AccessTypeCodeEnum.Physical],
accessTypes: [AccessTypeCodeEnum.Physical, AccessTypeCodeEnum.Online],
access: [undefined],
faustIds: getAllFaustIds(selectedManifestations),
isbn: null, // Not needed for physical materials.
isbn: null, // Not needed.
// "manifestText" is used inside the availability hook to check whether the material is an article
// which we check inside shouldShowMaterialAvailabilityText() helper here.
manifestText: "NOT AN ARTICLE"
Expand Down Expand Up @@ -179,6 +177,7 @@ const MaterialHeader: React.FC<MaterialHeaderProps> = ({
/>
</div>
{/* MaterialAvailabilityText is only shown for:
- Online manifestations if the user is logged in
- physical manifestations
- that are not periodical or articles
- that are available in at least one local library branch
Expand Down
18 changes: 15 additions & 3 deletions src/components/material/helper.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { AccessTypeCodeEnum } from "../../core/dbc-gateway/generated/graphql";
import { isAnonymous } from "../../core/utils/helpers/user";
import { Manifestation } from "../../core/utils/types/entities";
import { ManifestationMaterialType } from "../../core/utils/types/material-type";
import { getReaderPlayerType } from "../reader-player/helper";
import { hasCorrectMaterialType, isArticle } from "./material-buttons/helper";

export const isPhysical = (manifestations: Manifestation[]) => {
Expand All @@ -18,14 +20,24 @@ export const isPeriodical = (manifestations: Manifestation[]) => {
);
};

export const isMaterialButtonsOnlineInternal = (
manifestations: Manifestation[]
) => {
return Boolean(getReaderPlayerType(manifestations));
};

export const shouldShowMaterialAvailabilityText = (
manifestations: Manifestation[]
) => {
return (
const isOnlineMaterial =
!isAnonymous() && isMaterialButtonsOnlineInternal(manifestations);

const isPhysicalMaterial =
isPhysical(manifestations) &&
!isPeriodical(manifestations) &&
!isArticle(manifestations)
);
!isArticle(manifestations);

return isOnlineMaterial || isPhysicalMaterial;
};

export default {};
28 changes: 14 additions & 14 deletions src/components/reader-player/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,25 +84,25 @@ export const getOrderIdByIdentifier = ({
return loanWithIdentifier ? loanWithIdentifier.orderId : null;
};

export const readerTypes = [
ManifestationMaterialType.ebook,
ManifestationMaterialType.pictureBookOnline,
ManifestationMaterialType.animatedSeriesOnline,
ManifestationMaterialType.yearBookOnline
];

export const playerTypes = [
ManifestationMaterialType.audioBook,
ManifestationMaterialType.podcast,
ManifestationMaterialType.musicOnline,
ManifestationMaterialType.audioBookTape
];

export const getReaderPlayerType = (
manifestations: Manifestation[]
): "reader" | "player" | null => {
const materialTypes = getMaterialTypes(manifestations);

const readerTypes = [
ManifestationMaterialType.ebook,
ManifestationMaterialType.pictureBookOnline,
ManifestationMaterialType.animatedSeriesOnline,
ManifestationMaterialType.yearBookOnline
];

const playerTypes = [
ManifestationMaterialType.audioBook,
ManifestationMaterialType.podcast,
ManifestationMaterialType.musicOnline,
ManifestationMaterialType.audioBookTape
];

if (readerTypes.some((type) => materialTypes.includes(type))) return "reader";
if (playerTypes.some((type) => materialTypes.includes(type))) return "player";

Expand Down

0 comments on commit 089e11f

Please sign in to comment.