Skip to content

Commit

Permalink
Polishing TuneMenu arrows (#125)
Browse files Browse the repository at this point in the history
  • Loading branch information
cohitre authored Aug 8, 2024
1 parent 029ca67 commit 18e513d
Showing 1 changed file with 16 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ import { ArrowDownwardOutlined, ArrowUpwardOutlined, DeleteOutlined } from '@mui
import { IconButton, Paper, Stack, Tooltip } from '@mui/material';

import { TEditorBlock } from '../../../editor/core';
import { resetDocument, useDocument } from '../../../editor/EditorContext';
import { resetDocument, setSelectedBlockId, useDocument } from '../../../editor/EditorContext';
import { ColumnsContainerProps } from '../../ColumnsContainer/ColumnsContainerPropsSchema';

const STYLE: CSSProperties = {
position: 'absolute',
top: 0,
left: -52,
borderRadius: 64,
padding: 2,
};

type Props = {
Expand Down Expand Up @@ -78,19 +79,20 @@ export default function TuneMenu({ blockId }: Props) {
};

const handleMoveClick = (direction: 'up' | 'down') => {
const moveChildrenIds = (childrenIds: string[] | null | undefined) => {
if (!childrenIds) {
return childrenIds;
const moveChildrenIds = (ids: string[] | null | undefined) => {
if (!ids) {
return ids;
}
const index = childrenIds.indexOf(blockId);
if (index !== -1) {
if (direction === 'up' && index > 0) {
[childrenIds[index], childrenIds[index - 1]] = [childrenIds[index - 1], childrenIds[index]];
} else if (direction === 'down' && index < childrenIds.length - 1) {
[childrenIds[index], childrenIds[index + 1]] = [childrenIds[index + 1], childrenIds[index]];
}
const index = ids.indexOf(blockId);
if (index < 0) {
return ids;
}
const childrenIds = [...ids];
if (direction === 'up' && index > 0) {
[childrenIds[index], childrenIds[index - 1]] = [childrenIds[index - 1], childrenIds[index]];
} else if (direction === 'down' && index < childrenIds.length - 1) {
[childrenIds[index], childrenIds[index + 1]] = [childrenIds[index + 1], childrenIds[index]];
}

return childrenIds;
};
const nDocument: typeof document = { ...document };
Expand Down Expand Up @@ -139,8 +141,9 @@ export default function TuneMenu({ blockId }: Props) {
nDocument[id] = block;
}
}
console.log(nDocument);

resetDocument(nDocument);
setSelectedBlockId(blockId);
};

return (
Expand Down

0 comments on commit 18e513d

Please sign in to comment.