Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OV-13: Add-side-bar-component #49

Merged
merged 45 commits into from
Sep 2, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
710594c
OV-13: + create svg icons logic
JKaypa Aug 22, 2024
bd262ca
OV-13: + create side bar component
JKaypa Aug 22, 2024
7057630
OV-13: + export components
JKaypa Aug 22, 2024
ca68a7c
OV-13: + export icon component
JKaypa Aug 22, 2024
423aed2
OV-50: * update user card and extract user circle component
JKaypa Aug 22, 2024
738bec9
OV-50: * update side bar component
JKaypa Aug 22, 2024
79c883d
OV-13: * update code review
JKaypa Aug 22, 2024
037263e
Merge branch 'task/OV-13-add-side-bar-component' into task/OV-50-inte…
JKaypa Aug 22, 2024
55f0c22
OV-62: + create avatar layout component
JKaypa Aug 26, 2024
c6c19ec
OV-62: * update dots component
JKaypa Aug 26, 2024
c7b1a3c
OV-13: - remove icons from components to common directory
JKaypa Aug 26, 2024
b7b4588
Merge branch 'next' of https://github.com/BinaryStudioAcademy/bsa-202…
JKaypa Aug 27, 2024
1f61db8
Merge branch 'next' of https://github.com/BinaryStudioAcademy/bsa-202…
JKaypa Aug 27, 2024
705769b
OV-13: * update folder structure and code as reviewed
JKaypa Aug 27, 2024
b71f4ec
Merge branch 'next' of https://github.com/BinaryStudioAcademy/bsa-202…
JKaypa Aug 27, 2024
0b3eeda
OV-62: * update code base regarding reviews
JKaypa Aug 27, 2024
117974d
Merge branch 'next' of https://github.com/BinaryStudioAcademy/bsa-202…
JKaypa Aug 27, 2024
dac6f0f
OV-13: * change side-bar to sidebar names
JKaypa Aug 28, 2024
31beb61
Merge branch 'next' of https://github.com/BinaryStudioAcademy/bsa-202…
JKaypa Aug 28, 2024
cfea637
OV-62: - remove create avatar from components
JKaypa Aug 28, 2024
3887708
OV-62: + add new text variant
JKaypa Aug 28, 2024
fb2c99b
OV-62: + add my-avatar route
JKaypa Aug 28, 2024
18744f9
OV-62: + create my avatar page
JKaypa Aug 28, 2024
ae474ec
OV-62: + add my avatar page to route system
JKaypa Aug 28, 2024
3337f4e
OV-62: * change name to my avatar
JKaypa Aug 28, 2024
7bdd20b
OV-13: * change sidebar item
JKaypa Aug 28, 2024
5b3fd86
OV-13: - remove size.enum.ts
JKaypa Aug 28, 2024
8465d15
OV-13: * merge next
JKaypa Aug 28, 2024
d69d13f
Merge branch 'task/OV-13-add-side-bar-component' into task/OV-62-crea…
JKaypa Aug 28, 2024
6e81e1b
OV-62: * update sidebar
JKaypa Aug 28, 2024
4c2fded
OV-62: + integrate sidebar to my avatar page
JKaypa Aug 28, 2024
ddf0544
OV-13: * update sidebar
JKaypa Aug 28, 2024
646420f
OV-62: + add my avatar item
JKaypa Aug 28, 2024
2afb10e
OV-62: * adjustemts
JKaypa Aug 29, 2024
f07ed07
OV-13: * remove heigh
JKaypa Aug 29, 2024
774dc40
OV-13: * minor fixes
JKaypa Aug 29, 2024
73a83ae
Merge branch 'next' of https://github.com/BinaryStudioAcademy/bsa-202…
JKaypa Aug 29, 2024
8d2d5ed
OV-62: * merge
JKaypa Aug 29, 2024
14e3bfa
OV-13: + add icon converter and update sidebar icons
JKaypa Aug 30, 2024
cf4ee6b
OV-13: * merging
JKaypa Aug 30, 2024
38b9ce4
OV-13: * update height
JKaypa Aug 30, 2024
d481914
OV-62: * merge
JKaypa Aug 30, 2024
abfb4c0
OV-13: * merge next
JKaypa Sep 2, 2024
dfc31a0
OV-13: * modified component name
JKaypa Sep 2, 2024
cd13620
Merge branch 'task/OV-62-create-avatar-page' into task/OV-13-add-side…
JKaypa Sep 2, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions frontend/src/bundles/common/components/components.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
export { Button } from './button/button.js';
export { Header } from './header/header.js';
export { IconMap } from './icon/icon.js';
export { Input } from './input/input.js';
export { Link } from './link/link.js';
export { Loader } from './loader/loader.js';
export { Overlay } from './overlay/overlay.js';
export { RouterProvider } from './router-provider/router-provider.js';
export { SideBar } from './side-bar/side-bar.js';
export { VideoModal } from './video-modal/video-modal.js';
export { DownloadIcon } from '@chakra-ui/icons';
export { ViewIcon, ViewOffIcon } from '@chakra-ui/icons';
Expand All @@ -17,10 +19,12 @@ export {
FormControl,
FormErrorMessage,
Heading,
Icon,
IconButton,
InputGroup,
InputRightElement,
SimpleGrid,
Spacer,
Text,
VStack,
} from '@chakra-ui/react';
Expand Down
28 changes: 28 additions & 0 deletions frontend/src/bundles/common/components/icon/components/icons.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { type IconProps } from '@chakra-ui/react';
import { type ReactElement } from 'react';

import { Icon } from '../../components.js';

const HomeIcon = (properties: IconProps): ReactElement => {
return (
<Icon viewBox="0 0 16 18" {...properties}>
<path
d="M2 16H5V10H11V16H14V7L8 2.5L2 7V16ZM0 18V6L8 0L16 6V18H9V12H7V18H0Z"
fill="currentColor"
/>
</Icon>
);
};

const LogOutIcon = (properties: IconProps): ReactElement => {
return (
<Icon viewBox="0 0 18 19" {...properties}>
<path
d="M2 18.5C1.45 18.5 0.979167 18.3042 0.5875 17.9125C0.195833 17.5208 0 17.05 0 16.5V2.5C0 1.95 0.195833 1.47917 0.5875 1.0875C0.979167 0.695833 1.45 0.5 2 0.5H8C8.28333 0.5 8.52083 0.595833 8.7125 0.7875C8.90417 0.979167 9 1.21667 9 1.5C9 1.78333 8.90417 2.02083 8.7125 2.2125C8.52083 2.40417 8.28333 2.5 8 2.5H2V16.5H8C8.28333 16.5 8.52083 16.5958 8.7125 16.7875C8.90417 16.9792 9 17.2167 9 17.5C9 17.7833 8.90417 18.0208 8.7125 18.2125C8.52083 18.4042 8.28333 18.5 8 18.5H2ZM14.175 10.5H7C6.71667 10.5 6.47917 10.4042 6.2875 10.2125C6.09583 10.0208 6 9.78333 6 9.5C6 9.21667 6.09583 8.97917 6.2875 8.7875C6.47917 8.59583 6.71667 8.5 7 8.5H14.175L12.3 6.625C12.1167 6.44167 12.025 6.21667 12.025 5.95C12.025 5.68333 12.1167 5.45 12.3 5.25C12.4833 5.05 12.7167 4.94583 13 4.9375C13.2833 4.92917 13.525 5.025 13.725 5.225L17.3 8.8C17.5 9 17.6 9.23333 17.6 9.5C17.6 9.76667 17.5 10 17.3 10.2L13.725 13.775C13.525 13.975 13.2875 14.0708 13.0125 14.0625C12.7375 14.0542 12.5 13.95 12.3 13.75C12.1167 13.55 12.0292 13.3125 12.0375 13.0375C12.0458 12.7625 12.1417 12.5333 12.325 12.35L14.175 10.5Z"
fill="currentColor"
/>
JKaypa marked this conversation as resolved.
Show resolved Hide resolved
</Icon>
);
};

export { HomeIcon, LogOutIcon };
12 changes: 12 additions & 0 deletions frontend/src/bundles/common/components/icon/icon-map.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { ArrowLeftIcon, ArrowRightIcon } from '@chakra-ui/icons';

import { HomeIcon, LogOutIcon } from './components/icons.js';

const IconMap = {
HOME: HomeIcon,
LOG_OUT: LogOutIcon,
ARROW_LEFT: ArrowLeftIcon,
ARROW_RIGHT: ArrowRightIcon,
} as const;

export { IconMap };
2 changes: 2 additions & 0 deletions frontend/src/bundles/common/components/icon/icon.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { IconMap } from './icon-map.js';
export { Size } from './size.enum.js';
5 changes: 5 additions & 0 deletions frontend/src/bundles/common/components/icon/size.enum.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const Size = {
LG: 5,
};
JKaypa marked this conversation as resolved.
Show resolved Hide resolved

export { Size };
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { useLocation } from 'react-router-dom';

import { Link } from '~/bundles/common/components/components.js';
import { type AppRoute } from '~/bundles/common/enums/enums.js';
import { type ValueOf } from '~/bundles/common/types/types.js';

import {
type CollapseButtonProperties,
CollapseButton,
} from './collapse-button.js';

type Properties = Omit<CollapseButtonProperties, 'bg' | 'handleClick'> & {
to: ValueOf<typeof AppRoute>;
};

const CollapseButtonLink = ({
icon,
isCollapsed,
label,
to,
}: Properties): JSX.Element => {
const { pathname } = useLocation();

const activeButtonPage = (page: ValueOf<typeof AppRoute>): string => {
return pathname === page ? 'background.600' : '';
};

return (
<Link to={to}>
<CollapseButton
bg={activeButtonPage(to)}
icon={icon}
isCollapsed={isCollapsed}
label={label}
/>
</Link>
);
};

export { CollapseButtonLink };
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { type ReactElement } from 'react';

import { Box } from '~/bundles/common/components/components.js';

type Properties = {
bg?: string;
color?: string;
handleClick?: () => void;
icon: ReactElement;
isCollapsed: boolean;
label: string;
};

const CollapseButton = ({
bg = 'none',
color = 'white',
handleClick = (): void => {},
icon,
isCollapsed,
label,
}: Properties): JSX.Element => {
JKaypa marked this conversation as resolved.
Show resolved Hide resolved
return (
<Box
as="button"
w="100%"
h="50px"
color={color}
display="flex"
justifyContent={isCollapsed ? 'center' : 'flex-start'}
alignItems="center"
gap="10px"
fontSize="1rem"
fontWeight="bold"
bg={bg}
borderRadius="10px"
p="10px"
onClick={handleClick}
>
{icon}
{isCollapsed ? '' : label}
</Box>
);
};

export { type Properties as CollapseButtonProperties, CollapseButton };
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { CollapseButton } from './collapse-button.js';
export { CollapseButtonLink } from './collapse-button-link.js';
102 changes: 102 additions & 0 deletions frontend/src/bundles/common/components/side-bar/side-bar.tsx
JKaypa marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
import { useCallback, useState } from 'react';
o-nedashkivska marked this conversation as resolved.
Show resolved Hide resolved
import { useLocation, useNavigate } from 'react-router-dom';
JKaypa marked this conversation as resolved.
Show resolved Hide resolved

import {
Box,
Flex,
Icon,
IconButton,
IconMap,
Spacer,
} from '~/bundles/common/components/components.js';
import { AppRoute } from '~/bundles/common/enums/enums.js';
import { type ValueOf } from '~/bundles/common/types/types.js';

import { Size } from '../icon/icon.js';
import {
CollapseButton,
CollapseButtonLink,
} from './libs/components/components.js';

const SideBar = (): JSX.Element => {
const [isCollapsed, setIsCollapsed] = useState(false);
const { pathname } = useLocation();
const navigate = useNavigate();

const toggle = useCallback(
JKaypa marked this conversation as resolved.
Show resolved Hide resolved
(): void => setIsCollapsed(!isCollapsed),
[isCollapsed],
);

const activeIconPage = (page: ValueOf<typeof AppRoute>): string => {
return pathname === page ? 'white' : 'background.600';
};

const logOut = useCallback(() => {
JKaypa marked this conversation as resolved.
Show resolved Hide resolved
//ToDo: log out user with token
navigate(AppRoute.SIGN_IN);
}, [navigate]);

return (
<Flex
w={isCollapsed ? '60px' : '260px'}
bg="background.900"
height="100vh"
position="fixed"
flexDirection="column"
justifyContent="space-between"
p="10px"
pb="20px"
>
<IconButton
bg="none"
aria-label={isCollapsed ? 'expand' : 'collapse'}
icon={
isCollapsed ? (
<Icon as={IconMap.ARROW_RIGHT} />
) : (
<Icon as={IconMap.ARROW_LEFT} />
)
}
JKaypa marked this conversation as resolved.
Show resolved Hide resolved
mb="10px"
onClick={toggle}
_active={{ bg: 'none' }}
_hover={{ bg: 'none' }}
justifyContent={isCollapsed ? 'center' : 'flex-end'}
/>
o-nedashkivska marked this conversation as resolved.
Show resolved Hide resolved

<Box>
<CollapseButtonLink
icon={
<Icon
as={IconMap.HOME}
boxSize={Size.LG}
color={activeIconPage('/')}
/>
}
label="Home"
to="/"
JKaypa marked this conversation as resolved.
Show resolved Hide resolved
isCollapsed={isCollapsed}
/>
</Box>

<Spacer />

<CollapseButton
color="brand.secondary.600"
icon={
<Icon
as={IconMap.LOG_OUT}
boxSize={Size.LG}
color="brand.secondary.600"
/>
}
isCollapsed={isCollapsed}
label={'log out'}
handleClick={logOut}
/>
</Flex>
);
};

export { SideBar };
Loading