Skip to content

Commit

Permalink
chore(web): fix infobox blocks using old value when new value is unde…
Browse files Browse the repository at this point in the history
…fined (#943)
  • Loading branch information
KaWaite authored Mar 26, 2024
1 parent 78bcd8d commit b43956e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ export default (value: unknown | undefined) => {
const [isReady, setIsReady] = useState(false);
const [currentValue, setCurrentValue] = useState<unknown | undefined>(value);

const [lastFeatureSelected, setLastFeatureSelected] = useState<string | undefined>(undefined);

const [evaluatedResult, setEvaluatedResult] = useState<string | undefined>(undefined);

const visualizer = useVisualizer();
Expand All @@ -25,7 +27,10 @@ export default (value: unknown | undefined) => {
return;
}
const selectedFeature = visualizer.current?.layers.selectedFeature();
if (selectedFeature) {
if (selectedFeature && selectedFeature.id !== lastFeatureSelected) {
setLastFeatureSelected(selectedFeature.id);
setEvaluatedResult(undefined);
} else if (selectedFeature) {
const simpleFeature: Feature = {
id: selectedFeature.id,
type: "feature",
Expand Down
9 changes: 6 additions & 3 deletions web/src/beta/lib/core/Crust/Infobox/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,14 @@ export default ({
const [selectedBlockId, setSelectedBlockId] = useState<string>();
const [openBlocksIndex, setOpenBlocksIndex] = useState<number>();

// Will only be undefined when infobox is first created, so default to true
const showInfobox = useMemo(
() =>
infobox?.property?.default?.enabled?.value === undefined
? false
: !!infobox.property.default.enabled.value,
infobox
? infobox?.property?.default?.enabled?.value === undefined
? true
: !!infobox.property.default.enabled.value
: false,
[infobox],
);

Expand Down

0 comments on commit b43956e

Please sign in to comment.