Skip to content

Commit

Permalink
chore(web): storyblock ux update (#776)
Browse files Browse the repository at this point in the history
  • Loading branch information
mkumbobeaty authored Nov 7, 2023
1 parent 3bbd0f9 commit 0c16b45
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ type Props = {
dndEnabled?: boolean;
settingsEnabled?: boolean;
onClick?: () => void;
onClickAway?: () => void;
onRemove?: () => void;
};

Expand All @@ -44,7 +43,6 @@ const BlockWrapper: React.FC<Props> = ({
dndEnabled = true,
settingsEnabled = true,
onClick,
onClickAway,
onRemove,
}) => {
const {
Expand Down Expand Up @@ -81,12 +79,13 @@ const BlockWrapper: React.FC<Props> = ({
setEditMode={setEditMode}
onEditModeToggle={handleEditModeToggle}
onSettingsToggle={handleSettingsToggle}
onRemove={onRemove}
onClickAway={onClickAway}>
onRemove={onRemove}>
<Block
padding={panelSettings?.padding?.value}
isEditable={isEditable}
onClick={handleBlockClick}>
onClick={e => {
handleBlockClick(e);
}}>
{children ?? (isEditable && <Template icon={icon} />)}
</Block>
{editMode && groupId && propertyId && settingsEnabled && (
Expand Down
24 changes: 14 additions & 10 deletions web/src/beta/lib/core/StoryPanel/Block/builtin/common/hooks.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { MouseEvent, useCallback, useEffect, useMemo, useState } from "react";
import { MouseEvent, useCallback, useMemo, useState } from "react";

import { Spacing } from "@reearth/beta/lib/core/mantle";

Expand All @@ -21,22 +21,26 @@ export default ({
}) => {
const [editMode, setEditMode] = useState(false);
const [showSettings, setShowSettings] = useState(false);

useEffect(() => {
if (!isSelected && editMode) {
setEditMode(false);
}
}, [isSelected, editMode]);

const title = useMemo(() => name ?? property?.title, [name, property?.title]);
const [clickCount, setClickCount] = useState(0);

const handleBlockClick = useCallback(
(e: MouseEvent<HTMLDivElement>) => {
e.stopPropagation();
if ((showSettings && isSelected) || editMode) return;
onClick?.();
if (clickCount === 0) {
setClickCount(1);
onClick?.();
setTimeout(() => {
setClickCount(0);
}, 300);
} else if (clickCount === 1) {
setClickCount(0);
setEditMode(true);
onClick?.();
}
},
[onClick, showSettings, isSelected, editMode],
[showSettings, isSelected, editMode, clickCount, onClick],
);

const defaultSettings = useMemo(() => property?.default ?? property?.title, [property]);
Expand Down
2 changes: 1 addition & 1 deletion web/src/beta/lib/core/StoryPanel/SelectableArea/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ const Wrapper = styled.div<{ isSelected?: boolean; noBorder?: boolean }>`
transition: all 0.3s;
padding: 1px;
position: relative;
overflow: hidden;
overflow: ${({ isSelected }) => (isSelected ? "visible" : "hidden")};
:hover {
border-color: ${({ isSelected, theme }) => !isSelected && theme.select.weaker};
Expand Down

0 comments on commit 0c16b45

Please sign in to comment.