diff --git a/src/components/AppLayout/AppActionContext.tsx b/src/components/AppLayout/AppActionContext.tsx index 6083d883b..ad7e71990 100644 --- a/src/components/AppLayout/AppActionContext.tsx +++ b/src/components/AppLayout/AppActionContext.tsx @@ -1,7 +1,15 @@ import React from "react"; -const AppActionContext = React.createContext>( - undefined -); +interface AppAction { + anchor: React.RefObject; + docked: boolean; + setDocked: (docked: boolean) => void; +} +const AppActionContext = React.createContext({ + anchor: undefined, + docked: true, + setDocked: () => undefined +}); +export const useAppAction = () => React.useContext(AppActionContext); export default AppActionContext; diff --git a/src/components/AppLayout/AppLayout.tsx b/src/components/AppLayout/AppLayout.tsx index 128c20a95..c5fdf190d 100644 --- a/src/components/AppLayout/AppLayout.tsx +++ b/src/components/AppLayout/AppLayout.tsx @@ -50,6 +50,9 @@ const useStyles = makeStyles( position: "sticky", zIndex: 10 }, + appActionDocked: { + position: "static" + }, appLoader: { height: appLoaderHeight, marginBottom: theme.spacing(2), @@ -313,6 +316,7 @@ const AppLayout: React.FC = ({ children }) => { const [appState, dispatchAppState] = useAppState(); const { location } = useRouter(); const [isNavigatorVisible, setNavigatorVisibility] = React.useState(false); + const [docked, setDocked] = React.useState(true); const menuStructure = createMenuStructure(intl); const configurationMenu = createConfigurationMenu(intl); @@ -365,7 +369,13 @@ const AppLayout: React.FC = ({ children }) => { setVisibility={setNavigatorVisibility} /> - +
= ({ children }) => { : children}
-
+
diff --git a/src/components/SaveButtonBar/SaveButtonBar.tsx b/src/components/SaveButtonBar/SaveButtonBar.tsx index d741cae2f..61c37c94b 100644 --- a/src/components/SaveButtonBar/SaveButtonBar.tsx +++ b/src/components/SaveButtonBar/SaveButtonBar.tsx @@ -9,7 +9,7 @@ import React from "react"; import { useIntl } from "react-intl"; import { maybe } from "../../misc"; -import AppActionContext from "../AppLayout/AppActionContext"; +import AppActionContext, { useAppAction } from "../AppLayout/AppActionContext"; import ConfirmButton, { ConfirmButtonTransitionState } from "../ConfirmButton/ConfirmButton"; @@ -41,8 +41,12 @@ const useStyles = makeStyles( backgroundColor: theme.palette.error.main, color: theme.palette.error.contrastText }, + paper: { + borderBottomLeftRadius: 0, + borderBottomRightRadius: 0 + }, root: { - height: 120 + height: 70 }, spacer: { flex: "1" @@ -76,67 +80,69 @@ export const SaveButtonBar: React.FC = props => { } = props; const classes = useStyles(props); + const appAction = useAppAction(); const intl = useIntl(); const scrollPosition = useWindowScroll(); + + React.useEffect(() => { + appAction.setDocked(disabled); + + return () => appAction.setDocked(true); + }, [disabled]); + const scrolledToBottom = scrollPosition.y + window.innerHeight >= document.body.scrollHeight; - const shouldDisplay = onDelete || !disabled; - return ( - - {anchor => - anchor ? ( - - {shouldDisplay && ( -
- - - - {!!onDelete && ( - - )} -
- - - {maybe( - () => labels.save, - intl.formatMessage(buttonMessages.save) - )} - - - - -
- )} - - ) : null - } - - ); + return appAction.anchor ? ( + +
+ + + + {!!onDelete && ( + + )} +
+ + + {maybe( + () => labels.save, + intl.formatMessage(buttonMessages.save) + )} + + + + +
+ + ) : null; }; SaveButtonBar.displayName = "SaveButtonBar"; export default SaveButtonBar;