diff --git a/frontend/src/bundles/video-editor/components/menu/menu.tsx b/frontend/src/bundles/video-editor/components/menu/menu.tsx index 941ad782b..3619fdb7a 100644 --- a/frontend/src/bundles/video-editor/components/menu/menu.tsx +++ b/frontend/src/bundles/video-editor/components/menu/menu.tsx @@ -1,12 +1,31 @@ import { Box, Flex, VStack } from '~/bundles/common/components/components.js'; +import { isEmptyArray, isNullOrUndefined } from '~/bundles/common/helpers/helpers.js'; +import { useCallback } from '~/bundles/common/hooks/hooks.js'; import { type MenuItem } from '../../types/types.js'; type MenuProperties = { items: MenuItem[]; + activeIndex: number | null; + setActiveIndex: (index: number) => void; }; -const Menu: React.FC = ({ items }) => { +const Menu: React.FC = ({ items, activeIndex, setActiveIndex }) => { + const handleClick = useCallback( + (index: number) => { + return () => { + if (isEmptyArray(items) || index >= items.length) + {return;} + + const item = items[index]; + if(isNullOrUndefined(item)) {return;} + + setActiveIndex(index); + item.onClick(); + }; + }, + [setActiveIndex, items] + ); return ( = ({ items }) => { {items.map((item, index) => ( = ({ items }) => { gap: 1, cursor: 'pointer', borderRadius: '8px', + bg: activeIndex === index ? 'background.600' : 'transparent', _hover: { bg: 'background.600', }, diff --git a/frontend/src/bundles/video-editor/pages/video-editor.tsx b/frontend/src/bundles/video-editor/pages/video-editor.tsx index 51eef8a05..3ab55053e 100644 --- a/frontend/src/bundles/video-editor/pages/video-editor.tsx +++ b/frontend/src/bundles/video-editor/pages/video-editor.tsx @@ -1,6 +1,5 @@ -import { useCallback, useState } from 'react'; - import { AssetsIcon, AvatarIcon, ScriptIcon, TemplatesIcon, TextIcon } from '~/bundles/common/components/icons/icons.js'; +import { useCallback, useState } from '~/bundles/common/hooks/hooks.js'; import { Menu, MenuBody } from '../components/components.js'; import { @@ -14,6 +13,7 @@ import { import { type MenuItem } from '../types/menu-item.type.js'; const VideoEditor: React.FC = () => { + const [activeIndex, setActiveIndex] = useState(null); const [activeContent, setActiveContent] = useState( null, ); @@ -26,8 +26,9 @@ const VideoEditor: React.FC = () => { setIsOpen(true); }; - const handleClose = useCallback((): void => { + const resetActiveItem = useCallback((): void => { setIsOpen(false); + setActiveIndex(null); }, []); const menuItems: MenuItem[] = [ @@ -60,8 +61,8 @@ const VideoEditor: React.FC = () => { return ( <> - - + + {activeContent}