Skip to content

Commit

Permalink
fix: fixed bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
adolfokrah committed Sep 25, 2024
1 parent e0bd370 commit 1d53102
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/components/exposed-components/list/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export default function List<T>({
key: `${propName}.${index}`,
className: cn('visio-cms-list-none', listItemClassName || setListItemClassName?.(values, index), {
'visio-cms-outline visio-cms-outline-2 visio-cms-outline-blue-500':
`${selectedBlock.id}.${selectedListItem?.propName}` === `${pageBlockId}.${propName}.${index}` && !globalBlock,
`${selectedBlock?.id}.${selectedListItem?.propName}` === `${pageBlockId}.${propName}.${index}` && !globalBlock,
}),
children: renderComponent(values, index),
onClick: (e: MouseEvent) => {
Expand Down
2 changes: 2 additions & 0 deletions src/components/pages/page-content/components/bock-item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ export default function BlockItem({
index={index}
pageBlock={{ ...pageBlock, isGlobalBlock: globalBlock != null }}
pageBlocks={pageBlocks}
propName={propName}
parentBlockId={parentBlockId}
>
<div
onMouseDown={(e) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export default function EmptyPageDroppable({
const [isDraggingOver, setIsDraggingOver] = useState(false);

return (
<RightClickMenu index={0} pageBlocks={[]}>
<RightClickMenu index={0} pageBlocks={[]} propName={propName} parentBlockId={pageBlockId}>
<div
className={cn(
'visio-cms-h-screen visio-cms-grid visio-cms-place-items-center',
Expand Down
16 changes: 12 additions & 4 deletions src/components/ui/right-click-menu/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,15 @@ export default function RightClickMenu({
pageBlock,
index,
pageBlocks,
propName,
parentBlockId
}: {
children: React.ReactNode;
pageBlock?: PageBlock;
index: number;
pageBlocks: PageBlock[];
propName?: string;
parentBlockId?: string
}) {
const pageBlockId = pageBlock?.id;
const copiedBlock = localStorage.getItem('copiedBlock');
Expand All @@ -33,12 +37,16 @@ export default function RightClickMenu({
isGlobal: copiedBlockData?.isGlobalBlock,
globalBlockId: copiedBlockData?.globalBlockId,
fromClipBoard: true,
propName: propName,
pageBlockId: parentBlockId
};
sendMessageToParent({
type: 'addBlock',
content: JSON.stringify({ ...data }),
});
};

const content = JSON.stringify({pageBlockId, propName})
return (
<ContextMenu>
<ContextMenuTrigger asChild onMouseDown={(e) => e.stopPropagation()} disabled={!pageBlock && !copiedBlock}>
Expand All @@ -51,7 +59,7 @@ export default function RightClickMenu({
className="visio-cms-text-xs"
disabled={index === 0}
onSelect={() => {
sendMessageToParent({ type: 'moveBlockUp', content: pageBlockId });
sendMessageToParent({ type: 'moveBlockUp', content });
}}
>
Move block up
Expand All @@ -63,7 +71,7 @@ export default function RightClickMenu({
className="visio-cms-text-xs"
disabled={index === pageBlocks.length - 1}
onSelect={() => {
sendMessageToParent({ type: 'moveBlockDown', content: pageBlockId });
sendMessageToParent({ type: 'moveBlockDown', content });
}}
>
Move block down
Expand All @@ -84,7 +92,7 @@ export default function RightClickMenu({
<ContextMenuItem
className="visio-cms-text-xs"
onSelect={() => {
sendMessageToParent({ type: 'removeBlock', content: pageBlockId });
sendMessageToParent({ type: 'removeBlock', content });
}}
>
Remove block
Expand Down Expand Up @@ -135,7 +143,7 @@ export default function RightClickMenu({
<ContextMenuItem
className="visio-cms-text-xs"
onSelect={() => {
sendMessageToParent({ type: 'convertBlockToGlobal', content: pageBlockId });
sendMessageToParent({ type: 'convertBlockToGlobal', content });
}}
>
Save block as global
Expand Down
3 changes: 2 additions & 1 deletion src/lib/hooks/useCanvas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export default function useCanvas() {
? JSON.parse(copiedBlock)?.inputs
: globalBlock?.inputs || block.Schema.defaultPropValues;


if (propName && foundBlock) {
const foundPropInput = getValueByPath(foundBlock?.inputs, propName.split('.')) || [];
foundPropInput.splice(position, 0, {
Expand Down Expand Up @@ -343,7 +344,7 @@ export default function useCanvas() {
}
} else if (data.type === 'copyBlock') {
const blockId = data.content;
const pageBlock = activePage?.blocks?.[activePage.activeLanguageLocale]?.find((block) => block.id === blockId);
const pageBlock = getSelectedBlock(activePage?.blocks?.[activePage.activeLanguageLocale], blockId)
if (pageBlock) {
localStorage.setItem('copiedBlock', JSON.stringify(pageBlock));
toast.success('Block copied');
Expand Down

0 comments on commit 1d53102

Please sign in to comment.