Skip to content

Commit

Permalink
feat: create search app skeleton
Browse files Browse the repository at this point in the history
refs #22
  • Loading branch information
steveoh committed Dec 4, 2024
1 parent c22c29f commit 9ca9d67
Show file tree
Hide file tree
Showing 10 changed files with 85 additions and 12 deletions.
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"plss",
"PROJECTCATEGORYFUNDING",
"sgid",
"shapefile",
"sitla",
"srid",
"tagname",
Expand Down
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions search.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<div class="agrc-container">
<noscript> You need to enable JavaScript to run this app. </noscript>
<div id="root"></div>
<script type="module" src="/src/mainSearch.tsx"></script>
</div>
2 changes: 1 addition & 1 deletion src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export default function App() {
<div className="relative flex flex-1 flex-col rounded border border-b-0 border-zinc-200 dark:border-0 dark:border-zinc-700">
<div className="relative flex-1">
<ErrorBoundary FallbackComponent={ErrorFallback}>
<MapContainer />
<MapContainer configuration="edit" />
</ErrorBoundary>
<Drawer
type="tray"
Expand Down
24 changes: 24 additions & 0 deletions src/AppSearch.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import esriConfig from '@arcgis/core/config.js';

import { ErrorBoundary } from 'react-error-boundary';
import { AreaOfInterest, MapContainer } from './components';

const ErrorFallback = ({ error }: { error: Error }) => {
return (
<div role="alert">
<p>Something went wrong:</p>
<pre style={{ color: 'red' }}>{error.message}</pre>
</div>
);
};

esriConfig.assetsPath = import.meta.env.MODE === 'production' ? '/wri/js/ugrc/assets' : '/js/ugrc/assets';

export default function App() {
return (
<ErrorBoundary FallbackComponent={ErrorFallback}>
<AreaOfInterest />
<MapContainer configuration="search" />
</ErrorBoundary>
);
}
23 changes: 23 additions & 0 deletions src/components/AreaOfInterest.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { Button, ToggleButton } from '@ugrc/utah-design-system';

Check failure on line 1 in src/components/AreaOfInterest.tsx

View workflow job for this annotation

GitHub Actions / Lint and check types

Module '"@ugrc/utah-design-system"' has no exported member 'ToggleButton'.
import { useRef } from 'react';

export const AreaOfInterest = () => {
const areaOfInterestNode = useRef<HTMLInputElement>(null);

return (
<div className="px-2">
<h2>Area of Interest</h2>
<div className="flex w-fit gap-2 py-3">
<span>
<ToggleButton onChange={(value) => (areaOfInterestNode.current!.value = value.toString())}>

Check failure on line 12 in src/components/AreaOfInterest.tsx

View workflow job for this annotation

GitHub Actions / Lint and check types

Parameter 'value' implicitly has an 'any' type.
Draw a polygon
</ToggleButton>
</span>
<span>
<Button isDisabled>Upload a shapefile</Button>
</span>
</div>
<input ref={areaOfInterestNode} id="aoiGeometry" type="text" className="hidden" />
</div>
);
};
20 changes: 12 additions & 8 deletions src/components/MapContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ type SelectorOptions = {
position: 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right';
};

export const MapContainer = () => {
export const MapContainer = ({ configuration }: { configuration: 'search' | 'edit' }) => {
const mapNode = useRef<HTMLDivElement | null>(null);
const mapComponent = useRef<EsriMap | null>(null);
const mapView = useRef<MapView | null>(null);
Expand Down Expand Up @@ -101,7 +101,7 @@ export const MapContainer = () => {
if (isReady) {
// layers are stacked on top of each other in a reverse order from how they are listed
// e.g. land ownership is on the very bottom and centroids are on the very top
addLayers([
const referenceLayers = [
landOwnership,
plss,
streams,
Expand All @@ -114,14 +114,18 @@ export const MapContainer = () => {
forestService,
sageGrouse,
stewardship,
polygons,
lines,
points,
centroids,
]);
];
const operationalLayers = [polygons, lines, points, centroids];

if (configuration === 'search') {
operationalLayers.forEach((x) => (x.visible = false));
addLayers(operationalLayers);
} else {
addLayers(referenceLayers.concat(operationalLayers));
}
}
setMapView(mapView.current!);
}, [isReady, mapView, addLayers, setMapView]);
}, [isReady, mapView, addLayers, setMapView, configuration]);

return (
<>
Expand Down
1 change: 1 addition & 0 deletions src/components/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './AreaOfInterest.tsx';
export * from './CentroidToggle.tsx';
export * from './FeatureData.tsx';
export * from './Loaders.tsx';
Expand Down
14 changes: 14 additions & 0 deletions src/mainSearch.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import '@arcgis/core/assets/esri/themes/light/main.css';
import React from 'react';
import { createRoot } from 'react-dom/client';
import App from './AppSearch';
import { MapProvider } from './components/contexts';
import './index.css';

createRoot(document.getElementById('root')!).render(
<React.StrictMode>
<MapProvider>
<App />
</MapProvider>
</React.StrictMode>,
);
1 change: 1 addition & 0 deletions vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export default defineConfig(({ mode }) => {
input: {
main: resolve(__dirname, 'map.html'),
dev: resolve(__dirname, 'index.html'),
search: resolve(__dirname, 'search.html'),
},
},
},
Expand Down

0 comments on commit 9ca9d67

Please sign in to comment.