From d6bf3ef1fcf35bc357f470252c20d93cc4e366e5 Mon Sep 17 00:00:00 2001 From: Beatrice Mkumbo Date: Sun, 26 Nov 2023 22:14:27 +0300 Subject: [PATCH] chore(web): fix story block bugs (#829) Co-authored-by: KaWaite <34051327+KaWaite@users.noreply.github.com> --- .../beta/components/DragAndDropList/Item.tsx | 10 +++++-- .../StoryPanel/Block/builtin/Timeline/hook.ts | 8 ++--- .../Block/builtin/common/Wrapper.tsx | 7 ++++- .../StoryPanel/Block/builtin/common/hooks.ts | 30 ++++++++++--------- .../beta/lib/core/StoryPanel/Block/types.ts | 2 ++ .../beta/lib/core/StoryPanel/Page/index.tsx | 6 +++- .../core/StoryPanel/PanelContent/index.tsx | 3 ++ web/src/beta/lib/core/StoryPanel/hooks.ts | 7 ++++- web/src/beta/lib/core/StoryPanel/index.tsx | 3 ++ 9 files changed, 52 insertions(+), 24 deletions(-) diff --git a/web/src/beta/components/DragAndDropList/Item.tsx b/web/src/beta/components/DragAndDropList/Item.tsx index 66a0a8cf6e..4d91d3ffde 100644 --- a/web/src/beta/components/DragAndDropList/Item.tsx +++ b/web/src/beta/components/DragAndDropList/Item.tsx @@ -102,7 +102,11 @@ const Item: FC = ({ drop(contentRef); return shouldUseCustomHandler ? ( - +
{children}
@@ -115,7 +119,7 @@ const Item: FC = ({ export default memo(Item); -const SItem = styled.div<{ isDragging: boolean }>` +const SItem = styled.div<{ isDragging: boolean; customHandler?: boolean }>` ${({ isDragging }) => `opacity: ${isDragging ? 0 : 1};`} - cursor: move; + cursor: ${({ customHandler }) => (customHandler ? "default" : "move")}; `; diff --git a/web/src/beta/lib/core/StoryPanel/Block/builtin/Timeline/hook.ts b/web/src/beta/lib/core/StoryPanel/Block/builtin/Timeline/hook.ts index d6992f509f..11a455fd13 100644 --- a/web/src/beta/lib/core/StoryPanel/Block/builtin/Timeline/hook.ts +++ b/web/src/beta/lib/core/StoryPanel/Block/builtin/Timeline/hook.ts @@ -250,7 +250,7 @@ export default ({ if (!handleOnDrag || !e.target || !range) { return; } - if (target && target.style.pointerEvents === "none") { + if (target && target.style.pointerEvents === "none" && !inEditor) { const evt = e; let newPosition = evt.clientX - distX.current; newPosition = Math.max(newPosition, 16); @@ -260,17 +260,17 @@ export default ({ committer?.id && handleOnDrag(new Date(conv), committer?.id); } }, - [committer?.id, handleOnDrag, range, target], + [committer?.id, handleOnDrag, inEditor, range, target], ); const handleOnClick: MouseEventHandler = useCallback( e => { - if (range) { + if (!inEditor && range) { const conv = convertPositionToTime(e as unknown as MouseEvent, range.start, range.end); committer?.id && handleOnDrag(new Date(conv), committer?.id); } }, - [range, committer?.id, handleOnDrag], + [inEditor, range, committer?.id, handleOnDrag], ); const handleTimelineCommitterChange = useCallback( (committer: TimelineCommitter) => { diff --git a/web/src/beta/lib/core/StoryPanel/Block/builtin/common/Wrapper.tsx b/web/src/beta/lib/core/StoryPanel/Block/builtin/common/Wrapper.tsx index 55520b757e..514c4e889e 100644 --- a/web/src/beta/lib/core/StoryPanel/Block/builtin/common/Wrapper.tsx +++ b/web/src/beta/lib/core/StoryPanel/Block/builtin/common/Wrapper.tsx @@ -30,6 +30,7 @@ type Props = { settingsEnabled?: boolean; onClick?: () => void; onRemove?: () => void; + onBlockDoubleClick?: () => void; onPropertyUpdate?: ( propertyId?: string, schemaItemId?: string, @@ -63,6 +64,7 @@ const BlockWrapper: React.FC = ({ dndEnabled = true, settingsEnabled = true, onClick, + onBlockDoubleClick, onRemove, onPropertyUpdate, onPropertyItemAdd, @@ -80,12 +82,14 @@ const BlockWrapper: React.FC = ({ handleEditModeToggle, handleSettingsToggle, handleBlockClick, + handleDoubleClick, } = useHooks({ name, isSelected, property, isEditable, onClick, + onBlockDoubleClick, }); return ( @@ -113,7 +117,8 @@ const BlockWrapper: React.FC = ({ isEditable={isEditable} onClick={e => { handleBlockClick(e); - }}> + }} + onDoubleClick={handleDoubleClick}> {children ?? (isEditable &&