From 51a1783f975abc2b61e360345865b8df93c340fc Mon Sep 17 00:00:00 2001 From: Robin van Zanten Date: Thu, 22 Jul 2021 17:26:30 +0200 Subject: [PATCH] feat(menu): add usermenu to sidebar --- src/components/Layout/Layout.module.scss | 11 +++++++ src/components/Layout/Layout.tsx | 30 +++++++++++++++++++ .../Layout/__snapshots__/Layout.test.tsx.snap | 29 +++++++++++++++++- 3 files changed, 69 insertions(+), 1 deletion(-) diff --git a/src/components/Layout/Layout.module.scss b/src/components/Layout/Layout.module.scss index ad5503883..fdb0c3b16 100644 --- a/src/components/Layout/Layout.module.scss +++ b/src/components/Layout/Layout.module.scss @@ -32,3 +32,14 @@ border-top: 1px solid rgba(variables.$white, 0.12); opacity: 0.12; } + +.buttonContainer { + display: flex; + flex-direction: column; + padding: 0 variables.$base-spacing; + + > button:first-child { + margin-bottom: variables.$base-spacing / 2; + color: var(--primary-color); + } +} diff --git a/src/components/Layout/Layout.tsx b/src/components/Layout/Layout.tsx index d1b9cac0f..f0d3826eb 100644 --- a/src/components/Layout/Layout.tsx +++ b/src/components/Layout/Layout.tsx @@ -3,6 +3,7 @@ import { Helmet } from 'react-helmet'; import { useTranslation } from 'react-i18next'; import { useHistory } from 'react-router'; +import { AccountStore } from '../../stores/AccountStore'; import useSearchQueryUpdater from '../../hooks/useSearchQueryUpdater'; import { UIStore } from '../../stores/UIStore'; import Button from '../Button/Button'; @@ -13,6 +14,7 @@ import DynamicBlur from '../DynamicBlur/DynamicBlur'; import { ConfigContext } from '../../providers/ConfigProvider'; import MenuButton from '../../components/MenuButton/MenuButton'; import { addQueryParam } from '../../utils/history'; +import UserMenu from '../UserMenu/UserMenu'; import styles from './Layout.module.scss'; @@ -27,7 +29,9 @@ const Layout: FC = ({ children }) => { const blurImage = UIStore.useState((s) => s.blurImage); const searchQuery = UIStore.useState((s) => s.searchQuery); const searchActive = UIStore.useState((s) => s.searchActive); + const userMenuOpen = UIStore.useState((s) => s.userMenuOpen); const { updateSearchQuery, resetSearchQuery } = useSearchQueryUpdater(); + const isLoggedIn = !!AccountStore.useState((state) => state.user); const searchInputRef = useRef(null) as React.MutableRefObject; @@ -59,6 +63,28 @@ const Layout: FC = ({ children }) => { history.push(addQueryParam(history, 'u', 'login')); }; + const toggleUserMenu = (value: boolean) => + UIStore.update((state) => { + state.userMenuOpen = value; + }); + + const userActions = isLoggedIn ? ( + + ) : ( +
+
+ ); + return (
@@ -85,6 +111,9 @@ const Layout: FC = ({ children }) => { onSearchButtonClick={searchButtonClickHandler} onCloseSearchButtonClick={closeSearchButtonClickHandler} onLoginButtonClick={loginButtonClickHandler} + isLoggedIn={isLoggedIn} + userMenuOpen={userMenuOpen} + toggleUserMenu={toggleUserMenu} >
diff --git a/src/components/Layout/__snapshots__/Layout.test.tsx.snap b/src/components/Layout/__snapshots__/Layout.test.tsx.snap index 1398a8cba..d45df96d6 100644 --- a/src/components/Layout/__snapshots__/Layout.test.tsx.snap +++ b/src/components/Layout/__snapshots__/Layout.test.tsx.snap @@ -49,7 +49,9 @@ exports[` renders layout 1`] = `