Skip to content

Commit

Permalink
chore(web): fly to layers (#739)
Browse files Browse the repository at this point in the history
  • Loading branch information
mkumbobeaty authored Oct 18, 2023
1 parent 6c8a42f commit ce69e7f
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 34 deletions.
6 changes: 3 additions & 3 deletions web/src/beta/features/Editor/Visualizer/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ import {
useSelected,
useSelectedBlock,
useWidgetAlignEditorActivated,
useZoomedLayerId,
selectedWidgetAreaVar,
isVisualizerReadyVar,
useZoomedLayerId,
} from "@reearth/services/state";

import { convertStory, convertWidgets, processLayers } from "./convert";
Expand Down Expand Up @@ -261,7 +261,6 @@ export default ({
sceneId,
rootLayerId,
selectedLayerId,
zoomedLayerId,
selectedBlockId: selectedBlock,
sceneProperty,
pluginProperty,
Expand All @@ -280,6 +279,7 @@ export default ({
useExperimentalSandbox,
isVisualizerReady,
selectWidgetArea: selectedWidgetAreaVar,
zoomedLayerId,
handleStoryBlockCreate,
handleStoryBlockDelete,
handlePropertyValueUpdate,
Expand All @@ -293,7 +293,7 @@ export default ({
onWidgetAlignSystemUpdate,
onIsCapturingChange,
handleDropLayer,
zoomToLayer,
handleMount,
zoomToLayer,
};
};
4 changes: 2 additions & 2 deletions web/src/beta/features/Editor/Visualizer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ const Visualizer: React.FC<Props> = ({
const {
rootLayerId,
selectedBlockId,
zoomedLayerId,
sceneProperty,
pluginProperty,
clusters,
Expand All @@ -62,6 +61,7 @@ const Visualizer: React.FC<Props> = ({
layerSelectionReason,
useExperimentalSandbox,
isVisualizerReady: _isVisualizerReady,
zoomedLayerId,
handleStoryBlockCreate,
handleStoryBlockDelete,
handlePropertyValueUpdate,
Expand All @@ -75,8 +75,8 @@ const Visualizer: React.FC<Props> = ({
onWidgetAlignSystemUpdate,
selectWidgetArea,
handleDropLayer,
zoomToLayer,
handleMount,
zoomToLayer,
} = useHooks({ sceneId, isBuilt, storyId: selectedStory?.id, currentPage, showStoryPanel });

const renderInfoboxInsertionPopUp = useCallback<
Expand Down
1 change: 1 addition & 0 deletions web/src/beta/features/Editor/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ const Editor: React.FC<Props> = ({ sceneId, projectId, workspaceId, tab }) => {
onLayerNameUpdate: handleLayerNameUpdate,
onSceneSettingSelect: handleSceneSettingSelect,
onDataSourceManagerOpen: handleDataSourceManagerOpener,
onFlyTo: handleFlyTo,
});

const { rightPanel } = useRightPanel({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// import ListItem from "@reearth/beta/components/ListItem";
import SidePanelSectionField from "@reearth/beta/components/SidePanelSectionField";
import type { LayerNameUpdateProps } from "@reearth/beta/features/Editor/useLayers";
import { FlyTo } from "@reearth/beta/lib/core/types";
import type { NLSLayer } from "@reearth/services/api/layersApi/utils";
import { useT } from "@reearth/services/i18n";
import { styled } from "@reearth/services/theme";
Expand All @@ -16,6 +17,7 @@ type GroupSectionFieldProps = {
onLayerSelect: (id: string) => void;
onSceneSettingSelect: () => void;
onDataSourceManagerOpen: () => void;
onFlyTo?: FlyTo;
};

const GroupSectionField: React.FC<GroupSectionFieldProps> = ({
Expand All @@ -27,6 +29,7 @@ const GroupSectionField: React.FC<GroupSectionFieldProps> = ({
onLayerSelect,
// onSceneSettingSelect,
onDataSourceManagerOpen,
onFlyTo,
}) => {
const t = useT();

Expand All @@ -50,6 +53,7 @@ const GroupSectionField: React.FC<GroupSectionFieldProps> = ({
onLayerNameUpdate={onLayerNameUpdate}
onLayerSelect={onLayerSelect}
onDataSourceManagerOpen={onDataSourceManagerOpen}
onFlyTo={onFlyTo}
/>
</StyledSidePanelSectionField>
</>
Expand Down
83 changes: 56 additions & 27 deletions web/src/beta/features/Editor/tabs/map/LeftPanel/Layers/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import Icon from "@reearth/beta/components/Icon";
import * as Popover from "@reearth/beta/components/Popover";
import PopoverMenuContent from "@reearth/beta/components/PopoverMenuContent";
import type { LayerNameUpdateProps } from "@reearth/beta/features/Editor/useLayers";
import { FlyTo } from "@reearth/beta/lib/core/types";
import type { NLSLayer } from "@reearth/services/api/layersApi/utils";
import { useT } from "@reearth/services/i18n";
import { styled } from "@reearth/services/theme";
Expand All @@ -17,6 +18,7 @@ type LayersProps = {
onLayerNameUpdate: (inp: LayerNameUpdateProps) => void;
onLayerSelect: (id: string) => void;
onDataSourceManagerOpen: () => void;
onFlyTo?: FlyTo;
};

const Layers: React.FC<LayersProps> = ({
Expand All @@ -26,6 +28,7 @@ const Layers: React.FC<LayersProps> = ({
onLayerNameUpdate,
onLayerSelect,
onDataSourceManagerOpen,
onFlyTo,
}) => {
const t = useT();
const [isAddMenuOpen, setAddMenuOpen] = useState(false);
Expand All @@ -34,36 +37,51 @@ const Layers: React.FC<LayersProps> = ({
setAddMenuOpen(prev => !prev);
}, []);

const handleZoomToLayer = () => {
if (selectedLayerId) {
onFlyTo?.(selectedLayerId);
}
};

return (
<LayerContainer>
<Popover.Provider open={isAddMenuOpen} onOpenChange={toggleAddMenu} placement="bottom-end">
<Popover.Trigger asChild>
<AddLayerIcon onClick={toggleAddMenu}>
<Icon icon="addLayer" />
</AddLayerIcon>
</Popover.Trigger>
<ActionWrapper>
<StyledIcon
onClick={handleZoomToLayer}
icon="zoomToLayer"
size={16}
disabled={!selectedLayerId}
/>
<Popover.Provider open={isAddMenuOpen} onOpenChange={toggleAddMenu} placement="bottom-end">
<Popover.Trigger asChild>
<AddLayerIcon onClick={toggleAddMenu}>
<Icon icon="addLayer" />
</AddLayerIcon>
</Popover.Trigger>

<Popover.Content>
<PopoverMenuContent
size="md"
items={[
{
name: t("Add Layer from Resource"),
icon: "file",
onClick: () => {
onDataSourceManagerOpen();
toggleAddMenu();
<Popover.Content>
<PopoverMenuContent
size="md"
items={[
{
name: t("Add Layer from Resource"),
icon: "file",
onClick: () => {
onDataSourceManagerOpen();
toggleAddMenu();
},
},
},
// {
// name: t("Add Sketch Layer"),
// icon: "pencilSimple",
// onClick: () => {},
// },
]}
/>
</Popover.Content>
</Popover.Provider>
// {
// name: t("Add Sketch Layer"),
// icon: "pencilSimple",
// onClick: () => {},
// },
]}
/>
</Popover.Content>
</Popover.Provider>
</ActionWrapper>

{layers.map(layer => (
<LayerItem
key={layer.id}
Expand All @@ -84,11 +102,22 @@ const LayerContainer = styled.div`
flex-direction: column;
`;

const ActionWrapper = styled.div`
flex: 1;
display: flex;
justify-content: right;
`;

const AddLayerIcon = styled.div`
padding: 2px;
margin-bottom: 2px;
align-self: flex-end;
cursor: pointer;
`;

const StyledIcon = styled(Icon)<{ disabled?: boolean }>`
padding: 3px;
cursor: ${({ disabled }) => (disabled ? "default" : "pointer")};
color: ${({ disabled, theme }) => (disabled ? theme.content.weak : theme.content.strong)};
border-radius: 5px;
`;
export default Layers;
4 changes: 4 additions & 0 deletions web/src/beta/features/Editor/tabs/map/LeftPanel/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import SidePanelCommon from "@reearth/beta/features/Editor/SidePanel";
import GroupSectionField from "@reearth/beta/features/Editor/tabs/map/LeftPanel/GroupField";
import { FlyTo } from "@reearth/beta/lib/core/types";
import type { NLSLayer } from "@reearth/services/api/layersApi/utils";
import { useT } from "@reearth/services/i18n";

Expand All @@ -14,6 +15,7 @@ type Props = {
onLayerSelect: (id: string) => void;
onSceneSettingSelect: () => void;
onDataSourceManagerOpen: () => void;
onFlyTo?: FlyTo;
};

const MapSidePanel: React.FC<Props> = ({
Expand All @@ -25,6 +27,7 @@ const MapSidePanel: React.FC<Props> = ({
onLayerNameUpdate,
onSceneSettingSelect,
onDataSourceManagerOpen,
onFlyTo,
}) => {
const t = useT();

Expand All @@ -45,6 +48,7 @@ const MapSidePanel: React.FC<Props> = ({
onLayerSelect={onLayerSelect}
onSceneSettingSelect={onSceneSettingSelect}
onDataSourceManagerOpen={onDataSourceManagerOpen}
onFlyTo={onFlyTo}
/>
),
},
Expand Down
9 changes: 7 additions & 2 deletions web/src/beta/features/Editor/useLeftPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { ReactNode, useMemo } from "react";
import MapSidePanel from "@reearth/beta/features/Editor/tabs/map/LeftPanel";
import StorySidePanel from "@reearth/beta/features/Editor/tabs/story/LeftPanel";
import { Tab } from "@reearth/beta/features/Navbar";
import { FlyTo } from "@reearth/beta/lib/core/types";
import type { NLSLayer } from "@reearth/services/api/layersApi/utils";
import type { Story } from "@reearth/services/api/storytellingApi/utils";

Expand Down Expand Up @@ -31,6 +32,7 @@ type Props = {
onLayerNameUpdate: (inp: LayerNameUpdateProps) => void;
onLayerSelect: (id: string) => void;
onDataSourceManagerOpen: () => void;
onFlyTo?: FlyTo;
};

export default ({
Expand All @@ -50,6 +52,7 @@ export default ({
onLayerSelect,
onSceneSettingSelect,
onDataSourceManagerOpen,
onFlyTo,
}: Props) => {
const leftPanel = useMemo<ReactNode | undefined>(() => {
switch (tab) {
Expand All @@ -64,6 +67,7 @@ export default ({
onLayerSelect={onLayerSelect}
onSceneSettingSelect={onSceneSettingSelect}
onDataSourceManagerOpen={onDataSourceManagerOpen}
onFlyTo={onFlyTo}
/>
);
case "story":
Expand All @@ -86,15 +90,16 @@ export default ({
}, [
tab,
nlsLayers,
selectedStory,
selectedLayerId,
selectedSceneSetting,
currentPageId,
onLayerDelete,
onLayerNameUpdate,
onLayerSelect,
onSceneSettingSelect,
onDataSourceManagerOpen,
onFlyTo,
selectedStory,
currentPageId,
onCurrentPageChange,
onPageDuplicate,
onPageDelete,
Expand Down

0 comments on commit ce69e7f

Please sign in to comment.