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

fix(web): sketch layer custom property in infobox #1248

Merged
merged 7 commits into from
Nov 19, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ const Content: FC<Props> = ({ block, isEditable, ...props }) => {
displayTypeField?.value === "custom" ? (
properties ? (
<CustomFields
selectedFeature={selectedComputedFeature}
properties={properties}
extensionId={block?.extensionId}
/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Template from "@reearth/beta/features/Visualizer/Crust/StoryPanel/Block/Template";
import { ComputedFeature } from "@reearth/core";
import { FC } from "react";

import { PropertyListItem } from "../ListEditor";
Expand All @@ -8,11 +9,19 @@ import useEvaluateProperties from "./useEvaluateProperties";

type Props = {
extensionId?: string;
selectedFeature?: ComputedFeature;
properties?: PropertyListItem[];
};

const CustomFields: FC<Props> = ({ extensionId, properties }) => {
const evaluatedProperties = useEvaluateProperties(properties);
const CustomFields: FC<Props> = ({
extensionId,
properties,
selectedFeature
}) => {
const evaluatedProperties = useEvaluateProperties({
selectedFeature,
properties
});

return (
<>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import { evalExpression, useVisualizer, Feature } from "@reearth/core";
import { evalExpression, Feature, ComputedFeature } from "@reearth/core";
import { isEqual } from "lodash-es";
import { useEffect, useState } from "react";

import { PropertyListItem } from "../ListEditor";

export default (properties: PropertyListItem[] | undefined) => {
type Props = {
selectedFeature?: ComputedFeature;
properties?: PropertyListItem[];
};
export default ({ properties, selectedFeature }: Props) => {
const [isReady, setIsReady] = useState(false);
const [currentValue, setCurrentValue] = useState<
PropertyListItem[] | undefined
Expand All @@ -14,7 +18,6 @@ export default (properties: PropertyListItem[] | undefined) => {
PropertyListItem[] | undefined
>(undefined);

const visualizer = useVisualizer();

// We want the useEffect to be called on each render to make sure evaluatedProperties is up to date
useEffect(() => {
Expand All @@ -27,7 +30,6 @@ export default (properties: PropertyListItem[] | undefined) => {
setEvaluatedResult(undefined);
return;
}
const selectedFeature = visualizer.current?.layers.selectedFeature();
if (selectedFeature) {
const simpleFeature: Feature = {
id: selectedFeature.id,
Expand Down Expand Up @@ -58,7 +60,7 @@ export default (properties: PropertyListItem[] | undefined) => {
setEvaluatedResult(es as PropertyListItem[]);
}
}
}, [isReady, currentValue, properties, evaluatedProperties, visualizer]);
}, [isReady, currentValue, properties, evaluatedProperties, selectedFeature]);

return evaluatedProperties?.filter((ep) => ep !== undefined);
};
Loading