Skip to content

Commit

Permalink
feat: return data promise to onNodeClick
Browse files Browse the repository at this point in the history
  • Loading branch information
haakonflatval-cognite committed Aug 4, 2023
1 parent b41109e commit 5cec685
Showing 1 changed file with 10 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export type Reveal3DResourcesProps<NodeType = any> = {
resources: AddResourceOptions[];
fdmAssetMappingConfig: FdmAssetMappingsConfig;
styling?: Reveal3DResourcesStyling;
onNodeClick?: (node: NodeDataResult<NodeType> | undefined) => void;
onNodeClick?: (node: Promise<NodeDataResult<NodeType> | undefined>) => void;
};

export const Reveal3DResources = <NodeType = any,>({
Expand Down Expand Up @@ -75,18 +75,15 @@ export const Reveal3DResources = <NodeType = any,>({

useEffect(() => {
const callback = (event: PointerEventData): void => {
void (async (event: PointerEventData): Promise<void> => {
if (onNodeClick === undefined) return;
const data = await queryMappedData<NodeType>(
viewer,
client,
fdmSdk,
fdmAssetMappingConfig,
event
);

onNodeClick(data);
})(event);
if (onNodeClick === undefined) return;
const data = queryMappedData<NodeType>(
viewer,
client,
fdmSdk,
event,
fdmAssetMappingConfig
);
onNodeClick(data);
};

viewer.on('click', callback);
Expand Down

0 comments on commit 5cec685

Please sign in to comment.