commit16
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
import SearchState from '@/components/search-state';
|
||||
import { useEffect, useState } from 'react';
|
||||
import TerritoryGeometryPreview from './territory-geometry-preview';
|
||||
import TerritorialMap from './catalogue-investment-map';
|
||||
import InvestmentMapCoverage from './investment-map-coverage';
|
||||
import InteractiveInvestmentMap, {
|
||||
import {
|
||||
type InvestmentMapFeature,
|
||||
type InvestmentMapArea,
|
||||
} from './interactive-investment-map';
|
||||
@@ -23,9 +23,9 @@ export default function InvestmentMapPanel({
|
||||
const [retry, setRetry] = useState(0);
|
||||
const [areas, setAreas] = useState<InvestmentMapArea[]>([]);
|
||||
const [truncated, setTruncated] = useState(false);
|
||||
const [showPoints, setShowPoints] = useState(true);
|
||||
const [showAreas, setShowAreas] = useState(true);
|
||||
const [matched, setMatched] = useState(0);
|
||||
const [responseKey, setResponseKey] = useState('');
|
||||
const current = responseKey === key;
|
||||
useEffect(() => {
|
||||
const controller = new AbortController();
|
||||
const params = new URLSearchParams(JSON.parse(key));
|
||||
@@ -46,6 +46,7 @@ export default function InvestmentMapPanel({
|
||||
.then((data) => {
|
||||
if (controller.signal.aborted) return;
|
||||
setPoints(data.features);
|
||||
setResponseKey(key);
|
||||
setAreas(data.areas ?? []);
|
||||
setMissing(data.unlocated ?? []);
|
||||
setTruncated(Boolean(data.truncated));
|
||||
@@ -59,8 +60,10 @@ export default function InvestmentMapPanel({
|
||||
);
|
||||
})
|
||||
.catch(() => {
|
||||
if (!controller.signal.aborted)
|
||||
if (!controller.signal.aborted) {
|
||||
setResponseKey(key);
|
||||
setError('Não foi possível concluir a pesquisa.');
|
||||
}
|
||||
});
|
||||
return () => controller.abort();
|
||||
}, [key, retry]);
|
||||
@@ -69,53 +72,14 @@ export default function InvestmentMapPanel({
|
||||
<SearchState
|
||||
scope="Registos consultados pelo mapa"
|
||||
countLabel="investimentos, incluindo os que não têm coordenadas"
|
||||
loading={points === null && !error}
|
||||
error={error}
|
||||
total={matched}
|
||||
loading={!current || (points === null && !error)}
|
||||
error={current ? error : ''}
|
||||
total={current ? matched : 0}
|
||||
retry={() => setRetry((value) => value + 1)}
|
||||
/>
|
||||
<fieldset className="flex flex-wrap gap-4 rounded border p-3">
|
||||
<legend className="font-semibold">
|
||||
Camadas desta consulta
|
||||
</legend>
|
||||
<label>
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={showPoints}
|
||||
onChange={(event) =>
|
||||
setShowPoints(event.target.checked)
|
||||
}
|
||||
/>{' '}
|
||||
Investimentos com ponto
|
||||
</label>
|
||||
<label>
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={showAreas}
|
||||
onChange={(event) => setShowAreas(event.target.checked)}
|
||||
/>{' '}
|
||||
Áreas e limites
|
||||
</label>
|
||||
</fieldset>
|
||||
{!showPoints && !showAreas && (
|
||||
<p role="status">
|
||||
Camadas ocultas. Active uma camada para voltar a consultar
|
||||
os registos no mapa.
|
||||
</p>
|
||||
)}
|
||||
<InteractiveInvestmentMap
|
||||
points={points === null ? null : showPoints ? points : []}
|
||||
areas={showAreas ? areas : []}
|
||||
/>
|
||||
{points !== null && (
|
||||
<InvestmentMapCoverage
|
||||
points={points}
|
||||
areas={areas}
|
||||
unlocated={missing.length}
|
||||
truncated={truncated}
|
||||
/>
|
||||
)}
|
||||
<TerritoryGeometryPreview
|
||||
<TerritorialMap
|
||||
points={current ? (error ? [] : points) : null}
|
||||
areas={current ? areas : []}
|
||||
territoryId={
|
||||
territoryId ||
|
||||
String(
|
||||
@@ -123,12 +87,20 @@ export default function InvestmentMapPanel({
|
||||
filters.admin_post_id ||
|
||||
filters.district_id ||
|
||||
filters.province_id ||
|
||||
filters.geo_location_id ||
|
||||
'',
|
||||
)
|
||||
) ||
|
||||
undefined
|
||||
}
|
||||
/>
|
||||
{missing.length > 0 && (
|
||||
{current && points !== null && (
|
||||
<InvestmentMapCoverage
|
||||
points={points}
|
||||
areas={areas}
|
||||
unlocated={missing.length}
|
||||
truncated={truncated}
|
||||
/>
|
||||
)}
|
||||
{current && missing.length > 0 && (
|
||||
<div>
|
||||
<p>
|
||||
{missing.length} investimentos sem ponto público
|
||||
|
||||
Reference in New Issue
Block a user