diff --git a/src/apps/loan-list/modal/material-details-modal.tsx b/src/apps/loan-list/modal/material-details-modal.tsx index 554129e670..c0e1590337 100644 --- a/src/apps/loan-list/modal/material-details-modal.tsx +++ b/src/apps/loan-list/modal/material-details-modal.tsx @@ -1,3 +1,4 @@ +// Todo: Fix infinite loop in MaterialDetailsModal import React, { FC, ReactNode } from "react"; import Modal from "../../../core/utils/modal"; import { useText } from "../../../core/utils/text"; @@ -33,6 +34,7 @@ const MaterialDetailsModal: FC = ({ children }) => { const t = useText(); + // console.log("Rendering MaterialDetailsModal:"); if (!modalId) { return null; diff --git a/src/apps/loan-list/modal/material-details.tsx b/src/apps/loan-list/modal/material-details.tsx index 090f4b5c6b..f3a99b6ffa 100644 --- a/src/apps/loan-list/modal/material-details.tsx +++ b/src/apps/loan-list/modal/material-details.tsx @@ -2,7 +2,6 @@ import React, { FC, useState } from "react"; import ReservationIcon from "@danskernesdigitalebibliotek/dpl-design-system/build/icons/collection/Reservations.svg"; import LoansIcon from "@danskernesdigitalebibliotek/dpl-design-system/build/icons/collection/Loans.svg"; import EbookIcon from "@danskernesdigitalebibliotek/dpl-design-system/build/icons/collection/Ebook.svg"; -import ExternalLinkIcon from "@danskernesdigitalebibliotek/dpl-design-system/build/icons/buttons/icon-btn-external-link.svg"; import { useText } from "../../../core/utils/text"; import { isDigital } from "../utils/helpers"; import { materialIsOverdue } from "../../../core/utils/helpers/general"; @@ -22,6 +21,7 @@ import { RequestStatus } from "../../../core/utils/types/request"; import { RenewedLoanV2 } from "../../../core/fbs/model"; import RenewalModalMessage from "../../../components/renewal/RenewalModalMessage"; import { formatDate } from "../../../core/utils/helpers/date"; +import useGetWorkUrlFromIdentifier from "../../../core/utils/useGetWorkUrlFromIdentifier"; interface MaterialDetailsProps { loan: LoanType | null; @@ -33,6 +33,7 @@ const MaterialDetails: FC = ({ material, modalId }) => { + const { workUrl } = useGetWorkUrlFromIdentifier(loan?.identifier); const [renewingStatus, setRenewingStatus] = useState("idle"); const [renewingResponse, setRenewingResponse] = useState< RenewedLoanV2[] | null @@ -40,7 +41,6 @@ const MaterialDetails: FC = ({ const t = useText(); const u = useUrls(); - const ereolenMyPageUrl = u("ereolenMyPageUrl"); const viewFeesAndCompensationRatesUrl = u("viewFeesAndCompensationRatesUrl"); if (!loan) { @@ -119,18 +119,13 @@ const MaterialDetails: FC = ({ renewalStatusList={renewalStatusList} /> )} - {isDigital(loan) && ( + {isDigital(loan) && workUrl && (
- {t("materialDetailsGoToEreolenText")} - + {t("materialDetailsGoToMaterialText")}
)} @@ -186,18 +181,13 @@ const MaterialDetails: FC = ({ renewalStatusList={renewalStatusList} /> )} - {isDigital(loan) && ( + {isDigital(loan) && workUrl && (
- {t("materialDetailsGoToEreolenText")} - + {t("materialDetailsGoToMaterialText")}
)} diff --git a/src/apps/material/material.entry.tsx b/src/apps/material/material.entry.tsx index e2219c24be..c6ff6773ce 100644 --- a/src/apps/material/material.entry.tsx +++ b/src/apps/material/material.entry.tsx @@ -102,6 +102,8 @@ interface MaterialEntryTextProps { okButtonText: string; onlineLimitMonthAudiobookInfoText: string; onlineLimitMonthEbookInfoText: string; + onlineMaterialPlayerText: string; + onlineMaterialReaderText: string; onlineMaterialTeaserText: string; openOrderAuthenticationErrorText: string; openOrderErrorMissingPincodeText: string; diff --git a/src/apps/material/material.stories.tsx b/src/apps/material/material.stories.tsx index 3f559b63e5..2193e620e8 100644 --- a/src/apps/material/material.stories.tsx +++ b/src/apps/material/material.stories.tsx @@ -303,6 +303,14 @@ const meta: Meta = { description: "Online limit info text", control: { type: "text" } }, + onlineMaterialPlayerText: { + description: "Material button online player text", + control: { type: "text" } + }, + onlineMaterialReaderText: { + description: "Material button online reader text", + control: { type: "text" } + }, onlineMaterialTeaserText: { description: "Material button online teaser text", control: { type: "text" } @@ -795,6 +803,8 @@ const meta: Meta = { "You have borrowed @count out of @limit possible e-books this month", onlineLimitMonthAudiobookInfoText: "You have borrowed @count out of @limit possible audio-books this month", + onlineMaterialPlayerText: "Listen to @materialType", + onlineMaterialReaderText: "Read @materialType", onlineMaterialTeaserText: "Try @materialType", approveReservationText: "Approve reservation", shiftText: "Change", diff --git a/src/apps/material/material.tsx b/src/apps/material/material.tsx index 051f98c84d..65a60e1021 100644 --- a/src/apps/material/material.tsx +++ b/src/apps/material/material.tsx @@ -33,14 +33,13 @@ import { getBestMaterialTypeForWork, getDetailsListData, getInfomediaIds, - getManifestationIsbn, getManifestationsOrderByTypeAndYear, isParallelReservation } from "./helper"; import MaterialDisclosure from "./MaterialDisclosure"; import ReservationFindOnShelfModals from "./ReservationFindOnShelfModals"; import PlayerModal from "../../components/material/player-modal/PlayerModal"; -import { hasPlayerManifestation } from "../../components/reader-player/helper"; +import useReaderPlayer from "../../core/utils/useReaderPlayer"; export interface MaterialProps { wid: WorkId; @@ -57,6 +56,11 @@ const Material: React.FC = ({ wid }) => { const { data: userData } = usePatronData(); const [isUserBlocked, setIsUserBlocked] = useState(null); const { track } = useStatistics(); + const { + type: readerPlayerType, + identifier, + orderId + } = useReaderPlayer(selectedManifestations); useEffect(() => { setIsUserBlocked(!!(userData?.patron && isBlocked(userData.patron))); @@ -173,7 +177,6 @@ const Material: React.FC = ({ wid }) => { setSelectedPeriodical={setSelectedPeriodical} /> ))} - {infomediaIds.length > 0 && !isAnonymous() && !isUserBlocked && ( = ({ wid }) => { setSelectedPeriodical={setSelectedPeriodical} /> )} - {hasPlayerManifestation(selectedManifestations) && ( - + {readerPlayerType === "player" && ( + <> + {identifier && } + {orderId && } + )} diff --git a/src/components/material/material-buttons/online/MaterialButtonsOnlineInternal.tsx b/src/components/material/material-buttons/online/MaterialButtonsOnlineInternal.tsx index bda5d7e347..9c05d469c3 100644 --- a/src/components/material/material-buttons/online/MaterialButtonsOnlineInternal.tsx +++ b/src/components/material/material-buttons/online/MaterialButtonsOnlineInternal.tsx @@ -1,16 +1,14 @@ import React, { FC } from "react"; import { Manifestation } from "../../../../core/utils/types/entities"; -import { - hasPlayerManifestation, - hasReaderManifestation -} from "../../../reader-player/helper"; import MaterialSecondaryLink from "../generic/MaterialSecondaryLink"; import MaterialSecondaryButton from "../generic/MaterialSecondaryButton"; import { playerModalId } from "../../player-modal/helper"; -import { getManifestationIsbn } from "../../../../apps/material/helper"; import { useModalButtonHandler } from "../../../../core/utils/modal"; import { useText } from "../../../../core/utils/text"; import { ButtonSize } from "../../../../core/utils/types/button"; +import useReaderPlayer from "../../../../core/utils/useReaderPlayer"; +import LinkButton from "../../../Buttons/LinkButton"; +import { Button } from "../../../Buttons/Button"; type MaterialButtonsOnlineInternalType = { size?: ButtonSize; @@ -25,41 +23,109 @@ const MaterialButtonsOnlineInternal: FC = ({ }) => { const t = useText(); const { open } = useModalButtonHandler(); + const { type, orderId, identifier } = useReaderPlayer(manifestations); - return ( - <> - {/* Todo: add logic for the reservation / loan / Read / Listen buttons here */} + const renderReaderButton = () => { + if (orderId) { + return ( + + {t("onlineMaterialReaderText", { + placeholders: { "@materialType": t("ebookText") } + })} + + ); + } + + return null; + }; - {hasReaderManifestation(manifestations) && ( + const renderReaderTeaserButton = () => { + if (orderId) return null; + + if (identifier) { + return ( - )} - {hasPlayerManifestation(manifestations) && ( + ); + } + return null; + }; + + const renderPlayerButton = () => { + if (orderId) { + return ( +