From 4813e9e787cac79ab88cb31327a0d87ffb6b7a41 Mon Sep 17 00:00:00 2001 From: sophia-massie Date: Mon, 27 Jan 2025 16:46:58 -0600 Subject: [PATCH] task/WG-401-Add-Asset-to-Feature-Hook --- .../components/AssetDetail/AssetButton.tsx | 34 +++++++++++++++++-- react/src/hooks/features/index.ts | 1 + .../hooks/features/useImportFeatureAsset.ts | 12 +++++++ react/src/types/feature.ts | 4 +++ 4 files changed, 48 insertions(+), 3 deletions(-) create mode 100644 react/src/hooks/features/useImportFeatureAsset.ts diff --git a/react/src/components/AssetDetail/AssetButton.tsx b/react/src/components/AssetDetail/AssetButton.tsx index 197a22b1..72fbb035 100644 --- a/react/src/components/AssetDetail/AssetButton.tsx +++ b/react/src/components/AssetDetail/AssetButton.tsx @@ -2,7 +2,8 @@ import React from 'react'; import DOMPurify from 'dompurify'; import { Button } from '@tacc/core-components'; import { Feature, FeatureType } from '@hazmapper/types'; -import { getFeatureType } from '@hazmapper/types'; +import { getFeatureType, IFileImportRequest } from '@hazmapper/types'; +import { useImportFeatureAsset } from '@hazmapper/hooks'; type AssetButtonProps = { selectedFeature: Feature; @@ -20,6 +21,26 @@ const AssetButton: React.FC = ({ const pointCloudURL = DOMPurify.sanitize(featureSource + '/index.html'); const featureType = getFeatureType(selectedFeature); + const projectId = selectedFeature.project_id; + const featureId = selectedFeature.id; + const { + mutate: importFeatureAsset, + isPending: isImporting, + isSuccess: isImportingSuccess, + } = useImportFeatureAsset(projectId, featureId); + + const handleImportFeatureAsset = (importData: IFileImportRequest) => { + importFeatureAsset(importData); + }; + const handleSubmit = () => { + const importData: IFileImportRequest = { + /*TODO Replace with passed in values from + FileBrowserModal. These are hardcoded to test.*/ + system_id: 'project-4072868216578445806-242ac117-0001-012', + path: 'images_good/image.jpg', + }; + handleImportFeatureAsset(importData); + }; return ( <> @@ -36,9 +57,16 @@ const AssetButton: React.FC = ({ View )} - {featureType.includes(selectedFeature.geometry.type) && isPublicView && ( + {featureType.includes(selectedFeature.geometry.type) && !isPublicView && ( //TODO - + )} ); diff --git a/react/src/hooks/features/index.ts b/react/src/hooks/features/index.ts index 5e114f75..15f98749 100644 --- a/react/src/hooks/features/index.ts +++ b/react/src/hooks/features/index.ts @@ -1,4 +1,5 @@ export { useDeleteFeature } from './useDeleteFeature'; +export { useImportFeatureAsset } from './useImportFeatureAsset'; export { useFeatures, useCurrentFeatures, diff --git a/react/src/hooks/features/useImportFeatureAsset.ts b/react/src/hooks/features/useImportFeatureAsset.ts new file mode 100644 index 00000000..e8a4f305 --- /dev/null +++ b/react/src/hooks/features/useImportFeatureAsset.ts @@ -0,0 +1,12 @@ +import { usePost } from '../../requests'; +import { ApiService, Feature, IFileImportRequest } from '@hazmapper/types'; + +export const useImportFeatureAsset = (projectId: number, featureId: number) => { + const endpoint = `/projects/${projectId}/features/${featureId}/assets/`; + return usePost({ + endpoint, + apiService: ApiService.Geoapi, + }); +}; + +export default useImportFeatureAsset; diff --git a/react/src/types/feature.ts b/react/src/types/feature.ts index 6f48f95d..de24c0e2 100644 --- a/react/src/types/feature.ts +++ b/react/src/types/feature.ts @@ -147,3 +147,7 @@ export interface QuestionnaireAsset { path: string; previewPath: string; } +export interface IFileImportRequest { + system_id: string; + path: string; +}