Skip to content

Commit

Permalink
Show give dialog when downloading PDF from new Subjects
Browse files Browse the repository at this point in the history
  • Loading branch information
RoyEJohnson committed Oct 6, 2023
1 parent d462a6f commit 08591fc
Showing 1 changed file with 29 additions and 7 deletions.
36 changes: 29 additions & 7 deletions src/app/components/book-tile/book-tile.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import { FormattedMessage, useIntl } from 'react-intl';
import useAmazonAssociatesLink from '~/pages/details/common/get-this-title-files//amazon-associates-link';
import { usePrintCopyDialog, isRealPrintLink } from '~/pages/details/common/get-this-title-files/options';
import bookPromise from '~/models/book-titles';
import useGiveDialog from '~/pages/details/common/get-this-title-files/give-before-pdf/give-before-pdf';
import {isMobileDisplay} from '~/helpers/device';
import cn from 'classnames';
import './book-tile.scss';

Expand Down Expand Up @@ -85,13 +87,7 @@ function GetTheBookDropdown({ bookInfo }) {
/>
</a>
{
pdfLink &&
<a role="menuitem" href={pdfLink}>
<FormattedMessage
id="getit.pdf.download"
defaultMessage="Download a PDF"
/>
</a>
pdfLink && <PDFLinkWithGiveDialog pdfLink={pdfLink} />
}
<PrintOption bookInfo={bookInfo} />
<hr />
Expand All @@ -115,6 +111,32 @@ function GetTheBookDropdown({ bookInfo }) {
);
}

function PDFLinkWithGiveDialog({pdfLink}) {
const {GiveDialog, open, enabled} = useGiveDialog();

const openGiveDialog = React.useCallback(
(event) => {
if (enabled && !isMobileDisplay()) {
event.preventDefault();
open();
}
},
[enabled, open]
);

return (
<React.Fragment>
<a role="menuitem" href={pdfLink} onClick={openGiveDialog}>
<FormattedMessage
id="getit.pdf.download"
defaultMessage="Download a PDF"
/>
</a>
<GiveDialog link={pdfLink} />
</React.Fragment>
);
}

function useBookInfo(id) {
const [state, setState] = React.useState();

Expand Down

0 comments on commit 08591fc

Please sign in to comment.