diff --git a/src/components/BookDetail/BookDetail.tsx b/src/components/BookDetail/BookDetail.tsx index f9fe47c4..dbebf0e2 100644 --- a/src/components/BookDetail/BookDetail.tsx +++ b/src/components/BookDetail/BookDetail.tsx @@ -42,6 +42,7 @@ import { import { Helmet } from "react-helmet"; import { DownloadToBloomDialogs } from "./DownloadToBloomButton"; import { BookOwnerControlsBox } from "./BookOwnerControlsBox"; +import { StaffControlsBox } from "./StaffControlsBox"; const BookDetail: React.FunctionComponent = (props) => { const l10n = useIntl(); @@ -324,6 +325,7 @@ const BookDetailInternal: React.FunctionComponent<{ showDownloadDialog={showDownloadDialog} /> )} + diff --git a/src/components/BookDetail/BookExtraPanels.tsx b/src/components/BookDetail/BookExtraPanels.tsx index e0a6087f..88e1c1c9 100644 --- a/src/components/BookDetail/BookExtraPanels.tsx +++ b/src/components/BookDetail/BookExtraPanels.tsx @@ -16,26 +16,15 @@ import ExpandMoreIcon from "@material-ui/icons/ExpandMore"; import { HarvesterArtifactUserControl } from "./ArtifactVisibilityPanel/ArtifactVisibilityPanel"; import { LoggedInUser } from "../../connection/LoggedInUser"; import { commonUI } from "../../theme"; + +// This used to have three panels, but two got moved to StaffControlsBox.tsx. +// Rather than refactor this back out, I'm taking the simple route of just +// leaving the remainder as is. Who knows if we'll add another panel here someday. export const BookExtraPanels: React.FunctionComponent<{ book: Book; }> = observer((props) => { const user = LoggedInUser.current; const userIsUploader = user?.username === props.book.uploader?.username; - - // causes webpack to create a chunk for this which we only download as needed. - const ReactJsonView = React.lazy(() => - user?.moderator - ? import( - /* webpackChunkName: "react-json-view" */ "react-json-view" - ) - : new Promise(() => {}) - ); - - const StaffPanel = React.lazy(() => - user?.moderator - ? import(/* webpackChunkName: "staffPanel" */ "../Admin/StaffPanel") - : new Promise(() => {}) - ); return (
)} - - {user?.moderator && ( - - }> - Staff Controls - - - - Loading chunk for showing staff panel... -
- } - > - - - - - )} - {user?.moderator && ( - - }> - Raw Book Data (Staff Only) - - -
- Loading chunk for showing json...
- } - > - - - {/* {JSON.stringify(props.book)} */} - -
-
- )} ); }); diff --git a/src/components/BookDetail/BookOwnerControlsBox.tsx b/src/components/BookDetail/BookOwnerControlsBox.tsx index 76e29799..e7c6047a 100644 --- a/src/components/BookDetail/BookOwnerControlsBox.tsx +++ b/src/components/BookDetail/BookOwnerControlsBox.tsx @@ -25,6 +25,7 @@ import { useGetPermissions, } from "../../connection/LibraryQueryHooks"; import { OSFeaturesContext } from "../OSFeaturesContext"; +import { ControlsBox } from "./ControlsBox"; export const BookOwnerControlsBox: React.FunctionComponent<{ book: Book; @@ -77,16 +78,7 @@ export const BookOwnerControlsBox: React.FunctionComponent<{ const showDeleteButton = userIsModerator || permissions.delete === true; return ( -
+
)} -
+
); }); diff --git a/src/components/BookDetail/ControlsBox.tsx b/src/components/BookDetail/ControlsBox.tsx new file mode 100644 index 00000000..80ffcc48 --- /dev/null +++ b/src/components/BookDetail/ControlsBox.tsx @@ -0,0 +1,29 @@ +// this engages a babel macro that does cool emotion stuff (like source maps). See https://emotion.sh/docs/babel-macros +import css from "@emotion/css/macro"; +// these two lines make the css prop work on react elements +import { jsx } from "@emotion/core"; +/** @jsx jsx */ + +import React from "react"; + +import { commonUI } from "../../theme"; + +// This is just a reusable box with a border around it. +export const ControlsBox: React.FunctionComponent< + React.HTMLProps +> = (props) => { + return ( +
+ {props.children} +
+ ); +}; diff --git a/src/components/BookDetail/StaffControlsBox.tsx b/src/components/BookDetail/StaffControlsBox.tsx new file mode 100644 index 00000000..5bf1944b --- /dev/null +++ b/src/components/BookDetail/StaffControlsBox.tsx @@ -0,0 +1,100 @@ +// this engages a babel macro that does cool emotion stuff (like source maps). See https://emotion.sh/docs/babel-macros +import css from "@emotion/css/macro"; +// these two lines make the css prop work on react elements +import { jsx } from "@emotion/core"; +/** @jsx jsx */ + +import React, { Fragment } from "react"; +import { observer } from "mobx-react-lite"; +import { + ExpansionPanel, + ExpansionPanelSummary, + ExpansionPanelDetails, +} from "@material-ui/core"; + +import { Book } from "../../model/Book"; +import { useGetUserIsModerator } from "../../connection/LoggedInUser"; +import ExpandMoreIcon from "@material-ui/icons/ExpandMore"; +import { commonUI } from "../../theme"; +import { ControlsBox } from "./ControlsBox"; + +export const StaffControlsBox: React.FunctionComponent<{ + book: Book; +}> = observer((props) => { + const userIsModerator = useGetUserIsModerator(); + const showControlsBox = userIsModerator; + + if (!showControlsBox) return ; + + // causes webpack to create a chunk for this which we only download as needed. + const StaffPanel = React.lazy( + () => import(/* webpackChunkName: "staffPanel" */ "../Admin/StaffPanel") + ); + const ReactJsonView = React.lazy( + () => + import(/* webpackChunkName: "react-json-view" */ "react-json-view") + ); + + return ( + +

+ You have staff permission on this book +

+ + }> + Staff Controls + + + Loading chunk for showing staff panel...
+ } + > + + + + + + }> + Raw Book Data + + +
+ Loading chunk for showing json...
+ } + > + + + +
+
+ + ); +});