From 4ee533eec0308ae827702cd47fc7b7134f7649d7 Mon Sep 17 00:00:00 2001 From: Justinas <156369263+justinnas@users.noreply.github.com> Date: Mon, 2 Sep 2024 14:46:56 +0300 Subject: [PATCH] Moved BaseLayout into routes, made sidebar icons highlighted depending on the page --- app/front-end/src/app/provider.tsx | 5 +- app/front-end/src/app/router.tsx | 17 ++++- .../components/buttons/IconTitleButton.tsx | 16 ++++- .../src/components/layouts/baseLayout.tsx | 5 +- .../src/components/sidebar/sidebar.tsx | 71 +++++++++++-------- app/front-end/src/types/constants/paths.ts | 9 +-- 6 files changed, 76 insertions(+), 47 deletions(-) diff --git a/app/front-end/src/app/provider.tsx b/app/front-end/src/app/provider.tsx index 928db5d..31c7e84 100644 --- a/app/front-end/src/app/provider.tsx +++ b/app/front-end/src/app/provider.tsx @@ -1,4 +1,3 @@ -import { BaseLayout } from '@/components/layouts/baseLayout'; import { SessionContextProvider, ThemeContextProvider } from '@/stores'; import { CircularProgress } from '@mui/material'; import React from 'react'; @@ -41,9 +40,7 @@ export const AppProvider = ({ children }: AppProviderProps) => { fallback={} > - - {children} - + {children} ); diff --git a/app/front-end/src/app/router.tsx b/app/front-end/src/app/router.tsx index 039123f..e8ba1a6 100644 --- a/app/front-end/src/app/router.tsx +++ b/app/front-end/src/app/router.tsx @@ -1,3 +1,4 @@ +import { BaseLayout } from '@/components/layouts/baseLayout'; import { Paths } from '@/types'; import { useMemo } from 'react'; import { createBrowserRouter, RouterProvider } from 'react-router-dom'; @@ -32,14 +33,26 @@ export const AppRouter = () => { path: Paths.HOME, lazy: async () => { const { Home } = await import('./routes/home'); - return { Component: Home }; + return { + Component: (props) => ( + + + + ), + }; }, }, { path: Paths.NOTFOUND, lazy: async () => { const { NotFound } = await import('./routes/notFound'); - return { Component: NotFound }; + return { + Component: (props) => ( + + + + ), + }; }, }, ]), diff --git a/app/front-end/src/components/buttons/IconTitleButton.tsx b/app/front-end/src/components/buttons/IconTitleButton.tsx index 4f9d877..be38de8 100644 --- a/app/front-end/src/components/buttons/IconTitleButton.tsx +++ b/app/front-end/src/components/buttons/IconTitleButton.tsx @@ -8,6 +8,7 @@ interface Props { height?: string; borderRadius?: string; onClick?: () => void; + isActive?: boolean; } /** @@ -29,7 +30,15 @@ interface Props { * * @returns {JSX.Element} The `IconTitleButton` component rendering an icon button and an optional title. */ -export const IconTitleButton: React.FC = ({ icon, title, width, height, borderRadius, onClick }) => { +export const IconTitleButton: React.FC = ({ + icon, + title, + width, + height, + borderRadius, + onClick, + isActive = false, +}) => { const Theme = useTheme(); return ( @@ -41,8 +50,11 @@ export const IconTitleButton: React.FC = ({ icon, title, width, height, b borderRadius: borderRadius || '1rem', transition: 'background-color 0.5s ease', ':hover': { - backgroundColor: alpha(Theme.palette.primary.contrastText, 0.2), + backgroundColor: isActive + ? alpha(Theme.palette.primary.contrastText, 0.3) + : alpha(Theme.palette.primary.contrastText, 0.2), }, + backgroundColor: isActive ? alpha(Theme.palette.primary.contrastText, 0.3) : 'transparent', }} onClick={onClick} > diff --git a/app/front-end/src/components/layouts/baseLayout.tsx b/app/front-end/src/components/layouts/baseLayout.tsx index 38dc358..82c0185 100644 --- a/app/front-end/src/components/layouts/baseLayout.tsx +++ b/app/front-end/src/components/layouts/baseLayout.tsx @@ -109,10 +109,7 @@ export const BaseLayout: React.FC = ({ children }) => { flexDirection: 'row', }} > - + void; - handleShortcutsDialogOpen: () => void; + settingsDialogOpen: () => void; + shortcutsDialogOpen: () => void; } -export const Sidebar: React.FC = ({ handleSettingsDialogOpen, handleShortcutsDialogOpen }) => { +export const Sidebar: React.FC = ({ settingsDialogOpen, shortcutsDialogOpen }) => { + const location = useLocation(); + return ( - + = ({ handleSettingsDialogOpen, hand alignItems: 'center', }} > - - } - title={'Home'} - /> - - } - title={'Macros'} - /> + + + } + title={'Home'} + isActive={location.pathname === Paths.HOME} + /> + + + + } + title={'Macros'} + isActive={location.pathname === Paths.MACROS} + /> + = ({ handleSettingsDialogOpen, hand icon={ } - onClick={handleSettingsDialogOpen} + onClick={settingsDialogOpen} /> = ({ handleSettingsDialogOpen, hand sx={{ width: '1.5rem', height: '1.5rem', color: Colors.backgroundPrimaryLight }} /> } - onClick={handleShortcutsDialogOpen} + onClick={shortcutsDialogOpen} /> diff --git a/app/front-end/src/types/constants/paths.ts b/app/front-end/src/types/constants/paths.ts index 920578e..04bfbf8 100644 --- a/app/front-end/src/types/constants/paths.ts +++ b/app/front-end/src/types/constants/paths.ts @@ -16,12 +16,13 @@ * @example * // Example usage of Paths * import { Paths } from './path/to/paths'; - * + * * // Configure routing * * */ export const Paths = { - HOME: '/', - NOTFOUND: '*', -}; \ No newline at end of file + HOME: '/', + MACROS: '/macros', + NOTFOUND: '*', +};