import { Add, Star } from '@mui/icons-material'; import { Button, Divider, IconButton, SwipeableDrawer, Tooltip, useMediaQuery, useTheme } from '@mui/material'; import { Section as SectionRecord } from '@reactive-resume/schema'; import cloneDeep from 'lodash/cloneDeep'; import get from 'lodash/get'; import Link from 'next/link'; import { useTranslation } from 'next-i18next'; import React, { ReactComponentElement, useMemo } from 'react'; import { validate } from 'uuid'; import Logo from '@/components/shared/Logo'; import { getCustomSections, getSectionsByType, left } from '@/config/sections'; import { setSidebarState } from '@/store/build/buildSlice'; import { useAppDispatch, useAppSelector } from '@/store/hooks'; import { addSection } from '@/store/resume/resumeSlice'; import styles from './LeftSidebar.module.scss'; import Section from './sections/Section'; const LeftSidebar = () => { const theme = useTheme(); const { t } = useTranslation(); const dispatch = useAppDispatch(); const isDesktop = useMediaQuery(theme.breakpoints.up('lg')); const sections = useAppSelector((state) => state.resume.present.sections); const { open } = useAppSelector((state) => state.build.sidebar.left); const customSections = useMemo(() => getCustomSections(sections), [sections]); const handleOpen = () => dispatch(setSidebarState({ sidebar: 'left', state: { open: true } })); const handleClose = () => dispatch(setSidebarState({ sidebar: 'left', state: { open: false } })); const handleClick = (id: string) => { const elementId = validate(id) ? `#section-${id}` : `#${id}`; const section = document.querySelector(elementId); if (section) { section.scrollIntoView({ behavior: 'smooth', block: 'start' }); } }; const handleAddSection = () => { const newSection: SectionRecord = { name: 'Custom Section', type: 'custom', visible: true, columns: 2, items: [], }; dispatch(addSection({ value: newSection, type: 'custom' })); }; const sectionsList = () => { const sectionsComponents: Array> = []; for (const item of left) { const id = (item as any).id; const component = (item as any).component; const type = component.props.type || 'basic'; const addMore = !!component.props.addMore; sectionsComponents.push(
{component}
); if (addMore) { const additionalSections = getSectionsByType(sections, type); const elements = []; for (const element of additionalSections) { const newId = element.id; const props = cloneDeep(component.props); props.path = 'sections.' + newId; props.name = element.name; props.isDeletable = true; props.addMore = false; props.isDuplicated = true; const newComponent = React.cloneElement(component, props); elements.push(
{newComponent}
); } sectionsComponents.push(...elements); } } return sectionsComponents; }; return (
{sectionsList()} {customSections.map(({ id }) => (
))}
); }; export default LeftSidebar;