import { Add, Close, Restore } from '@mui/icons-material'; import { Button, IconButton, Tooltip } from '@mui/material'; import clsx from 'clsx'; import cloneDeep from 'lodash/cloneDeep'; import get from 'lodash/get'; import { useTranslation } from 'next-i18next'; import { DragDropContext, Draggable, DraggableLocation, Droppable, DropResult } from 'react-beautiful-dnd'; import Heading from '@/components/shared/Heading'; import { useAppDispatch, useAppSelector } from '@/store/hooks'; import { addPage, deletePage, setResumeState } from '@/store/resume/resumeSlice'; import styles from './Layout.module.scss'; const getIndices = (location: DraggableLocation) => ({ page: +location.droppableId.split('.')[0], column: +location.droppableId.split('.')[1], section: +location.index, }); const Layout = () => { const { t } = useTranslation(); const dispatch = useAppDispatch(); const layout = useAppSelector((state) => state.resume.metadata.layout); const resumeSections = useAppSelector((state) => state.resume.sections); const onDragEnd = (dropResult: DropResult) => { const { source: srcLoc, destination: destLoc } = dropResult; if (!destLoc) return; const newLayout = cloneDeep(layout); const srcIndex = getIndices(srcLoc); const destIndex = getIndices(destLoc); const section = layout[srcIndex.page][srcIndex.column][srcIndex.section]; // Remove item at source newLayout[srcIndex.page][srcIndex.column].splice(srcIndex.section, 1); // Insert item at destination newLayout[destIndex.page][destIndex.column].splice(destIndex.section, 0, section); dispatch(setResumeState({ path: 'metadata.layout', value: newLayout })); }; const handleAddPage = () => dispatch(addPage()); const handleDeletePage = (page: number) => dispatch(deletePage({ page })); const handleResetLayout = () => { for (let i = layout.length - 1; i > 0; i--) { handleDeletePage(i); } }; return ( <> ('builder.rightSidebar.sections.layout.tooltip.reset-layout')}> } /> {/* Pages */} {layout.map((columns, pageIndex) => (

{t('builder.common.glossary.page')} {pageIndex + 1}

('builder.common.actions.delete', { token: t('builder.common.glossary.page') })} > handleDeletePage(pageIndex)}>
{/* Sections */} {columns.map((sections, columnIndex) => { const index = `${pageIndex}.${columnIndex}`; return ( {(provided) => (

{columnIndex ? 'Sidebar' : 'Main'}

{/* Sections */} {sections.map((sectionId, sectionIndex) => ( {(provided) => (
{get(resumeSections, `${sectionId}.name`)}
)}
))} {provided.placeholder}
)} ); })}
))}
); }; export default Layout;