Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: DDFBRA-251 - User can open their loaned e materials #1573

Conversation

kasperbirch1
Copy link
Contributor

@kasperbirch1 kasperbirch1 commented Dec 6, 2024

Link to issue

https://reload.atlassian.net/browse/DDFBRA-251

Description

This pull request ensures that users who already have a digital loan (OrderId) at Publizon will see a button labeled either "Read" or "Listen to @materialType."

Changes Made:

  1. Added orderId to LoanType and included it in the return of mapPublizonLoanToLoanType.
  2. Introduced a new hook, useReaderPlayer, which accepts selectedManifestations and returns an orderId if the identifier for the selectedManifestations exists in the Publizon loans retrieved from useLoans.

### Known Issues:
This is a WIP because an issue with FocusTrap still needs to be resolved. Currently, FocusTrap is temporarily set to active={false} to avoid blocking further testing.

@kasperbirch1 kasperbirch1 force-pushed the DDFBRA-251-logged-in-user-can-open-their-loaned-e-material branch from 6a06120 to f11511b Compare December 10, 2024 14:23
While investigating https://reload.atlassian.net/browse/DDFBRA-236, I identified an infinite loop in `MaterialDetailsModal`. This issue appears when the modal is opened via "user/loans" and potentially all places it is used
Since all data from loans comes from Publizon, we don’t have a `workId`, which is required to link to the material. Therefore, I use the `useComplexSearchWithPaginationQuery` to find the work using the ISBN (identifier) and construct the `workId` into a URL, e.g., `/work/work-of:870970-basis:62986115`.  Additionally, if it finds the material type, it adds that as a parameter.
This commit ensures that users who already have a digital loan (OrderId) at Publizon will see a button labeled either "Read" or "Listen to @materialType."

### Changes Made:
1. Added `orderId` to `LoanType` and included it in the return of `mapPublizonLoanToLoanType`.
2. Introduced a new hook, `useReaderPlayerButtons`, which accepts `selectedManifestations` and returns an `orderId` if the identifier for the `selectedManifestations` exists in the Publizon loans retrieved from `useLoans`.

### Known Issues:
This is a WIP because an issue with `FocusTrap` still needs to be resolved. Currently, `FocusTrap` is temporarily set to `active={false}` to avoid blocking further testing.
This change was required to avoid removing the `FocusTrap` from the modal, as it states: "Your focus-trap must have at least one container with at least one tabbable node in it at all times."

I spent some time attempting to use `createPortal` to manage a single modal in `material.tsx`, but this approach does not work because the modal is only rendered after it is opened.

The solution is to include both modals in `material.tsx` and utilize the existing `useReaderPlayerButtons` hook to determine whether the modal should render. This necessitated a small refactor to handle scenarios where there are no `manifestations`.

Additionally, I made a minor cleanup, but further improvements are still needed.
Eliminate redundant code, prevent duplicate invocations of `getMaterialTypes`, and consolidate the logic into a single function for determining the type. Use the `type` from `useReaderPlayerButtons` to control when player logic is enabled.
It is now also used to determine the modals, so a more generic name is appropriate.
@kasperbirch1 kasperbirch1 force-pushed the DDFBRA-236-logged-in-user-can-go-from-digital-loans-to-material-to-listen-read branch from c02d269 to 94c6cd2 Compare December 11, 2024 08:40
@kasperbirch1 kasperbirch1 force-pushed the DDFBRA-251-logged-in-user-can-open-their-loaned-e-material branch from f11511b to c3a9bcf Compare December 11, 2024 08:40
Perhaps there should be some logic in `useLoans` or `useReaderPlayer` to prevent them from being called if no user is logged in.
This change optimizes the `useReaderPlayer` hook to fetch data from Publizon only if the user is logged in. The hook now uses `useGetV1UserLoans` instead of `useLoans`, ensuring that only the necessary data is fetched. This update also makes the hook more reusable for the "Go-project" and prevents the need to add translation strings for `expirationWarningDaysBeforeConfig` in the Material app.

Additionally, this update prevents the Cypress test from failing by ensuring the API's is called only when the user is logged in.
as the reader page in Drupal doesn't support camelCase.

See this commit:
danskernesdigitalebibliotek/dpl-cms@1279f27 ("Rename orderid to lowercase
")
There is no reason to try borrowing a material that the user has already loaned.
kasperbirch1 added a commit to danskernesdigitalebibliotek/dpl-cms that referenced this pull request Dec 12, 2024
kasperbirch1 added a commit to danskernesdigitalebibliotek/dpl-cms that referenced this pull request Dec 12, 2024
kasperbirch1 added a commit to danskernesdigitalebibliotek/dpl-cms that referenced this pull request Dec 12, 2024
@kasperbirch1 kasperbirch1 changed the base branch from DDFBRA-236-logged-in-user-can-go-from-digital-loans-to-material-to-listen-read to reader-player-feature December 13, 2024 10:52
@kasperbirch1 kasperbirch1 merged commit 4dbc5d2 into reader-player-feature Dec 13, 2024
20 checks passed
@kasperbirch1 kasperbirch1 deleted the DDFBRA-251-logged-in-user-can-open-their-loaned-e-material branch December 13, 2024 10:56
@kasperbirch1 kasperbirch1 mentioned this pull request Dec 13, 2024
kasperbirch1 added a commit that referenced this pull request Dec 17, 2024
…logged-in-user-can-open-their-loaned-e-material

WIP: DDFBRA-251 - User can open their loaned e materials
kasperbirch1 added a commit that referenced this pull request Jan 7, 2025
…logged-in-user-can-open-their-loaned-e-material

WIP: DDFBRA-251 - User can open their loaned e materials
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant