Skip to content

Commit

Permalink
fix(frontend): do not display pmtiles generated for another project
Browse files Browse the repository at this point in the history
  • Loading branch information
spwoodcock committed Jun 6, 2024
1 parent a688885 commit d1e8a6b
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions src/frontend/src/views/ProjectDetailsV2.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ const Home = () => {
const [dataExtractExtent, setDataExtractExtent] = useState(null);
const [taskBoundariesLayer, setTaskBoundariesLayer] = useState<null | Record<string, any>>(null);
// Can pass a File object, or a string URL to be read by PMTiles
const [customBasemapData, setCustomBasemapData] = useState<File | string>();
const [customBasemapData, setCustomBasemapData] = useState<File | string | null>();
const [viewState, setViewState] = useState('project_info');
const projectId: string = params.id;
const defaultTheme = useAppSelector((state) => state.theme.hotTheme);
Expand Down Expand Up @@ -263,10 +263,24 @@ const Home = () => {
}
const opfsPmtilesData = await readFileFromOPFS(projectOpfsBasemapPath);
setCustomBasemapData(opfsPmtilesData);
// setCustomBasemapData(projectOpfsBasemapPath);
};
useEffect(() => {
getPmtilesBasemap();
if (!projectOpfsBasemapPath) {
return;
}

// Extract project id from projectOpfsBasemapPath
const projectOpfsBasemapPathParts = projectOpfsBasemapPath.split('/');
const projectOpfsBasemapProjectId = projectOpfsBasemapPathParts[0];

// Check if project id from projectOpfsBasemapPath matches current projectId
if (projectOpfsBasemapProjectId !== projectId) {
// If they don't match, set CustomBasemapData to null
setCustomBasemapData(null);
} else {
// If they match, fetch the basemap data
getPmtilesBasemap();
}
return () => {};
}, [projectOpfsBasemapPath]);
const [showDebugConsole, setShowDebugConsole] = useState(false);
Expand Down

0 comments on commit d1e8a6b

Please sign in to comment.