Skip to content

Commit

Permalink
Book download into a new collection for editing (BL-13035) (#535)
Browse files Browse the repository at this point in the history
* Book download into a new collection for editing (BL-13035)

* Disable new behavior until 5.7 ships
  • Loading branch information
JohnThomson authored Feb 6, 2024
1 parent 1d29f95 commit 5a2198b
Show file tree
Hide file tree
Showing 6 changed files with 332 additions and 159 deletions.
17 changes: 13 additions & 4 deletions src/components/BookDetail/ArtifactHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,14 @@ export enum ArtifactType {
bloomSource = "bloomSource",
}

export function getArtifactUrl(book: Book, artifactType: ArtifactType): string {
export function getArtifactUrl(
book: Book,
artifactType: ArtifactType,
// only used for shellbook, true if we want to download for editing.
// In some ways I would prefer to have a separate artifact type for this, but
// we don't want a new entry for that in ArtifactVisibilitySettings.
forEdit?: boolean
): string {
let url;
switch (artifactType) {
case ArtifactType.readOnline:
Expand All @@ -24,7 +31,7 @@ export function getArtifactUrl(book: Book, artifactType: ArtifactType): string {
url = getDownloadUrl(book, "bloompub");
break;
case ArtifactType.shellbook:
url = getBookOrderUrl(book);
url = getBookOrderUrl(book, !!forEdit);
break;
case ArtifactType.pdf:
// We need the raw book name here, because we're going for the PDF
Expand All @@ -42,7 +49,7 @@ export function getArtifactUrl(book: Book, artifactType: ArtifactType): string {
return url;
}

function getBookOrderUrl(book: Book) {
function getBookOrderUrl(book: Book, forEdit: boolean) {
if (!book.baseUrl) return "";

// Generate a bookOrder URL from the baseUrl. We used to create and store the bookOrder as a field
Expand Down Expand Up @@ -74,7 +81,9 @@ function getBookOrderUrl(book: Book) {

return `bloom://localhost/order?orderFile=${
match[1]
}&title=${encodeURIComponent(book.title)}&minVersion=${minVersion}`;
}&title=${encodeURIComponent(book.title)}&minVersion=${minVersion}${
forEdit ? "&forEdit=true" : ""
}`;
}

return "";
Expand Down
112 changes: 98 additions & 14 deletions src/components/BookDetail/BookDetail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import css from "@emotion/css/macro";
import { jsx } from "@emotion/core";
/** @jsx jsx */

import React from "react";
import React, { useRef } from "react";
import { useGetBookDetail } from "../../connection/LibraryQueryHooks";
import { Book } from "../../model/Book";

import { Checkbox, Divider, FormControlLabel } from "@material-ui/core";
import { Button, Checkbox, Divider, FormControlLabel } from "@material-ui/core";
import { Alert } from "@material-ui/lab";

import { observer } from "mobx-react-lite";
Expand Down Expand Up @@ -44,6 +44,7 @@ import {
useIsAppHosted,
} from "../appHosted/AppHostedUtils";
import { Helmet } from "react-helmet";
import { DownloadToBloomDialogs } from "./DownloadToBloomButton";

const BookDetail: React.FunctionComponent<IBookDetailProps> = (props) => {
const l10n = useIntl();
Expand Down Expand Up @@ -96,6 +97,13 @@ const BookDetail: React.FunctionComponent<IBookDetailProps> = (props) => {
}
};

// This constant lets us keep active some code we don't want to take effect
// until Bloom 5.7 is shipping. I don't want to comment it out because I want
// it to continue to keep up to date. Also, a single line here can just be changed here to enable it.
// The true/false tricks lint into not complaining about unreachable code.
let bloom57IsShipping = true;
bloom57IsShipping = false;

const BookDetailInternal: React.FunctionComponent<{
book: Book;
contextLangTag?: string;
Expand All @@ -114,13 +122,13 @@ const BookDetailInternal: React.FunctionComponent<{
`}
/>
);

const embeddedMode = useIsEmbedded();
const appHostedMode = useIsAppHosted();
const user = LoggedInUser.current;
const userIsUploader = user?.username === props.book.uploader?.username;
const l10n = useIntl();
const getResponsiveChoice = useResponsiveChoice();
const showDownloadDialog = useRef<() => void | undefined>();
return (
<div
// had width:800px, but that destroys responsiveness
Expand Down Expand Up @@ -371,22 +379,98 @@ const BookDetailInternal: React.FunctionComponent<{
/>
)}
{userIsUploader && (
<Alert
severity="info"
<div
css={css`
margin-top: 20px;
display: flex;
flex-direction: column;
`}
>
<FormattedMessage
id={"book.detail.updateBookNotice"}
defaultMessage={
"If you want to update this book with any changes, just upload it again from Bloom, using the same account. Your new version will replace this one."
}
/>
</Alert>
<h2
css={css`
margin-bottom: 0;
color: ${commonUI.colors.bloomBlue};
`}
id="book.detail.editing"
>
Editing
</h2>
<Alert severity="info">
<div>
<FormattedMessage
id={"book.detail.updateBookNotice"}
defaultMessage={
"If you want to update this book with any changes, just upload it again from Bloom, using the same account. Your new version will replace this one."
}
/>
</div>
{bloom57IsShipping && (
<div
css={css`
margin-top: 10px;
`}
>
<FormattedMessage
id={
"book.detail.getForEditBookNotice"
}
defaultMessage={
"If necessary, we can give you the book to edit in Bloom. You must first have Bloom 5.7 or greater installed ({downloadLink})"
}
values={{
downloadLink: (
<BlorgLink
href="page/create/downloads"
css={css`
color: ${commonUI
.colors
.bloomBlue};
`}
>
<FormattedMessage
id={
"book.detail.downloadBloom"
}
defaultMessage={
"Download Bloom"
}
/>
</BlorgLink>
),
}}
/>
</div>
)}
</Alert>
{bloom57IsShipping && (
<Button
onClick={() =>
showDownloadDialog.current?.()
}
color="secondary"
variant="outlined"
css={css`
align-self: flex-end;
margin-top: 5px;
`}
>
<FormattedMessage
id={"book.detail.editDownload"}
defaultMessage={
"Download into Bloom for editing"
}
/>
</Button>
)}
</div>
)}

<BookExtraPanels book={props.book} />
<DownloadToBloomDialogs
book={props.book}
getShowFunction={(download) =>
(showDownloadDialog.current = download)
}
forEdit={true}
/>
</React.Fragment>
)}
</div>
Expand Down
Loading

0 comments on commit 5a2198b

Please sign in to comment.