From 3816ebb0a56aca9c481fa14fe33d1bbb0da0e3cf Mon Sep 17 00:00:00 2001 From: dominik-zeglen Date: Sat, 8 Aug 2020 14:59:09 +0200 Subject: [PATCH] Add navigator button --- src/components/AppLayout/AppLayout.tsx | 319 +++++++++++++------------ src/components/Navigator/Navigator.tsx | 14 +- src/index.tsx | 2 - 3 files changed, 175 insertions(+), 160 deletions(-) diff --git a/src/components/AppLayout/AppLayout.tsx b/src/components/AppLayout/AppLayout.tsx index d521bb9b1..a701ec067 100644 --- a/src/components/AppLayout/AppLayout.tsx +++ b/src/components/AppLayout/AppLayout.tsx @@ -28,6 +28,7 @@ import useRouter from "use-react-router"; import Container from "../Container"; import ErrorPage from "../ErrorPage"; +import Navigator from "../Navigator"; import AppActionContext from "./AppActionContext"; import AppHeaderContext from "./AppHeaderContext"; import { appLoaderHeight, drawerWidth, drawerWidthExpanded } from "./consts"; @@ -310,6 +311,7 @@ const AppLayout: React.FC = ({ children }) => { const intl = useIntl(); const [appState, dispatchAppState] = useAppState(); const { location } = useRouter(); + const [isNavigatorVisible, setNavigatorVisibility] = React.useState(false); const menuStructure = createMenuStructure(intl); const configurationMenu = createConfigurationMenu(intl); @@ -356,170 +358,181 @@ const AppLayout: React.FC = ({ children }) => { }; return ( - - -
-
- setDrawerState(false)} - open={isDrawerOpened} - small={!isMenuSmall} - > -
+ + + +
+
+ setDrawerState(false)} + open={isDrawerOpened} + small={!isMenuSmall} > - -
-
- +
-
- - -
-
- {appState.loading ? ( - - ) : ( -
- )} -
-
- -
-
setDrawerState(!isDrawerOpened)} - > - - - - -
-
-
-
- -
- - ) - } - classes={{ - avatar: classes.avatar - }} - className={classes.userChip} - label={ - <> - {user.email} - - - } - onClick={() => setMenuState(!isMenuOpened)} - data-test="userMenu" + +
+ +
+
+ + +
+
+ {appState.loading ? ( + + ) : ( +
+ )} +
+
+ +
+
setDrawerState(!isDrawerOpened)} + > + + + + +
+
+
+
+ - - {({ TransitionProps, placement }) => ( - - - setMenuState(false)} - mouseEvent="onClick" - > - - - - - - - - - - - - )} - + +
+ + ) + } + classes={{ + avatar: classes.avatar + }} + className={classes.userChip} + label={ + <> + {user.email} + + + } + onClick={() => setMenuState(!isMenuOpened)} + data-test="userMenu" + /> + + {({ TransitionProps, placement }) => ( + + + setMenuState(false)} + mouseEvent="onClick" + > + + + + + + + + + + + + )} + +
-
- + +
+
+ {appState.error + ? appState.error === "unhandled" && ( + + ) + : children} +
-
- {appState.error - ? appState.error === "unhandled" && ( - - ) - : children} -
+
-
-
- - + + + ); }; diff --git a/src/components/Navigator/Navigator.tsx b/src/components/Navigator/Navigator.tsx index 07fc647b8..569eede26 100644 --- a/src/components/Navigator/Navigator.tsx +++ b/src/components/Navigator/Navigator.tsx @@ -60,8 +60,12 @@ const useStyles = makeStyles( } ); -const Navigator: React.FC = () => { - const [visible, setVisible] = React.useState(false); +export interface NavigatorProps { + visible: boolean; + setVisibility: (state: boolean) => void; +} + +const Navigator: React.FC = ({ visible, setVisibility }) => { const input = React.useRef(null); const [query, mode, change, actions] = useQuickSearch(visible, input); const intl = useIntl(); @@ -76,7 +80,7 @@ const Navigator: React.FC = () => { React.useEffect(() => { hotkeys(navigatorHotkey, event => { event.preventDefault(); - setVisible(!visible); + setVisibility(!visible); }); if (cmp(APP_VERSION, "2.1.0") !== 1 && !notifiedAboutNavigator) { @@ -110,7 +114,7 @@ const Navigator: React.FC = () => { setVisible(false)} + onClose={() => setVisibility(false)} >
@@ -122,7 +126,7 @@ const Navigator: React.FC = () => { onSelect={(item: QuickSearchAction) => { const shouldRemainVisible = item.onClick(); if (!shouldRemainVisible) { - setVisible(false); + setVisibility(false); } }} onInputValueChange={value => diff --git a/src/index.tsx b/src/index.tsx index f684c326c..9317abeea 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -1,4 +1,3 @@ -import Navigator from "@saleor/components/Navigator"; import useAppState from "@saleor/hooks/useAppState"; import { defaultDataIdFromObject, InMemoryCache } from "apollo-cache-inmemory"; import { ApolloClient } from "apollo-client"; @@ -139,7 +138,6 @@ const Routes: React.FC = () => { {isAuthenticated && !tokenAuthLoading && !tokenVerifyLoading ? ( - dispatchAppState({