Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(web): Story page click away #806

Merged
merged 5 commits into from
Nov 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions web/src/beta/lib/core/StoryPanel/Page/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ const StoryPanel: React.FC<Props> = ({
showSettings={showPageSettings}
isEditable={isEditable}
onClick={() => onPageSelect?.(page?.id)}
onClickAway={onPageSelect}
onSettingsToggle={onPageSettingsToggle}>
<Wrapper id={page?.id} padding={panelSettings.padding.value} gap={panelSettings.gap.value}>
{(isEditable || title?.title?.value) && (
Expand All @@ -115,7 +114,6 @@ const StoryPanel: React.FC<Props> = ({
isEditable={isEditable}
isSelected={selectedStoryBlockId === titleId}
onClick={() => onBlockSelect?.(titleId)}
onClickAway={onBlockSelect}
onPropertyUpdate={onPropertyUpdate}
onPropertyItemAdd={onPropertyItemAdd}
onPropertyItemMove={onPropertyItemMove}
Expand Down Expand Up @@ -158,7 +156,6 @@ const StoryPanel: React.FC<Props> = ({
isSelected={selectedStoryBlockId === b.id}
isEditable={isEditable}
onClick={() => onBlockSelect?.(b.id)}
onClickAway={onBlockSelect}
onRemove={onBlockDelete}
onPropertyUpdate={onPropertyUpdate}
onPropertyItemAdd={onPropertyItemAdd}
Expand Down
11 changes: 2 additions & 9 deletions web/src/beta/lib/core/StoryPanel/SelectableArea/hooks.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import { Dispatch, SetStateAction, useCallback, useEffect, useState } from "react";
import { Dispatch, SetStateAction, useEffect, useState } from "react";

type Props = {
editMode?: boolean;
isSelected?: boolean;
setEditMode?: Dispatch<SetStateAction<boolean>>;
onClickAway?: () => void;
};

export default ({ editMode, isSelected, setEditMode, onClickAway }: Props) => {
export default ({ editMode, isSelected, setEditMode }: Props) => {
const [showPadding, setShowPadding] = useState(false);

useEffect(() => {
Expand All @@ -16,14 +15,8 @@ export default ({ editMode, isSelected, setEditMode, onClickAway }: Props) => {
}
}, [isSelected, editMode, setEditMode]);

const handleClickAway = useCallback(() => {
setShowPadding(false);
onClickAway?.();
}, [onClickAway]);

return {
showPadding,
setShowPadding,
handleClickAway,
};
};
56 changes: 25 additions & 31 deletions web/src/beta/lib/core/StoryPanel/SelectableArea/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { Dispatch, ReactNode, SetStateAction } from "react";
import { styled } from "@reearth/services/theme";

import ActionPanel, { type ActionPosition } from "../Block/builtin/common/ActionPanel";
import ClickAwayListener from "../ClickAwayListener";

import useHooks from "./hooks";

Expand All @@ -24,7 +23,6 @@ type Props = {
onEditModeToggle?: () => void;
onSettingsToggle?: () => void;
onClick?: () => void;
onClickAway?: () => void;
onRemove?: () => void;
onPropertyUpdate?: (
propertyId?: string,
Expand Down Expand Up @@ -55,49 +53,45 @@ const SelectableArea: React.FC<Props> = ({
setEditMode,
onEditModeToggle,
onSettingsToggle,
onClick,
onClickAway,
onRemove,
onClick,
onPropertyUpdate,
onPropertyItemAdd,
onPropertyItemMove,
onPropertyItemDelete,
}) => {
const { showPadding, setShowPadding, handleClickAway } = useHooks({
const { showPadding, setShowPadding } = useHooks({
editMode,
isSelected,
setEditMode,
onClickAway,
});

return !isEditable ? (
<>{children}</>
) : (
<ClickAwayListener enabled={isSelected} onClickAway={handleClickAway}>
<Wrapper isSelected={isSelected} noBorder={noBorder} onClick={onClick}>
<ActionPanel
title={title}
icon={icon}
isSelected={isSelected}
showSettings={showSettings}
showPadding={showPadding}
editMode={editMode}
propertyId={propertyId}
panelSettings={panelSettings}
dndEnabled={dndEnabled}
position={position}
setShowPadding={setShowPadding}
onEditModeToggle={onEditModeToggle}
onSettingsToggle={onSettingsToggle}
onRemove={onRemove}
onPropertyUpdate={onPropertyUpdate}
onPropertyItemAdd={onPropertyItemAdd}
onPropertyItemMove={onPropertyItemMove}
onPropertyItemDelete={onPropertyItemDelete}
/>
{children}
</Wrapper>
</ClickAwayListener>
<Wrapper isSelected={isSelected} noBorder={noBorder} onClick={onClick}>
<ActionPanel
title={title}
icon={icon}
isSelected={isSelected}
showSettings={showSettings}
showPadding={showPadding}
editMode={editMode}
propertyId={propertyId}
panelSettings={panelSettings}
dndEnabled={dndEnabled}
position={position}
setShowPadding={setShowPadding}
onEditModeToggle={onEditModeToggle}
onSettingsToggle={onSettingsToggle}
onRemove={onRemove}
onPropertyUpdate={onPropertyUpdate}
onPropertyItemAdd={onPropertyItemAdd}
onPropertyItemMove={onPropertyItemMove}
onPropertyItemDelete={onPropertyItemDelete}
/>
{children}
</Wrapper>
);
};

Expand Down
Loading