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 all 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
2 changes: 2 additions & 0 deletions frontend/src/bundles/common/components/components.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export { Overlay } from './overlay/overlay.js';
export { Player } from './player/player.js';
export { RouterProvider } from './router-provider/router-provider.js';
export { Select } from './select/select.js';
export { Sidebar } from './sidebar/sidebar.js';
export { Textarea } from './textarea/textarea.js';
export { VideoModal } from './video-modal/video-modal.js';
export {
Expand All @@ -27,6 +28,7 @@ export {
InputGroup,
InputRightElement,
SimpleGrid,
Spacer,
Text,
VStack,
} from '@chakra-ui/react';
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { SidebarItem } from './sidebar-item/sidebar-item.js';
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 = {
icon: ReactElement;
isCollapsed: boolean;
label: string;
bg?: string;
color?: string;
onClick?: () => void;
};

const SidebarItem = ({
icon,
isCollapsed,
label,
bg = 'none',
color = 'white',
onClick = (): void => {},
}: Properties): JSX.Element => {
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={onClick}
>
{icon}
{isCollapsed ? '' : label}
</Box>
);
};

export { SidebarItem };
132 changes: 132 additions & 0 deletions frontend/src/bundles/common/components/sidebar/sidebar.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
import {
Box,
Flex,
Icon,
IconButton,
Link,
Spacer,
} from '~/bundles/common/components/components.js';
import { AppRoute } from '~/bundles/common/enums/enums.js';
import {
useCallback,
useLocation,
useNavigate,
useState,
} from '~/bundles/common/hooks/hooks.js';
import { IconName } from '~/bundles/common/icons/icons.js';
import { type ValueOf } from '~/bundles/common/types/types.js';
import { UserAvatar, UserCard } from '~/bundles/users/components/components.js';

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

type Properties = {
children: React.ReactNode;
};

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

const handleToggle = useCallback(
(): void => setIsCollapsed(!isCollapsed),
[isCollapsed],
);

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

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

const handleLogOut = useCallback(() => {
//ToDo: log out user with token
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

create ticket for it

navigate(AppRoute.SIGN_IN);
}, [navigate]);

return (
<Flex w="100%">
<Flex
w={isCollapsed ? '60px' : '270px'}
bg="background.900"
height="calc(100vh - 75px)"
position="fixed"
flexDirection="column"
justifyContent="space-between"
p="10px"
pb="20px"
>
<IconButton
aria-label={isCollapsed ? 'expand' : 'collapse'}
icon={
<Icon
as={
isCollapsed
? IconName.ARROW_RIGHT
: IconName.ARROW_LEFT
}
/>
}
onClick={handleToggle}
justifyContent={isCollapsed ? 'center' : 'flex-end'}
variant="icon"
/>
<Box mb="30px">
{/* ToDo: Add this username value dynamically */}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

create ticket for it

{isCollapsed ? <UserAvatar username="FN" /> : <UserCard />}
</Box>
<Box>
<Link to={AppRoute.ROOT}>
<SidebarItem
bg={activeButtonPage(AppRoute.ROOT)}
icon={
<Icon
as={IconName.HOME}
boxSize={5}
color={activeIconPage(AppRoute.ROOT)}
/>
}
isCollapsed={isCollapsed}
label="Home"
/>
</Link>
<Link to={AppRoute.MY_AVATAR}>
<SidebarItem
bg={activeButtonPage(AppRoute.MY_AVATAR)}
icon={
<Icon
as={IconName.AVATAR}
boxSize={5}
color={activeIconPage(AppRoute.MY_AVATAR)}
/>
}
isCollapsed={isCollapsed}
label="My Avatar"
/>
</Link>
</Box>
<Spacer />
<SidebarItem
color="brand.secondary.600"
icon={
<Icon
as={IconName.LOG_OUT}
boxSize={5}
color="brand.secondary.600"
/>
}
isCollapsed={isCollapsed}
label={'log out'}
onClick={handleLogOut}
/>
</Flex>
<Box flex="1" ml={isCollapsed ? '60px' : '270px'}>
{children}
</Box>
</Flex>
);
};

export { Sidebar };
1 change: 1 addition & 0 deletions frontend/src/bundles/common/enums/app-route.enum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const AppRoute = {
SIGN_IN: '/sign-in',
SIGN_UP: '/sign-up',
STUDIO: '/studio',
MY_AVATAR: '/my-avatar',
ANY: '*',
} as const;

Expand Down
2 changes: 1 addition & 1 deletion frontend/src/bundles/common/hooks/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ export { useAppForm } from './use-app-form/use-app-form.hook.js';
export { useAppSelector } from './use-app-selector/use-app-selector.hook.js';
export { useFormField } from './use-form-field/use-form-field.hook.js';
export { useCallback, useEffect, useMemo, useState } from 'react';
export { useLocation } from 'react-router-dom';
export { useLocation, useNavigate } from 'react-router-dom';
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import {
faCircleUser,
faHouse,
faRightFromBracket,
} from '@fortawesome/free-solid-svg-icons';

import { iconConverter } from './icon-converter.helper.js';

const HouseIcon = iconConverter(faHouse);
const RightFromBracketIcon = iconConverter(faRightFromBracket);
const CircleUserIcon = iconConverter(faCircleUser);

export { CircleUserIcon, HouseIcon, RightFromBracketIcon };
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import {
type ComponentWithAs,
type IconProps,
createIcon,
} from '@chakra-ui/react';
import { type IconDefinition } from '@fortawesome/free-solid-svg-icons';

const iconConverter = (
faIcon: IconDefinition,
): ComponentWithAs<'svg', IconProps> => {
const { icon, iconName } = faIcon;

return createIcon({
displayName: iconName,
viewBox: `0 0 ${icon[0]} ${icon[1]}`,
d: `${icon[4]}`,
});
};

export { iconConverter };
21 changes: 18 additions & 3 deletions frontend/src/bundles/common/icons/icon-name.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import { DownloadIcon, ViewIcon, ViewOffIcon } from '@chakra-ui/icons';
import {
faCircleUser,
ArrowLeftIcon,
ArrowRightIcon,
DownloadIcon,
ViewIcon,
ViewOffIcon,
} from '@chakra-ui/icons';
import {
faCloudArrowUp,
faEllipsisVertical,
faFileLines,
Expand All @@ -12,16 +17,26 @@ import {
faTableColumns,
} from '@fortawesome/free-solid-svg-icons';

import {
CircleUserIcon,
HouseIcon,
RightFromBracketIcon,
} from './helper/icon-conversion.helper.js';

const IconName = {
PEN: faPen,
HOME: HouseIcon,
LOG_OUT: RightFromBracketIcon,
ARROW_LEFT: ArrowLeftIcon,
ARROW_RIGHT: ArrowRightIcon,
FILE_LINES: faFileLines,
PLAY: faPlay,
SCROLL: faScroll,
OPTIONS_VERTICAL: faEllipsisVertical,
DOWNLOAD: DownloadIcon,
VIEW: ViewIcon,
VIEW_OFF: ViewOffIcon,
AVATAR: faCircleUser,
AVATAR: CircleUserIcon,
UPLOAD: faCloudArrowUp,
TEMPLATE: faTableColumns,
SCRIPT: faFont,
Expand Down
24 changes: 24 additions & 0 deletions frontend/src/bundles/my-avatar/components/circles/circles.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { Circle } from '~/bundles/common/components/components.js';

const Circles = (): JSX.Element => {
return (
<Circle
size="271px"
border="solid 1px"
borderColor="background.50"
position="absolute"
left="-71%"
top="-270%"
>
<Circle size="159px" border="solid 1px" borderColor="background.50">
<Circle
size="113px"
border="solid 1px"
borderColor="background.50"
/>
</Circle>
</Circle>
);
};

export { Circles };
3 changes: 3 additions & 0 deletions frontend/src/bundles/my-avatar/components/components.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export { Circles } from './circles/circles.js';
export { CreateAvatar } from './create-avatar/create-avatar.js';
export { Dots } from './dots/dots.js';
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { Box, Button, Flex } from '~/bundles/common/components/components.js';

import { Circles, Dots } from '../components.js';

const CreateAvatar = (): JSX.Element => {
return (
<Flex
bg="white"
h="215px"
borderRadius="lg"
justify="center"
align="center"
overflow="hidden"
>
<Box w="222px" position="relative">
<Circles />
<Dots />
<Button label="Create Avatar" />
</Box>
</Flex>
);
};

export { CreateAvatar };
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
const SIZE = '3px';
const COLOR = 'background.600';

export { COLOR, SIZE };
Loading
Loading